关于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 idwebrat的源码定义
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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
路过,博主的博客真漂亮。。
[***.116.15.85]2024年04月05日 23时32分53秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
三郎数据结构算法学习笔记:顺序存储二叉树
2019-04-26
三郎数据结构算法学习笔记:线索二叉树
2019-04-26
解释Spring支持的几种bean的作用域。
2019-04-26
Spring框架中都用到了哪些设计模式?
2019-04-26
什么是MyBatis?
2019-04-26
MyBatis的优点和缺点
2019-04-26
#{}和${}的区别是什么?
2019-04-26
LeetCode题解(1508):子数组和排序后的区间和(Python)
2019-04-26
LeetCode题解(1509):三次操作后最大值与最小值的最小差(Python)
2019-04-26
LeetCode题解(1510):石子游戏IV(Python)
2019-04-26
LeetCode题解(1497):检查数组对是否可以被k整除(Python)
2019-04-26
LeetCode题解(0781):森林中的兔子(Python)
2019-04-26
LeetCode题解(0930):和相同的二元子数组(Python)
2019-04-26
LeetCode题解(0939):最小面积矩形(Python)
2019-04-26
LeetCode题解(0954):二倍数对数组(Python)
2019-04-26
LeetCode题解(0957):N天后的牢房(Python)
2019-04-26
LeetCode题解(0974):和可被K整除的子数组(Python)
2019-04-26
LeetCode题解(0981):基于时间的键值存储(Python)
2019-04-26
LeetCode题解(0992):K个不同呢的子数组(Python)
2019-04-26
LeetCode题解(1001):网格照明(Python)
2019-04-26