Test that a form field has an error with Cucumber and Capybara
You can use the step definition below to say this:
Then the "Last name" field should have an error
Capybara
Then /^the "([^\"]*)" field should( not)? have an error$/ do |field, negate|
expectation = negate ? :should_not : :should
page.send(expectation, have_css('.field_with_errors', :text => field))
end
Related cards:
Test whether a form field exists with Cucumber and Capybara
The step definition below lets you say:
Then I should see a field "Password"
But I should not see a field "Role"
Here is the step definition:
Then /^I should( not)? see a field "([^"]*)"$/ do |negate, name|
expectation = neg...
How to test print stylesheets with Cucumber and Capybara
A print stylesheet is easy to create. Choose a font suited for paper, hide some elements, done. Unfortunately print stylesheets often break as the application is developed further, because they are quickly forgotten and nobody bothers to check if ...
Test that a select field contains an option with Cucumber
This note describes a Cucumber step definition that lets you say:
Then "Mow lawn" should be an option for "Activity"
But "Reply support mail" should not be an option for "Activity"
Note that this step checks whether an option is availabl...
Test that a form field is visible with Cucumber/Capybara
Spreewald now comes with a step that tests if a form field is visible:
Then the "Due date" field should be visible
But the "Author" field should not be visible
The step works by looking up the...
Test that a select option is selected with Cucumber
This step tests whether a given select option comes preselected in the HTML. There is another step to test that an option is available at all.
Cap...
Check that a text field is empty with Cucumber
This will not work (it always passes):
Then the "Title" field should contain ""
The value is turned into a regular expression, and an empty regular expression matches any string!
Do this instead for Capybara:
Then the "Title" field sho...
Capybara: Most okayest helper to download and inspect files
Testing file download links in an end-to-end test can be painful, especially with Selenium.
The attached download_helpers.rb
provides a download_link
method for your Capybara tests. It returns a hash describing the download...
Test that an exception or error page is raised in Capybara
You can use these step definitions:
Then /^I should not see an error$/ do
(200 .. 399).should include(page.status_code)
end
Then /^I should see an error$/ do
(400 .. 599).should include(page.status_code)
end
Note...
Test that a number or money amount is shown with Cucumber
This is an awful way to test whether a number is shown on the screen:
Then I should see "5"
It is awful because the step above is green for 5, 5123 and -51.
This step definition below makes sure this doesn't happen. You can use it like this...
Capybara: Waiting for pending AJAX requests after a test
When ending a Selenium test Capybara resets the browser state by closing the tab, clearing cookies, localStorage
, etc.
It may be a good idea to wait for all in-flight AJAX requests to finish before ending a scenario:
- You may have client-side...