Show Menu
Cheatography

Capybara Cheat Sheet Cheat Sheet by

capybara

Click

click_­button 'text on button'
click_­button 'id'
click_­button 'title'
click_­button 'value'
click_on 'link_o­r_b­utt­on_text'
click_link 'link_id'
click_link 'link_title'
click_link 'link_text'
click_on 'link_o­r_b­utt­on_­value'
find('css_se­lector').click
find(:­xpath, 'xpath_­sel­ector').click

Type

fill_in 'name', with: 'text to type in field'
fill_in 'id', with: 'text to type in field'
fill_in 'label', with: 'text to type in field'
find('css_se­lector').set­('text to type in field')
find(:­xpath, 'xpath_­sel­ector').set­('text to type in field')

Other Actions

select 'text of choice', :from => 'selec­t_id'
select 'text of choice', :from => 'selec­t_name'
select 'text of choice', :from => 'selec­t_l­abe­l_text'
check('name_o­f_c­heckbox')
check('id_of_­che­ckbox')
check('text_o­f_c­hec­kbo­x_label')
uncheck('name_i­d_o­r_t­ext­_of­_ch­eckbox')
attach­_file('name', 'path/­to/­fil­e/t­o_u­plo­ad.p­ng')
attach­_file('id', 'path/­to/­fil­e/t­o_u­plo­ad.p­ng')
attach­_file('label_text', 'path/­to/­fil­e/t­o_u­plo­ad.p­ng')
choose('radio_­but­ton­_name')
choose('radio_­but­ton_id')
choose­('radio button label text')

Capy

 

Navigate

visit 'url'
page.d­riv­er.b­ro­wse­r.s­wit­ch_­to.w­indow(window­_handle)
my_las­t_w­in_­handle = page.d­riv­er.b­ro­wse­r.w­ind­ow_­han­dle­s.last
my_ori­gin­al_­win­_handle = page.d­riv­er.b­ro­wse­r.w­ind­ow_­han­dle­s.first
page.d­riv­er.b­ro­wse­r.s­wit­ch_­to.a­le­rt.a­ccept

Scoping

within('css_l­ocator')
within­(:x­path, 'xpath­_lo­cator')
within­_fr­ame('name')
within­_fr­ame('id')
within­_fr­ame('index')
Anything in the block is scoped by the within. e.g. use with block syntax:
within­('#­div­_id') do
 ­ ­ ­cli­ck_­but­ton­('b­utt­on_id')
end

Verify

expect­(pa­ge).to have_c­ont­ent­('words on page')
expect(location).to have_c­ont­ent­('words in an area')
expect(page_o­r_l­ocation).to_not have_c­ont­ent­('u­nex­pected words')
expect­(cu­rre­nt_­url).to have_c­ont­ent­('p­art­/or­_al­l/o­f_url')
expect­(pa­ge).to have_s­ele­ctor('css_se­lector')
expect­(pa­ge).to have_s­ele­cto­r(:­xpath, 'xpath_­sel­ector')
expect­(pa­ge).to have_s­ele­ctor('css_se­lector', count: 12)
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Selenium WebDriver Cheat Sheet Cheat Sheet
          Cypressio Cheat Sheet
          ISTQB Test Automation Engineering Cheat Sheet