我有以下航空公司网站的导航路径:
Page1--->Page2(booking engine/booking happens here)----->page3(giving booking number)----->page4(opening booking details)
Page4 有两个弹出链接,点击每个链接都会打开两个弹出窗口。 我必须通过一个一个打开它们来检查两个弹出窗口的详细信息。
小黄瓜:
Scenario:...
Line1 Given I have a url
Line2 When I open the page1
Line3 And I go to page 2
Line4 And do the booking
Line5 And I go to page 3
Line6 And I enter booking number
Line7 And I click enter
Line8 Then it should open page4
Line9 When I click popup1 link1
Line10 Then It should open popup1
Line11 And Details of popup1 should be proper
Line12 When I click on popup2 link
Line13 Then It should open popup2
Line14 And details of popup2 should be proper
上面的Gherkin在单场景下存在
multiple When-Then pairs
的问题,不推荐使用。从第 1 行到第 8 行是打开两个弹出窗口之间的公共代码。我可以在上面写成:
Background:
Line1 Given I have a url
Line2 When I open the page1
Line3 And I go to page 2
Line4 And do the booking
Line5 And I go to page 3
Line6 And I enter booking number
Line7 And I click enter
Scenario: First Popup
Line8 When I click popup1 link1
Line10 Then It should open popup1
Line11 And Details of popup1 should be proper
Scenario: Second Popup
Line12 When I click popup1 link1
Line13 Then It should open popup1
Line14 And Details of popup1 should be proper
现在第 1 行到第 7 行很常见,但现在的问题是它将在两个场景的步骤定义中从第 1 行到第 7 行复制代码和执行。
所以我想问一下处理这些场景的正确方法应该是什么,以便小黄瓜中的场景测试个人行为并且在步骤定义中也没有代码重复?