我自动使用黄瓜和红宝石。我的方案如下。
Given I'm on home page
When i click on links
Then it should redirect to corresponding pages.
为了实现,我已完成迭代以点击第二步中的所有链接。
要做到这一点,我每次都要回到主页然后进行验证。我是否每次都必须重复第二步步骤实现,还是可以跳过第三步并在第二步中实现所有内容?
答案 0 :(得分:1)
您可以在表格中查看以下内容:
Background: Member should open homepage
Given member goes to home page
@javascript
Scenario: Member should go to correct url by clicking links in head menu
Then member should ensure that links in the table go to correct url
| Spor Giyim | /spor-giyim |
| Kadın | /kadin |
| Erkek | /erkek |
| Ayakkabı & Çanta | /ayakkabi-canta |
Ruby部分应该是这样的:
When(/^member should ensure that links in the table go to correct url$/) do |table|
# table is a Cucumber::Core::Ast::DataTable
links = table.raw
links.each do |line|
link = line[0]
target_url = line[1]
click_link(link)
url = page.current_url
expect(url).to include target_url
end
end
答案 1 :(得分:1)
我喜欢一种不那么迫切的方法:
Given I am on home page
When I collect a list of links and the text from the header menu
Then visiting each link should return a page where the title matches the link text
或者它可能与alt文本匹配,或者您匹配这些行中的URL或其他内容。我认为上面显示的一种强制性方法使得添加到页面中的新项目不会被检查,并且任何掉落的内容都会被检查。
如果你想让它更具必要性并且有一个列表,我会验证只有那些链接出现,并且如果新链接出现意外,它会引发错误。