Last active
August 29, 2015 14:06
-
-
Save Rafe/3ff8cb41616c39483d8f to your computer and use it in GitHub Desktop.
Reliable Capybara Cheetsheet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Find the first matching element | |
# Bad: | |
first('.active').click | |
# Good: | |
find('.active').click | |
find('.active', match: :first).click | |
# Interact with all matching elements | |
# Bad: | |
all('.active').each(&:click) | |
# Good: | |
find('.active', match: :first) | |
all('.active').each(&:click) | |
# Directly interacting with javascript | |
find('.active') | |
execute_script('$(".active").focus') | |
# Checking a field's value | |
expect(page).to have_field("Username", with: 'Joe') | |
# Checking an element's attribute | |
expect(page).to have_css(".user[data-name=''Joe]") | |
# Looking for matching CSS | |
# Bad: | |
expect(has_css?('active')).to be_true | |
# Good: | |
expect(page).to have_css('.active') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment