13
votes

I wrote some feature specs to test logging in through my rails app, and the specs all pass locally, but they fail when Travis CI runs them. Here is an example:

1) User Registration User signs up with valid credentials
     Failure/Error: fill_in 'Username', with: 'dannnnneh'
     Capybara::ElementNotFound:
       Unable to find field "Username"
     # ./spec/features/registrations_controller_spec.rb:8:in `block (2 levels) in <top (required)>'

I read on the common build problems for Travis CI to use Capybara.default_wait_time = 15; however, I either put that in the wrong place, or it doesn't work.

Example spec:

scenario 'User signs up with valid credentials' do
    Capybara.default_wait_time = 15
    visit '/users/sign_up'
    fill_in 'Username', with: 'dannnnneh'
    ...

EDIT:

I have also tried putting Capybara.default_wait_time = 15 in rails_helper.rb, spec_helper.rb, spec/support/capybara.rb.

I also added the following to .travis.yml because of this SO question.

script:
    - xvfb-run bundle exec rspec spec/features/*.rb

However, that did not work either.

Does anyone know what the probelm might be or how to fix it?

EDIT:

Here is my spec_helper.rb:

require 'simplecov'
SimpleCov.start


require 'capybara'
require 'capybara/poltergeist'

Capybara.javascript_driver = :poltergeist
Capybara.register_driver :poltergeist do |app|
  Capybara::Poltergeist::Driver.new(app, timeout: 15)
end

RSpec.configure do |config|

  config.expect_with :rspec do |expectations|
    expectations.include_chain_clauses_in_custom_matcher_descriptions = true
  end

  config.mock_with :rspec do |mocks|
    mocks.verify_partial_doubles = true
  end

end
4
What driver are you using? Is there any javascript running on that page that might make the login box appear?DickieBoy
@DickieBoy I'm not using a driver, do I need one?Dbz
I believe I have set it up to use Poltergeist, but still no luck.Dbz
Are you doing a bundle install in your test script on travis?DickieBoy
Everything bundle installs automatically when travis runs.Dbz

4 Answers

2
votes

Can you post your spec_helper ? Also, the official documentation suggests another way to configure xvfb, have you checked http://docs.travis-ci.com/user/gui-and-headless-browsers/ ?

2
votes

Check whether TrevisCI can create test DB. For working with Travis CI, I had to create public test DB which TravisCI can use...

2
votes

You have some problem or other, but no debug output, so it's hard to tell what's wrong. I would eliminate the issues one by one by altering your tests to give you that output. You could have one of the following (or something else):

  • You may not be on the correct page because the navigation has failed
  • You may not have anything on the page except an error message
  • You may have something else on the page which is covering up the username field

Try adding a step that validates the page you are on:

expect(page).to have_current_path('/users/sign_up')

Or try adding a step that prints out the HTML for the page.

puts page.html

or if not...

fail page.html

You should find something of use to tell you why you cannot see the input you want to fill in.

0
votes

The reason why travis CI was failing was because of an issue with require_tree in application.js. If the directory that require_tree is referencing is empty, then everything breaks. There are three solutions that I found.

1) Add a .keep file to the proper directory

2) Remove the require_tree statement and whatever is using it

3) Remove whatever is using the require_tree statement.

In my case, it was turbo-links that was causing the issue. I plan on implementing a front-end framework, so I removed the reference to turbo-links in application.html.slim

Travis CI only spit out this error when I switched from slim to erb, and puts page.html in one of my tests, so it was hard to track down.