I am testing a website that has both a vertical login form on the right, and a horizontal form on the bottom. Both have identically named "email" and "password" fields. So I am employing capybara's within
to scope for the fields I'm interested in. The interesting bits of the web form look like this:
I have two separate projects, in which I am experimenting with sauce labs for automation. The first project is the capybara-only example, modified to test the page shown above. The second project is a cucumber implementation of the exact same tests. These are very simple, one-time hard-coded tests, just to get a proof of concept of the two techniques.
Here is the interesting bit of the capybara-only example:
within(:css, ".right-container.login-form") do
fill_in 'email', :with => "greg.gauthier+#{generate_email_suffix}@website.com"
fill_in 'password', :with => 'l33tP@$$w0rd'
click_button 'Submit'
end
Here is the interesting bit of the cucumber step_definition:
When(/^The user enters his information$/) do
within(:css, ".right-container.login-form") do #the page has duplicate forms
fill_in 'email', :with => "greg.gauthier+#{generate_email_suffix}@website.com"
fill_in 'password', :with => 'l33tP@$$w0rd'
click_button 'Submit'
end
end
When I run the capybara-only version, everything works great. The form gets filled in, and the email confirmation gets sent.
However, when I run the cucumber version, I get this error:
Unable to find css ".right-container.login-form" (Capybara::ElementNotFound)
How can this be? It's the exact same page, the exact same capybara method (within
, using the :css
selector), and the exact same test code. What am I not getting (aside from the fact that I'm probably cuking it wrong)?
Oh, here's what the require list looks like in the sauce_helper:
Capybara-only version:
require "sauce"
require "sauce/capybara"
require 'capybara/rails'
require 'capybara/rspec'
Cucumber version:
require "sauce"
require "sauce/capybara"
require "sauce/cucumber"
Do I maybe need to include the extra capybara gems in the cucumber version?