测试web常用到的一些watir方法
上一篇 /
下一篇 2014-08-21 13:36:45
/ 个人分类:网页测试
Load the Watir
library
|
require 'watir'
|
Open a browser
(default: Internet Explorer)
|
browser = Watir::Browser.new:ie |
Open Browser at the specified URL
|
browser = Watir::Browser.start("http:) |
Go to a specified URL
|
browser.goto("http:) |
Close the browser
|
browser.close |
Text box or text area用法 |
Text box or text area
|
t = browser.text_field(:name, "username") |
Enter text in a text box
|
t.set("mickey mouse") |
Enter multiple lines in a multi-line text box
|
t.set("line 1\nline2") |
Butto/check box/drop down list/form/link/table的用法 |
Button
|
b = browser.button(:value, "Click Here") |
Set radio button or check box
|
c.set r.set |
Drop down list
|
d = browser.select_list(:name, "month") |
Check box
|
c = browser.checkbox(:name, "enabled") |
Radio button
|
r = browser.radio(:name, "payment type") |
Form
|
f = browser.form(:name, "address") f = browser.form(:action, "submit") |
Link
|
l = browser.link(:url, "http:) l = browser.link(:href, "http:) |
Table cell in a table (2nd row, 1st column)
|
td = browser.table(:name, 'recent_records')[2][1] |
Return the html of the page or any element
|
browser.html e.html |
Return the text of the page or any element
|
browser.text e.text |
Return the title of the document
|
browser.title |
Click a button or link
|
b.click l.click |
Clear an element
|
t.clear c.clear r.clear |
Select an option in a drop down list
|
d.select "cash" d.set "cash" |
Clear a drop down list
|
d.clearSelection |
Submit a form
|
f.submit |
Get text from status bar.
|
browser.status=> "Done" |
Return true if the specified text appears on the page
|
browser.text.include? 'llama' |
Return the contents of a table as an array
|
browser.table(:id, 'recent_records').to_a |
收藏
举报
TAG: