一些资源
-
http://gitrdoc.com/brynary/webrat
-
http://groups.google.com/group/webrat
-
http://webrat.lighthouseapp.com/
-
http://github.com/brynary/webrat
关于触发link
可以通过文本 title属性,和id属性]
<a href="/signup" title="Sign up" id="signup_link">Click here to
join!</a>
click_link "Click here to join!" # substring text
click_link /join/i # regexp text
click_link "Sign up" # substring title
click_link /sign.*up/i # regexp title
click_link /signup.*link/i # regexp id
click_link "signup_link" # exact id
webrat的源码定义
def click_link(text_or_title_or_id, options = {})
find_link(text_or_title_or_id).click(options)
end
而表单的输入框,可以通过id name属性或者label的inner text属性定位,例子如下:
输入框包括text fields, password fields和text areas
#<label for="user[email]">Enter your Email</label><input type="text"
name="user[email]" id="user_name">
fill_in "user_email", :with => "good@example" # exact id
fill_in /user.*email/, :with => "good@example" # regexp id
fill_in "user[email]", :with => "good@example" # substring name
fill_in /user[.*mail.*]/, :with => "good@example" # substring name
fill_in "Email", :with => "[email protected]" # substring label text
fill_in /enter your email/i, :with => "[email protected]" # regexp label text
对于隐藏字段的设定
# Hidden fields can be set
set_hidden_field 'user[l337_hax0r]', :to => 'true'
下拉菜单可以通过文本,name属性,label text属性来选中
# Select options can be 'selected' by inner text (an exact String or a Regexp
to match). It can optionally be selected from a particular select field, using
the usual id, name, or label text.
select "Free account"
select "Free account", :from => "Account Types"
select "Free account", :from => "user[account_type]"
select "Free account", :from => "user_account_type"
操作多选框
# Check boxes can be 'checked' and 'unchecked'
check 'Remember me'
uncheck 'Remember me'
操作单选框
# Radio buttons can be choosen, using the usual label text, name, or id.
choose "Yes"
click_button "Register"
# check for text in the body of html tags
# can be a string or regexp
assert_contain("BURNINATOR")
assert_contain(/trogdor/i)
assert_not_contain("peasants")
# check for a css3 selector
assert_have_selector 'div.pagination'
assert_have_no_selector 'form input#name'
判定页面是否有文字
# check for text in the body of html tags
# can be a string or regexp
# Matchers are verbs used with auxillary verbs should, should_not, etc.
response.should contain("BURNINATOR")
response.should contain(/trogdor/i)
response.should_not contain("peasants")
# check for a css3 selector
response.should have_selector('div.pagination')
response.should_not have_selector('form input#name')
在范围内的界定,
老猪上文已经提到selenium不支持
# selectors syntax is defined here: http://www.w3.org/TR/css3-selectors/
within 'div.pagination' do |scope|
scope.click_link "1"
end
within '.shows' do |scope|
scope.should contain("NFL")
# unfortunately, assertions don't support this currently
end
within 'form[name="search"] select[name="type"]' do |scope|
scope.should have_selector 'option[value="blah"]'
scope.should have_selector 'option[value="gah"]'
scope.should have_selector 'option[value="eep"]'
scope.should have_selector 'input:only-of-type'
scope.should have_selector 'input[name="query"]'
scope.should have_selector 'input[type="text"]'
end