Navigation & Windows
- Instantly share code notes and snippets. Go to capybaranodeactions and here it lists how you can attach a file check a checkbox choose a radio button click a button click a link click a link or a button fill in a text box field select a dropdown uncheck a checkbox or unselect a dropdown.
- 2021 850cc cheat sheets. Jump to Latest Follow 1 - 5 of 5 Posts. 2017 Wolverine RSPec SE Southern, Ont. Canada 7600 km and going Sept.
Interactive cheat sheet for Capybara:left:up:right:down:backspace:clear:return/:enter:tab:shift:control:alt:meta/:command.
visit('url')page.driver.browser.switch_to.window(window_handle)my_original_win_handle = page.driver.browser.window_handles.firstmy_last_win_handle = page.driver.browser.window_handles.lastpage.driver.browser.switch_to.alert.acceptpage.driver.go_backRspec Capybara Cheat Sheet
Clicking Links and Buttons
click_button('text, id, title, or value')click_link('link id, link title or *link text')click_on('link,button valueRspec Cheat Sheet Pdf
, or button text')page.driver.browser.action.move_to(page.all('p', text: 'Text').first.native).click.perform*also see Querying Forms, Data and Typing
fill_in('name, id or text', with: 'value')find('css_selector').set('value')find(:xpath, 'xpath_selector').set('value')select('text', from: 'select name, id or text ')check('name, id or text of checkbox')uncheck('name, id or text of checkbox')choose('radio button name, id or text')listbox-ex.native.sendkeys(:arrow_down)attach_file('name, id or text', 'file/name.png') Scoping
within('css_locator')within(:xpath, 'xpath_locator')within_frame('name or id')within_table('name or id')within_fieldset('name or id')Rspec Matchers Cheat Sheet
Querying
page.has_xpath?('//table/tr')page.has_css?('table tr.foo')page.has_content?('Text')page.should have_xpath('//table/tr')page.should have_css('table tr.foo')page.should have_content('Text')page.should have_no_content('Text')find_field('Text').valuefind_link('Text').visible?find_button('Send').clickfind('//table/tr').clickfind_by_id(id)locate('//*[@id='overlay'').find('//h1').clickall('a').each { |a| a[:href] }expect(page or location).to have_content('Text')expect(page).not_to have_content('Text')expect(page).to have_css('a', text: 'Text', visible: true) Movement, Scrolling and Window Size
page.execute_script('window.scrollBy(0,-200)')page.driver.browser.action.move_to(find_button(text).native).performpage.driver.browser.manage.window.maximizepage.driver.browser.manage.window.resize_to(x,y) Page Source
expect page.html.downcase.include? 'text'page.status_code.should be Rspec Expectations Cheat Sheet
200 (not supported by Selenium driver)page.driver.browser.manage.all_cookies.each {|cookie|} Scripting
result = page.evaluate_script('4 + 4
'); Debugging
save_and_open_pagealso, use Rspec Capybara Cheat Sheet
binding.pry