我想验证具有特定href的链接是否存在于页面上。我目前正在做我应该看到“/ some-link-here”,但似乎失败。我怎样才能确保链接存在,而不必点击+我应该在“/ some-link-here”页面?确定链接是否存在w黄瓜/水豚
3
A
回答
5
您将需要添加自定义步骤
Then /^"([^\"]*)" should link to "([^\"]*)"(?: within "([^\"]*)")$/ do |link_text,
page_name, container|
with_scope(container) do
URI.parse(page.find_link(link_text)['href']).path.should == path_to(page_name)
end
end
您可以像使用Then "User Login" should link to "the user_login page"
步骤,USER_LOGIN是你的路线
0
我用jatin的答案的名字,但有一个单独的作用域步:
When /^(.*) within ([^:]+)$/ do |step, parent|
with_scope(parent) { When step }
end
Then /^"([^\"]*)" should link to "([^\"]*)"$/ do |link_text, page_name|
URI.parse(page.find_link(link_text)['href']).path.should == path_to(page_name)
end
然后,我有这个在我的测试:
step '"my foods" should link to "food_histories" within ".tabs"'
这在我的路径:
# note: lots not shown
def path_to(page_name)
case page_name
when /^food_histories$/
food_histories_path
end
end
0
这是我做了我自己,很简单,但它确实意味着你硬编码您的网址这是诚实的,因为它使你的测试很脆不理想。特别是如果您使用的是第三方网址!
但是,如果您使用的是您管理的网址,并且很乐意继续进行此测试,那就去做吧。
Then /^the link is "(.*?)"$/ do |arg1|
page.should have_xpath("//a[@href='" + arg1 + "'][@target='_blank']")
end
相关问题
- 1. 点击链接使用水豚/黄瓜
- 2. 黄瓜vs水豚
- 3. 导轨+黄瓜+水豚:匹配确切链接文本
- 4. 水豚黄瓜匹配器
- 5. 传递黄瓜和水豚
- 6. 黄瓜/水豚对硒?
- 7. 黄瓜水豚步功能
- 8. 黄瓜,水豚和ElementNotFound
- 9. 黄瓜/水豚/硒 - 设置
- 10. 黄瓜水豚fill_in失败
- 11. 表订购黄瓜水豚
- 12. 水豚和黄瓜CSS定位
- 13. 黄瓜和水豚,点击非链接或按钮元素
- 14. 链接不触发通过黄瓜,水豚
- 15. 导轨,黄瓜,水豚 - 黄瓜一步不能按下按钮
- 16. 超时::错误与硒/水豚/黄瓜
- 17. 水豚/黄瓜找不到收音机
- 18. 黄瓜+水豚+硒:选择文本
- 19. 水豚黄瓜只有空白页
- 20. 水豚&黄瓜|获取饼干
- 21. 语法错误黄瓜+水豚
- 22. 黄瓜/水豚场景使用引号
- 23. 黄瓜/水豚表中的变量
- 24. 轨,黄瓜,水豚:会话不持久
- 25. 黄瓜/水豚测试x标签
- 26. 黄瓜/水豚找到()不重试
- 27. 点击图片使用黄瓜水豚
- 28. 使用黄瓜/水豚测试ActiveMerchant
- 29. 黄瓜/水豚undefined方法'访问'
- 30. 迭代列阵水豚黄瓜