I have a Ruby on Rails app that runs feature tests using Capybara, Poltergeist and PhantomJS.
Version 2.0.0 of PhantomJS has a rather significant bug that breaks a lot of tests (https://github.com/ariya/phantomjs/issues/12506) so I'd like to force the app to use a different version of PhantomJS when running the tests.
Is this possible from within Poltergeist's configuration, to raise an error or a warning if this buggy version is used, or is my best bet simply putting a note in the app's readme saying 'don't use version 2.0.0 due to this bug'?
at the moment my Capybara/Poltergeist configuration is very basic:
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, :timeout => 90)
end
As #pguardiario commented, you can just do something like
if `phantomjs -v`.start_with? '2'
#output whatever kind of warning you want
end
however the Poltergeist master branch has a fix for that particular issue so you could just try using that instead
Related
I'm using capybara webkit on Ubuntu (14.04 LTS) and I'm getting the following error when trying to use it:
Capybara::Webkit::ConnectionError: /srv/www/app/shared/bundle/ruby/2.1.0/gems/capybara-webkit-1.3.1/bin/webkit_server failed to start.
from /srv/www/app/shared/bundle/ruby/2.1.0/gems/capybara-webkit-1.3.1/lib/capybara/webkit/connection.rb:75:in `parse_port'
from /srv/www/app/shared/bundle/ruby/2.1.0/gems/capybara-webkit-1.3.1/lib/capybara/webkit/connection.rb:81:in `discover_port'
from /srv/www/app/shared/bundle/ruby/2.1.0/gems/capybara-webkit-1.3.1/lib/capybara/webkit/connection.rb:62:in `start_server'
from /srv/www/app/shared/bundle/ruby/2.1.0/gems/capybara-webkit-1.3.1/lib/capybara/webkit/connection.rb:25:in `initialize'
from /srv/www/app/shared/bundle/ruby/2.1.0/gems/capybara-webkit-1.3.1/lib/capybara/webkit/driver.rb:17:in `new'
I installed QT using:
sudo apt-get install libqt4-dev libqtwebkit-dev libqt5webkit5-dev
Using gem versions: capybara (2.4.4) and capybara-webkit (1.3.1)
The same program works fine on mac (qt installed using homebrew)
Thanks
It has been a long time since this question was asked, but I had the same problem even though I used much more ancient versions of anything. It turned out that webkit needs to be able to connect to some X-Server and this is its reaction if it fails. I ended up installing xvfb and using
xvfb-run --auto-servernum bundle exec rake test
(aliased of course) when running my tests. This is probably less than optimal, but it was good enough for me. Maybe this helps the next person who stumbles across this error.
I beat my head against this all morning. Turns out I had omitted this code from rails_helper.rb :
if ENV['HEADLESS']
require 'headless'
headless = Headless.new
headless.start
at_exit { headless.stop }
end
We use the HEADLESS environment variable to trigger this. Not sure if that's typical or a local convention. Regardless, I needed to add export HEADLESS=1 to .env to fire that off.
I also had to add gem 'headless', '~> 1.0.2' in Gemfile.
I'm trying to put the free software where I'm one of the collaborators to run the acceptance tests on Travis. Everything went very well except for the acceptance tests with selenium.
And this is a difficult issue because the software uses only the gem versions avaiable on Debian 6. So, everything is really outdated.
Being more specific, just the steps where I'm looking for some text on the screen, with the step:
page.should have_content(text)
I've already tried to:
to add some waiting since it could be looking for the element before it was rendered;
update the xpath;
remove the webrat, because I've read that it could be conclicting with capybara;
run the tests locally with xvfb;
create a VM with Ubuntu Server 12.04 32 bits (Travis version), install everything and run the tests on xvfb;
update Capybara from 1.1.1 to 1.1.4.
But the problem persists:
# features/step_definitions/web_steps.rb:107
Unable to find xpath "/html" (Capybara::ElementNotFound)
(eval):2:in `send'
(eval):2:in `text'
./features/step_definitions/web_steps.rb:110
./features/step_definitions/web_steps.rb:14:in `with_scope'
./features/step_definitions/web_steps.rb:108:in `/^(?:|I )should see "([^"]*)"(?: within "([^"]*)")?$/'
plugins/mezuro/features/repository.feature:101:in `And I should see "My Name"'
Here is the link for the build:
https://travis-ci.org/rafamanzo/mezuro-travis/builds/6231714
Anyone have any idea? I'm afraid that it is related with the gem versions and I'll not be able to fix it by any means.
Here are links for what I was able to find about it on Google:
https://groups.google.com/forum/#!msg/ruby-capybara/PDr7sZ124Vw/qLXqHXs0XdMJ
https://github.com/rspec/rspec-rails/issues/406
Thank you very much!
I'm trying out casperJS to run some automated tests. On windows. I followed this installation guide but am stuck.
when I try to run a simple test from the command line like this:
casperjs.bat smoketest.js
I get the following error:
Error: Cannot find module 'C:/code/base/main/Shared/casperjs\modules\cli.js'
I checked, and the file cli.js does exist under the specified path.
I thought the problem could be the mixture of forward and backward slashes in the path, but I edited the bootstrap.js casper code to hard code the path and it made no difference - it still the cannot find module.
I'm have tried this using phantomJS version 1.9.0, and 1.8.2.
Anyone know what I am doing wrong?
Has anyone had success running casper on Windows?
This is due to a bug in PhantomJS 1.9.0 that does not allow for absolute path loading in Windows. Afaik, this should only be apparent if you are using a master build of CasperJS (v1.1).
This bug has been fixed, but is not yet in the Windows binary. You can compile it yourself if you'd like, but that can take quite a bit of time.
I was using the master build of casper. With the latest released version, 1.0.2, it works fine.
I'm trying to create a custom model to interface with a database that isn't supported navtively by Rails or through the OpenLink ODBC driver. For some reason, I'm getting the following error:
no such file to load -- odbc
I'm at a lost as to why this is occurring as the ruby-odbc gem is in the GEM_PATH and I have a small script that tests this to ensure that the connection works and it worked perfectly. Does Rails ignore the gem_path? Is there something else I need to configure? I checked the GEM_PATH in Rails by writing it out to the browser and it matches what I saw in a terminal window.
FYI: I'm using rvm to manage ruby and all of my gems. Not sure if this makes any difference, though it really shouldn't from what I can tell.
Does your Gemfile include something like the following
gem 'ruby-odbc'
It is pretty easy with the added generator of rspec-rails to set up RSpec for testing a Rails application. But how about adding RSpec for testing a gem in development?
I am not using jeweler or such tools. I just used Bundler (bundle gem my_gem) to setup the structure for the new gem and edit the *.gemspec manually.
I also added s.add_development_dependency "rspec", ">= 2.0.0" to gemspec and did a bundle install.
Is there some nice tutorial what to do next to get RSpec working?
I've updated this answer to match current best practices:
Bundler supports gem development perfectly. If you are creating a gem, the only thing you need to have in your Gemfile is the following:
source "https://rubygems.org"
gemspec
This tells Bundler to look inside your gemspec file for the dependencies when you run bundle install.
Next up, make sure that RSpec is a development dependency of your gem. Edit the gemspec so it reads:
spec.add_development_dependency "rspec"
Next, create spec/spec_helper.rb and add something like:
require 'bundler/setup'
Bundler.setup
require 'your_gem_name' # and any other gems you need
RSpec.configure do |config|
# some (optional) config here
end
The first two lines tell Bundler to load only the gems inside your gemspec. When you install your own gem on your own machine, this will force your specs to use your current code, not the version you have installed separately.
Create a spec, for example spec/foobar_spec.rb:
require 'spec_helper'
describe Foobar do
pending "write it"
end
Optional: add a .rspec file for default options and put it in your gem's root path:
--color
--format documentation
Finally: run the specs:
$ rspec spec/foobar_spec.rb
Iain's solution above works great!
If you also want a Rakefile, this is all you need:
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
# If you want to make this the default task
task default: :spec
Check the RDoc for RakeTask for various options that you can optionally pass into the task definition.
You can generate your new gem with rspec by running bundler gem --test=rspec my_gem. No additional Setup!
I always forget this. It's implemented here: https://github.com/bundler/bundler/blob/33d2f67d56fe8bf00b0189c26125d27527ef1516/lib/bundler/cli/gem.rb#L36
Here's a cheap and easy (though not officially recommended) way:
Make a dir in your gem's root called spec, put your specs in there. You probably already have rspec installed, but if you don't, just do a gem install rspec and forget Gemfiles and bundler.
Next, you'll make a spec, and you need to tell it where your app is, where your files are, and include the file you want to test (along with any dependencies it has):
# spec/awesome_gem/awesome.rb
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
$: << File.join(APP_ROOT, 'lib/awesome_gem') # so rspec knows where your file could be
require 'some_file_in_the_above_dir' # this loads the class you want to test
describe AwesomeGem::Awesome do
before do
#dog = AwesomeGem::Awesome.new(name: 'woofer!')
end
it 'should have a name' do
#dog.name.should eq 'woofer!'
end
context '#lick_things' do
it 'should return the dog\'s name in a string' do
#dog.lick_things.should include 'woofer!:'
end
end
end
Open up Terminal and run rspec:
~/awesome_gem $ rspec
..
Finished in 0.56 seconds
2 examples, 0 failures
If you want some .rspec options love, go make a .rspec file and put it in your gem's root path. Mine looks like this:
# .rspec
--format documentation --color --debug --fail-fast
Easy, fast, neat!
I like this because you don't have to add any dependencies to your project at all, and the whole thing remains very fast. bundle exec slows things down a little, which is what you'd have to do to make sure you're using the same version of rspec all the time. That 0.56 seconds it took to run two tests was 99% taken up by the time it took my computer to load up rspec. Running hundreds of specs should be extremely fast. The only issue you could run into that I'm aware of is if you change versions of rspec and the new version isn't backwards compatible with some function you used in your test, you might have to re-write some tests.
This is nice if you are doing one-off specs or have some good reason to NOT include rspec in your gemspec, however it's not very good for enabling sharing or enforcing compatibility.