Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specs pass locally, but fail for Travis CI

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
like image 431
Dbz Avatar asked Jun 21 '15 03:06

Dbz


3 Answers

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/ ?

like image 133
jiop Avatar answered Nov 10 '22 02:11

jiop


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

like image 26
Сергій Назаревич Avatar answered Nov 10 '22 02:11

Сергій Назаревич


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.

like image 2
Matt Gibson Avatar answered Nov 10 '22 01:11

Matt Gibson