关于cucumber中webrat 模拟浏览器事件操作
发布日期:2021-09-29 20:08:34 浏览次数:3 分类:技术文章

本文共 3320 字,大约阅读时间需要 11 分钟。

一些资源
- [url]http://gitrdoc.com/brynary/webrat[/url]
- [url]http://groups.google.com/group/webrat[/url]
- [url]http://webrat.lighthouseapp.com/[/url]
- [url]http://github.com/brynary/webrat[/url]
关于触发link
可以通过文本 title属性,和id属性]
Click here to   join!
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
#   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 => "good@example.com"       # substring label text   fill_in /enter your email/i, :with => "good@example.com" # 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')
在范围内的界定,[url=hlee.iteye.com]老猪[/url]上文已经提到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

转载地址:https://blog.csdn.net/horace_lee/article/details/83712229 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:脱离Rails环境用ruby对普通网页进行测试
下一篇:关于rails 测试中selenium的定位页面元素

发表评论

最新留言

路过,博主的博客真漂亮。。
[***.116.15.85]2024年04月05日 23时32分53秒