Capybara: comparison of Float with String failed (ArgumentError)

Created on 25 Jul 2015  路  5Comments  路  Source: teamcapybara/capybara

Not sure when this started happening, but I'm getting this error message when trying to check for content on the page:

click_on 'A link or button'
expect(page).to have_content 'whatever'

#> comparison of Float with String failed (ArgumentError)

It used to be that Capybara would provide a helpful error message including the content that was found on the page. I'm using Capybara/Cucumber/RSpec to test an Ember.js app so maybe there is a bug in this particular combination.

Most helpful comment

In case anyone else comes across this (my google search led me here), I experienced this issue. The cause for me was the following line:

https://github.com/jnicklas/capybara/blob/master/lib/capybara/node/base.rb#L90

raise e if (Capybara::Helpers.monotonic_time - start_time) >= seconds

It turned out I was loading the wait time from my environment setting:

Capybara.default_max_wait_time = ENV['DEFAULT_MAX_WAIT_TIME'] || 20

The issue is that in this example ENV['DEFAULT_MAX_WAIT_TIME'] will be a string and not a numeric type.

Capybara.default_max_wait_time = (ENV['DEFAULT_MAX_WAIT_TIME'] || 20).to_i

Solved things for me.

All 5 comments

What driver are you using? What version of Capybara? and please post the stacktrace so we can see where the error is coming from

Mostly using capybara-webkit, but this happens when using selenium too. It usually happens when an element can't be found on the page. There is no stack trace other than my failing steps. My steps simply have things like fill_in fields or click_on links or expect(page).to have_content. The cause of the failure is that the AJAX request hasn't finished, and Capybara doesn't know to wait for those requests to finish. Normally, Capybara is smart enough to wait, but in this case, it's some sort of conflict with Ember.js's virtual DOM.

Without a stack trace or reproducible test case there's not much we can do about this

Closing -- if a stacktrace or reproducible test case is provided we can reopen

In case anyone else comes across this (my google search led me here), I experienced this issue. The cause for me was the following line:

https://github.com/jnicklas/capybara/blob/master/lib/capybara/node/base.rb#L90

raise e if (Capybara::Helpers.monotonic_time - start_time) >= seconds

It turned out I was loading the wait time from my environment setting:

Capybara.default_max_wait_time = ENV['DEFAULT_MAX_WAIT_TIME'] || 20

The issue is that in this example ENV['DEFAULT_MAX_WAIT_TIME'] will be a string and not a numeric type.

Capybara.default_max_wait_time = (ENV['DEFAULT_MAX_WAIT_TIME'] || 20).to_i

Solved things for me.

Was this page helpful?
0 / 5 - 0 ratings