我有一个特征文件
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
之前。
但是我看到我已经复制了"Create Profile“特性/场景中的相同代码。
如何在“转到我的帐户页面”方案中运行整个“创建配置文件”功能/方案?
我正在使用带有Selenium和JUnit的cucumber-jvm。
发布于 2012-04-24 21:11:26
你看到背景的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
但您必须将这两个特征文件合并为单个特征文件。
另外,还可以查看@After和@After cucumber注释-这样,如果之前的解决方案对您不起作用,您可以运行一些代码来初始化(或创建)您的测试帐户。
发布于 2012-07-26 17:15:18
Create Profile
特性指定了给定的/When/Then,因为这是驱动特性实现的原因。
许多其他功能将需要存在一个有效的配置文件。您不应该通过重复Create Profile
中的规范来为这些特性创建概要文件。相反,应该包含一些类似于Given I have a valid profile
的东西(可能在背景部分),并将其连接到创建概要文件的fixture代码。
https://stackoverflow.com/questions/10291303
复制相似问题