I've configured my CI server with Jenkins in order to run my test after each push to Git. I have some integration tests and there is always one that fails. The output given is that capybara can't find the element but if I run the test in local it works.
I've research a bit and I found headless gem but it doesn't work. I also tried to set Capybara.default_wait_time = 5 but nothing.
Does anyone know what kind of configuration I should set in order to get my jenkins green?
Thank you in advance
The failure to find may be element within the environment. Using the 'save_and_open' method will show the exact state of the page that is trying to be rendered in the CI server environment. You can add it to a test as simply as:
it 'should register successfully' do
visit registration_page
save_and_open_page
fill_in 'username', :with => 'mrUser'
end
This assumes that you can view the page on the CI server or alternatively with the headless version the file should be saved so that you review later.
Related
I maintain several extension for the Spree/Solidus Rails platform(s), and for some reason on one extension in particular I’m having a Capybara issue I can’t seem to track down.
Once I build a test environment, the first test of the first run through the specs always fails, with the following:
Capybara::Poltergeist::StatusFailError:
Request to 'http://127.0.0.1:52234/products' failed to reach server,
check DNS and/or server status - Timed out with no open resource requests
All subsequent specs pass. If I run bundle exec rspec spec again, then all specs pass.
I have tried increasing the Capybara timeout values to super high numbers:
RSpec.configure do |config|
config.include Spree::TestingSupport::CapybaraHelpers, type: :feature
Capybara.register_driver(:poltergeist) do |app|
Capybara::Poltergeist::Driver.new app, timeout: 90
end
Capybara.javascript_driver = :poltergeist
Capybara.default_max_wait_time = 90
end
But it seems to have no effect.
All my Travis builds fail on the first spec of the first run (and pass on everything else), which is making it hard to maintain the project, as all PRs look red.
Any ideas what might be going on here?
Most likely this is failing when Rails processes the asset pipeline at the first request. Try precompiling the test mode assets before running the test or increase the timeout in the driver registration even more. The Capybara.default_max_wait_time shouldn't affect this at all.
I have a Rails 3 app and I use cucumber for testing. One of my tests has the following step:
Then I should see "And now a word from our lawyers..."
The step is defined like this:
Then(/^I should see "(.*?)"$/) do |text|
expect(page).to have_content text
end
When I run the test locally everything works fine. I am using Semaphoreapp as a CI server. After a recent selenium driver update I get the following error when I run the test in my CI environment:
expected to find text "And now a word from our lawyers..." in " ��� And now a word from our lawyers... "
I assume this has to do with some Unicode issue on the CI service side. Is there a way to configure cucumber/capybara to use Unicode for matching?
I've recently moved mi CI server (Teamcity) to another powerful machine with same configuration and pretty similar OS.
Since then some of my integration specs have started to fail. My setup is pretty standard, Rails 3 + capybara + poltergeist + phantomjs.
Failures are deterministic, they always happen and they are always related to some missing nodes in the DOM. Also, failures happens across different projects with similar setup so it's not something related to project configuration. This is happening with both capybara 1.x and capybara 2.
This is the simplest failing spec. Note that this spec runs with no need of javascript, so the issue is also present in rack only specs.
scenario 'require an unsubscription' do
visit unsubscribe_index_path
within main_content do
choose list.description
fill_in 'Email', :with => subscriber.email
click_button 'Unsubscribe'
end
save_page # <--- Added to debug output
# !!! HERE is the first failing assertion
page.should have_content('You should have received a confirmation message')
# Analytics event recorded
# !!! this also is failing
page.should have_event('Unsubscription', 'Sent', list_name)
# If I comment previous two lines the spec passes on CI machine
# this means that the form is submitted with success since email is triggered
# from controller code
last_email_sent.should have_subject 'Unsubscribe request received'
last_email_sent.should deliver_to subscriber.email
end
What I've tried:
run the specs on different machines, they works on every dev machine and also in a staging server. I can only reproduce the failure on the CI machine even outside of CI environment (i.e. by running the specs via command line)
Increased Capybara.default_wait_time to a ridiculous 20
Tried with a brutal sleep before the page.should have_content line
upgrade RVM, ruby, capybara, poltergeist on their latest versions on the CI machine.
upgrade teamcity to its latest version
The strangest thing I found is when I've added a save_page call just before the failing line. If i run the spec on my machine and then on the CI where the server is failing and comparing those two files the result is this:
$ diff capybara-201309071*.html
26a27,29
> <script type='text/javascript'>
> _gaq.push(["_trackEvent","Unsubscription","Sent","listname"]);
> </script>
90a94,96
> <div class="alert-message message notice">
> <p>You should have received a confirmation message</p>
> </div>
Which are the two missing pieces which make the spec failing, so the form is submitted, controller action is run successfully but there are two missing pieces of dom. How that is possible? And why this is happening only on one machine?
For the records, those two pieces of DOM are added with standard rails tools one with
redirect_to unsubscribe_index_path, notice: ...
and the other with the analytical gem
I've found the issue, the two failing projects I'm using dalli_store as session store and I've put the config.cache_store = :dalli_store line in config/application.rb instead of config/environments/production.rb.
On the old CI server there was a memcached daemon running hence all specs was running fine.
In the new server since it's just a CI server and it doesn't run any production or staging code memcached is not present thus any session write (such as flash messages) was silently discarded and this is the reason why all that kind of specs was failing.
I solved by putting the config.cache line in the appropriate environment file, but I'm still wondering why dalli gem doesn't raise any warning when no memcached is available. While the choice of not failing on missing cache daemon is reasonable since the application should work with no cached data, it could be a performance killer in production code and it might go unnoticed if no warning is given.
I am trying to run my integration tests using RSpec and Capybara using the command "rspec spec" , it used to run fine until recently it just opens the browser and stays there until timeout.
Here is the test code :
it "should see payment error if payment amount is smaller than product price", :js => true do
visit("/")
find_link("A new product").click
end
Do you change the version of your browser? If the browser version is not supported by webdriver, it might run into the case as you mentioned.
I am writing integration test for one of my project, using the following gems for the same, rspec, capybara and selenium.
I face the following challenges in the same,
I want to run the test on an existing database, i don't want to clear the existing data before or after executing the test.
We have a remote server for integration testing. Is it possible to run the test on a remove server? The way i would like to go is after updating the build on integration server, i would like to go for a integration test using selenium.
Any help is highly appreciated.
Sorry, but selenium tests cannot be run in a transaction. You have to (for example) dump database and load previously prepared database after executing each test.
Yes, it is possible. What solution you're using for continuous integration and build management? What's the problem you're encountering? Can you describe it?
Got the solution, we need to do as follows,
Capybara.current_driver = :selenium
Capybara.app_host = 'http://www.google.com'
...
visit('/')
Reference: capybara gem