WebAUTOTESTAPI使用文档注释:#跟id默认是css,可以跟多个class样式,用.串联:text='保存'二层判断1、visit(url)导航到指定的URL,该URL可以是相对URL或绝对URL。visit('/foo')visit(')Capybara.app_host='具体地址在配置文件中设置时,框架中可以简写成如下格式:visit('/')#visitsthegooglehomepage2、Clickinglinksandbuttonsclick_link('id-of-link')#参数为abuttonbyid,textorvalueclick_link('LinkText')click_button('Save')#参数为:alinkbyidortextclick_on('LinkText')#参数为以上2者都可click_on('ButtonValue')3、Interactingwithformsfill_in('FirstName',:with='John')fill_in('Password',:with='Seekrit')fill_in('Description',:with='ReallyLongText...')#LocateatextfieldortextareaandfillitinwiththegiventextThefieldcanbefoundviaitsname,idorlabeltext.choose('ARadioButton')#aradiobuttonandmarkitaschecked.check('ACheckbox')#acheckboxandmarkitaschecked.uncheck('ACheckbox')#acheckboxandmarkuncheckit.attach_file('Image','/path/to/image.jpg')#findafilefieldonthepageandattachafilegivenitspath.select('Option',:from='SelectBox')#Findaselectboxonthepageandselectaparticularoptionfromit.例子:find('div.datagrid-view2').find('tr',:text='综合管理部测试').check('department_id')4、Queryingpage.has_selector?('tabletr')page.has_selector?(:xpath,'//table/tr')#Checksifagivenselectorisonthepageorcurrentnodepage.has_no_selector?(:content)#Checksifagivenselectorisnotonthepageorcurrentnodepage.has_xpath?('//table/tr')#ChecksifagivenXPathexpressionisonthepageorcurrentnode.page.has_css?('tabletr.foo')#ChecksifagivenCSSselectorisonthepageorcurrentnode.page.has_text?('loremipsum',between:2..4)#Checksifthepageorcurrentnodehasthegiventextcontent,ignoringanyHTMLtagsandnormalizingwhitespace.例子:find('tr',text:'家乐福').has_text?('家乐福')5、Findingfind_field('FirstName').value#Findaformfieldonthepage.find_link('Hello').visible?#Findalinkonthepage.find_button('Send').click#Findabuttononthepage.find(:xpath,//table/tr).clickfind(#overlay).find(h1).click#FindanElementbasedonthegivenarguments.all('a').each{|a|a[:href]}#Findallelementsonthepagematchingthegivenselectorandoptions.例子:find('div.combobox-item',:text='酷派8150').clickfind('div.combo-panel.panel-body.panel-body-noheader').find('div.combobox-item',:text='华为AscendD1').clickfind('textarea#checkOpinion').set'通过'all('input.combo-text.validatebox-text')[0].set'2013-11-07'all('span.combo-arrow')[2].click6、Scopingwithin(li#employee)dofill_in'Name',:with='Jimmy'endwithin(:xpath,//li[@id='employee'])dofill_in'Name',:with='Jimmy'endwithin_table('Employee')dofill_in'Name',:with='Jimmy'end例子:within_frame('frame销售明细')doclick_link('查询')endwithin_frame('frame订货管理')dofind('span.combo-arrow').clickfind('div.combobox-item',:text='已审核').clickfind('textarea#checkOpinion').set'通过'end7、Scriptingpage.execute_script($('body').empty())execute_script$('#roleCombo').combobox('setValue','#{hash[角色].to_s}')8、TABLEtable.hashes.eachdo|hash|drop_num=hash[工号].to_sdrop_num=ifdrop_num==空$changepage.find('input[name=employeeCode]').setdrop_numEnd9、assertassert_selector('div.panel.window',:text='启用账号')