Last active
June 26, 2022 08:32
-
-
Save cybersamx/c5521b9c0f3518af2b77 to your computer and use it in GitHub Desktop.
Capybara (visit/page) cheat sheet
This file contains 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
# Navigation | |
visit('/resources') | |
visit(resource_path(resource)) | |
# Clicking buttons and hyperlinks | |
click_button('Submit Button') | |
click_link('Link Text') | |
click_link('Link id') | |
click('Link or button') | |
# Forms | |
fill_in('Label name', with: 'value') | |
fill_in('Input name', with: 'value') | |
choose('Radio button') | |
check('Checkbox') | |
uncheck('Checkbox') | |
select('Option', from: 'Select Box') | |
# Scoping | |
within("//li[@id='employee']") do | |
# Do stuff | |
end | |
within(:css, "li#employee") do | |
# Do stuff | |
end | |
within_fieldset('Employee') do | |
# Do stuff | |
end | |
within_table('Employee') do | |
# Do stuff | |
end | |
# Querying | |
expect(page).to have_xpath('//table/tr') | |
expect(page).to have_css('table tr.foo') | |
expect(page).to have_content('foo') | |
find_field('First Name').value | |
find_link('Hello').visible? | |
find_button('Send').click | |
find('//table/tr').click | |
locate("//*[@id='overlay'").find("//h1").click | |
within(:css, 'ul li') { # Do stuff } | |
all('a').each { |a| a[:href] } | |
# Scripting | |
evaluate_script('4 + 4') | |
# XPath and CSS | |
# Credit: http://www.launchacademy.com/codecabulary/learn-test-driven-development/rspec/capybara-cheat-sheet |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment