— actions —
visit
'/about'click_on
'Ok!'click_link
'about'click_button
'Save'scripting
execute_script
'window.scrollTo(0, 700)'res =
evaluate_script
'document.charset'text inputs and text areas
fill_in
'hello-box', with:
'Howdy neighbor!'selects
selectunselect
'Purple''Purple',
from:
'color-box'radio buttons
choose
'Funny third option'checkboxes
checkuncheck
'Remember me'files
attach_file
'cat-pic', 'cat.jpg'history
go_back
'n'
go_forward
— matchers
and predicates
—
expect
(page).to
have_texthave_no_text
page.
has_text?has_no_text?
'Ring to rule them all', count: 1'Duck', minimum: 10'Dwarf', maximum: 7"Ocean's team member", between: 11..13'Justice for all'
allias:
have_contenthave_no_content has_content?has_no_content?expect
(page).to
page.
have_selector
has_selector?
have_no_selector
has_no_selector?
'form.sign-up .alert':css:xpath:button:link:field:select:table
Btw, try to click on underlined code for more options.
'nav li.active', count: 1'section', between: 2..4'.cta-btn', maximum: 2'article > p', mininum: 5'a[href$="cheatrags.com"]'
'//*[contains(., "Kapow!")]''Save''Profile', href: ‘/profile’'Employment', with: 'Liquor Ace''known-as', with: 'Chef''Biography', type: 'textarea''fancy-checkbox', checked: true
'pills', options: [’Red’, ‘Blue’]'pills', selected: ‘Red’'Your state', with_options: [‘NY’, ‘CA’]
'Analytics'- have_css has_css?have_no_css has_no_css?'nav li.active', count: 1'section', between: 2..4'.cta-btn', maximum: 2'article > p', mininum: 5'a[href$="cheatrags.com"]'
- have_xpath has_xpath?have_no_xpath has_no_xpath?'//*[contains(., "Kapow!")]'
- have_button has_button?have_no_button has_no_button?'Save'
- have_link has_link?have_no_link has_no_link?'Profile', href: ‘/profile’
- have_field has_field?have_no_field has_no_field?'Employment', with: 'Liquor Ace''known-as', with: 'Chef''Biography', type: 'textarea''fancy-checkbox', checked: true
- have_select has_select?have_no_select has_no_select?'pills', options: [’Red’, ‘Blue’]'pills', selected: ‘Red’'Your state', with_options: [‘NY’, ‘CA’]
- have_table has_table?have_no_tablehas_no_table?'Analytics'
have_titlehas_title?
have_no_titlehas_no_title?
more about

some other
![RSpec Matchers [cheatsheet]](/images/titles/rspec-matchers.png)
— finders —
page.
find
first
all
'ul.menu > li':id:field:link:button:link_or_button:checkbox:radio_button:file_field:select:option
,
'main-content', 'first-name''pin', type: 'password''subscribe', checked: true'hello-box', with: 'Hello!'
, 'T-600''T-600', href: '/t-600-specs'
,
'Launch',
'Ok',
'subscribe',
'Yes',
'cat-pic',
'Your country',
'New Zealand'- find_by_id'main-content'
- find_field'first-name''pin', type: 'password''subscribe', checked: true'hello-box', with: 'Hello!'
- find_link'T-600''T-600', href: '/t-600-specs'
- find_button'Launch'
These finders are chainable: page.
find
('#navbar').find_link
(’Sign Up’).click scoping
withinwithin_framewithin_windowwithin_tablewithin_fieldset
".login""video-player""wnd""Users""Skills"
do # whatever you like
end
— element —
el.
trigger
'play''focus''mouseup'
- el.click
- el.double_click
- el.right_click
- el.hover
- el.drag_toother_el
- el.set'new value'true
- option.select_option
- option.unselect_option
- el.native(access to driver specific methods)
- elel.native.send_keys[:command, 'a'], :backspace'Helo!', :left, :left, 'l', :enter:tab, :tab, :tab
:left :up :right :down
:backspace :clear
:return/:enter
:tab :shift :control :alt :meta/:command
:pause :escape :space
:backspace :clear
:return/:enter
:tab :shift :control :alt :meta/:command
:pause :escape :space
el
[
:title:href:name:placeholder
]
- el.text
- el.tag_name
- el.value
- el.checked?
- el.selected?
- el.visible?
- el.disabled?
— windows and modals —
-
wnd =window_opened_by{click_on‘Sign In’ }
-
wnd =switch_to_window{ title == 'Twitter login' }
within_window
->{ page.title == 'Twitter login' }windows.lastwnd
do
# whatever you like
end
- wnd.resize_to800, 600
- wnd.close
- wnd.maximize
- wnd.size
- wnd.current?
- wnd.closed?
- wnd.exists?
- expect(wnd).tobecome_closed
msg =
click_on
accept_alert
do
click_on
'Show Alert'
end
dismiss_confirmaccept_confirm
do
click_on
'Delete'
end
accept_promptdismiss_prompt
with: ‘Hello!’ do
do
click_on
'Say hello.'
end