Can page-object be used outside of Cucumber? - page-object-gem

I am trying to understand what exactly ties the page-object gem to Cucumber.
The page factory is exposed to Cucumbers world which allows the use of on / visit in steps, but this seems to be something that can be exposed without Cucumber.
The #browser variable which page-object relies on is created in a before_suite or before_scenario context in Cucumber but this can also be created without Cucumber.
Is there anything actually tying this gem to Cucumber?

Yes. Page-object gem can be used outside of Cucumber.
Here is an example how you can use it with RSpec.
$ tree
├── Gemfile
├── spec
│   ├── my_app
│   │   └── search_spec.rb
│   ├── pages
│   │   ├── article_page.rb
│   │   └── index_page.rb
│   └── spec_helper.rb
Gemfile
source "https://rubygems.org"
gem 'rspec'
gem 'page-object'
spec_helper.rb
require 'page-object'
Dir["#{File.dirname(__FILE__)}/pages/*_page.rb"].each { |file| require file }
RSpec.configure do |config|
config.include PageObject::PageFactory
config.before do
#browser = Watir::Browser.new :firefox
end
config.after do
#browser.close
end
end
search_spec.rb
require 'spec_helper'
describe 'Search field' do
it 'searches an article' do
visit(IndexPage) do |page|
page.search = 'Ruby'
page.submit_search
end
expect(on(ArticlePage).main_header).to eq('Ruby')
end
end
article_page.rb
class ArticlePage
include PageObject
h1(:main_header)
end
index_page.rb
class IndexPage
include PageObject
page_url 'https://www.wikipedia.org'
text_field(:search, id: 'searchInput')
button(:submit_search)
end

As has been mentioned on rubygems.org PageObject gem has only development dependency on Cucumber. It doesnt need cucumber for implementation. A precise explanation of difference between runtime and development dependencies is given here.
For execution purposes Cucumber looks for step definitions. Passing Page Factory to World adds the PageObject capabilities to Cucumber. The only thing that I can think of tying PageObject to Cucumber are its unit tests. Evmorov has already given a great solution for it to work with Rspec alone.

Related

Unable to minify Jekyll javascript via jekyll-assets or jekyll-minifier

I'm having a heck of a time figuring out how to get Jekyll (v4.0.0) to minify javascript. I have installed jekyll-assets (v3.0.12) and jekyll-minifier (v0.1.10) in an effort to do so, but no luck so far... the javascript remains unminified.
I've tried a number of configuration options in _config.yml that didn't help, referencing the documentation here:
https://github.com/envygeeks/jekyll-assets/tree/v3.0-current#configuration
Any help would be greatly appreciated!
Gemfile
# frozen_string_literal: true
source "https://rubygems.org"
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
# gem "rails"
gem "jekyll", "~> 4.0"
group :jekyll_plugins do
gem "jekyll-assets"
gem "jekyll-minifier"
end
_config.yml
permalink: pretty
sass:
style: compressed
exclude:
- gulpfile.js
- node_modules
- CNAME
- README
- '*.json'
- .DS_Store
plugins:
- jekyll-assets
- jekyll-minifier
assets:
sources:
- "css"
- "js"
_includes/scripts.html
...
{% javascript app %}
...
js/app.js
//=require scripts.js
//=require scripts-2.js
var myStr = "app";
myStr += " js";
console.log(myStr);
command line
JEKYLL_ENV=production bundle exec jekyll build
The Jekyll-Minifier plugin may be minifying javascript in the _site directory after Jekyll creates the static site. If you are using github pages, this won't work as Github is building from the source and has limited plugin support. You may have to build using the plugin and use the _site directory to serve manually, or find a different plugin that minimizes in place rather than in the _site directory.

Accessing static files in Golang

I am having trouble linking to an external CSS file in one of my served pages in a Go Server.
This is my project structure, with some comments. My $GOPATH, is the top-level directory. Note that there is a "main" executable that was built via using the "$go build main" command from this top-level directory. It essentially compiled the files in the src/main directory. I then run the program directly through this executable ("$.\main").
.
├── bin
├── main <-- Executable, not directory (built via "go build main")
├── pkg
│   └── darwin_amd64
├── src
│   ├── github.com
│   └── main <---- My Go files are here!
├── style
│   └── style.css
└── templates
└── developers.html
I am trying to use the style.css file as an externally linked style file in the developers.html template, that is eventually parsed and merged by Go. The files are listed below, in simplified versions.
developers.html
<html>
<head>
<link rel="stylesheet" type="text/css" href="style/style.css">
</head>
<body>
...
</body>
</html>
server.go
package main
import (
"log"
"net/http"
)
func main() {
styleHandler := http.FileServer(http.Dir("style"))
http.Handle("/style/", http.StripPrefix("/style/", styleHandler))
// router handles other non-static pages,
// and is defined in another .go source file. These are working.
router := MainRouter()
log.Fatal(http.ListenAndServe(":8080", router))
}
I'm sure the problem is how I'm treating the relative paths, but I can't figure it out. Thanks for any help.

couchbase where can I execute cbq command

I have a couchbase server and I want to connect to it from my query engine. I asked a lot and I found that I have to use this command
./cbq-engine -couchbase http://--couchbase-server-name--:8091/
regarding that I have many questions about that command, like where should I put the username and password, why should I use the port 8091 when my server is working online so port is 8080, I don't want the answer of those questions, but I need to know where should I execute that command?
I tried on cmd on but I got that cbq is not defined.
I am on windows 7 64bit
please help
Since you're on windows, I believe the difference is that it's cbq.exe and you'll need to have it in your path or be in that directory. The downloads as posted at http://www.couchbase.com/communities/n1ql do have cbq.exe included:
.
├── LICENSE.txt
├── README
├── cbq-engine.exe
├── cbq.exe
├── data
├── start_tutorial.bat
└── static
2 directories, 5 files
Also note that the Java 2.0, node.js 2.0 and some other SDKs have experimental support for N1QL querying.

Compass generated_images_dir is placing files in wrong folder

I have an issue with the compass generated_images_dir. The generated images doesn't get placed in the css/img directory but is instead placed in css. The goal is to have img-sb11bbe84f2.png inside css/img.
How can I get this to work?
I'm using ruby 2.1.2, compass 0.12.7 and Ubuntu 14.04 in case it's relevant
config.rb:
http_path = "/"
css_dir = "css"
sass_dir = "sass"
images_dir = "img"
generated_images_dir = "css/img"
javascripts_dir = "js"
Compass watch output:
>>> Change detected at 23:12:08 to: print.scss
create css/print.css
create css/ie.css
create css/img-sb11bbe84f2.png
create css/screen.css
>>> Compass is polling for changes. Press Ctrl-C to Stop.
Output directory is:
css
├── ie.css
├── img
├── img-sb11bbe84f2.png
├── print.css
└── screen.css
Try using:
generated_images_dir = "."

How can I serve only statics files on Google App Engine?

I wrote a game with HTML5. Locally, it only works if I run:
python -m SimpleHTTPServer
And then I open localhost:8000. So, just a bunch of .html and .js files won't work. I want to put my game online and because of this Github (Pages) is out of question, because it won't work.
This is the part of the code I need a server for (I do realize that localhost:8000/res/ won't work on App Engine, I'll need to change the address):
var mapFile = new XMLHttpRequest();
var self = this;
mapFile.open("GET", "http://localhost:8000/res/map" + mapNumber.toString() + ".txt", true);
mapFile.onreadystatechange = function() {
if (mapFile.readyState === 4) {
if (mapFile.status === 200) {
self.lines = mapFile.responseText.split("\n");
self.loadTilesFromLines();
}
}
};
mapFile.send(null);
So, I heard that Google App Engine would work, it supports Python and is very popular. Now, I don't need anything like what they have in their documentation (which is pretty well-written):
import webapp2
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.write('Hello, webapp2 World!')
app = webapp2.WSGIApplication([('/', MainPage)],
debug=True)
All I need is a SimpleHTTPServer that allows me to open my index.html on my-app.appspot.com.
I did try the example and got it up and running, but I can't force my browser to open index.html or src/ or even res/.
So, I am not even sure if Google App Engine supports what I'm trying to achieve here. The documentation just focus on building applications that use Python and all I needed with Python was a SimpleHTTPServer, which I don't think I need with App Engine.
Yes it is very doable on what you're trying to achieve here. Since you just want to serve static files it is very simple and you don't need to include any Python code.
Let's assume that you have this following structure:
└── my-game
├── app.yaml
└── static
├── index.html
├── js
│   └── script.js
└── res
└── map.txt
This app.yaml should look like this:
application: my-app
version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /
static_files: static/index.html
upload: static/index.html
- url: /
static_dir: static/
After you're going to install the Google App Engine SDK (if you didn't do that already), you will be able to run the dev_appserver.py command from your terminal. If you have the above structure try to run it using the following:
$ dev_appserver.py /path/to/my-game
If everything went smoothly you'll be able to see your index.html on http://localhost:8080, the map.txt on http://localhost:8080/res/map.txt and you should be able to figure out the rest.
Note that you could still run your application using the python -m SimpleHTTPServer from within the static directory and test it on localhost:8000.