我有一个功能文件
Feature: Create Profile
Scenario: Create Profile
Given I want to create a profile
When I create a profile
Then I should be navigated to Home Page
Then sign out link should exist
所以上面的操作都运行正常并断言它确实回到了主页并且存在退出链接。
现在我有另一个功能文件。
Feature: Go to my account page
Scenario: Go to my account page
Given I want to go to my account page
When I go to my account page
Then I should be navigated to the my account page
在运行"When I go to my account page"
步骤之前,用户应"Create Profile"
。
所以我做的是我附加了
When I create a profile
Then I should be navigated to Home Page
Then sign out link should exist
在When I go to my account page
之前。
但我发现我复制了“创建配置文件”功能/场景中的相同代码。
如何在“转到我的帐户页面”方案中运行整个“创建个人资料”功能/方案?
我正在使用带有Selenium和JUnit的cucumber-jvm。
答案 0 :(得分:1)
您是否看到了背景DSL功能?它适用于你的情况,但可能不是你真正要求的。在这种情况下,您可以要求用户通过以下方式创建个人资料:
Feature: Create Profile
Background:
Given I create a profile
And I should be navigated to Home Page
And sign out link should exist
Scenario: Create Profile
# do nothing because all actions are in background
Scenario: Go to my account page
When I go to my account page
Then I should be navigated to the my account page
但是您必须将两个要素文件合并到一个要素文件中。
另请查看@Before和@After黄瓜注释 - 以便您可以运行一些代码来初始化(或创建)您的测试帐户(如果之前的解决方案对您不起作用)。
答案 1 :(得分:1)
Create Profile
功能指定Given / When / Then,因为这是推动功能实现的原因。
许多其他功能需要存在有效的配置文件。您不应通过重复Create Profile
中的规范来为这些功能创建配置文件。相反,在Given I have a valid profile
(可能在背景部分)中包含一些内容,并将其连接到创建配置文件的fixture代码。