无法在黄瓜中单独实现两个步骤定义
Can't implement two step definitions individually in cucumber
我正在使用 Cucumber 和 ruby 进行自动化。我的场景如下。
Given I'm on home page
When i click on links
Then it should redirect to corresponding pages.
为了实现,我在第二步中反复点击了所有链接。
为此,我每次都必须回到主页,然后进行验证。我是否必须每次都重复第二步的实施,或者我可以跳过第三步并在第二步中实施所有内容吗?
您可以在 table 中执行以下操作:
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
我喜欢不太强制的方法:
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
或者它可能匹配替代文本,或者您匹配 URL 或类似的内容。我认为上面显示的命令式方法使得添加到页面的新项目不会被检查,任何脱落的东西都会被检查。
如果你想让它更命令并有一个列表,我会验证只有那些 link 出现并且如果新的 link 意外出现它会抛出错误。
我正在使用 Cucumber 和 ruby 进行自动化。我的场景如下。
Given I'm on home page
When i click on links
Then it should redirect to corresponding pages.
为了实现,我在第二步中反复点击了所有链接。
为此,我每次都必须回到主页,然后进行验证。我是否必须每次都重复第二步的实施,或者我可以跳过第三步并在第二步中实施所有内容吗?
您可以在 table 中执行以下操作:
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
我喜欢不太强制的方法:
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
或者它可能匹配替代文本,或者您匹配 URL 或类似的内容。我认为上面显示的命令式方法使得添加到页面的新项目不会被检查,任何脱落的东西都会被检查。
如果你想让它更命令并有一个列表,我会验证只有那些 link 出现并且如果新的 link 意外出现它会抛出错误。