0

第一个场景作为功能文件registration.feature(feature1)的一部分运行,内容如下:

Scenario: User can register as a Free account
 Given  I am on the home page
 When   I navigate to the Register page
 And    set all required fields for "Free" on the page
 And    check that info about successful registration is shown
 And    activate account
 Then   I copy the Free user information in a data file

然后我想在upgrade_accounts.feature(feature2)下运行以下功能

Feature:    Upgrade accounts
As an QA Engineer
I would like to upgrade my accounts to other types
So I can make sure upgrade functionality is working properly

Scenario: Existing free account is upgraded to premium
Given  I navigate to the login page
When   Sign in as free account retrieved from file
And    I navigate to updgrade accounts 
And    I select premium account and submit
Then   Verify premium package is active

我担心的是我如何使用适用于 step 的东西来实现这两个功能之间的连接:Then I copy the Free user information in a data filefrom feature1 和When Sign in as free account retrieved from fileon feature2。

所以我想问题是:最好使用哪种方法(gem)将数据从网页复制到文件中并读取并再次使用它?

谢谢!

4

2 回答 2

1

通常,不鼓励在功能文件之间创建依赖关系。您希望能够以确定的结果独立运行功能,因此通过状态耦合功能可能会产生脆弱(易碎)的功能。upgrade_accounts.feature例如,不执行就不可能成功执行registration.feature

如果您还没有拿起The Cucumber Book,它是很好的指南和资源。它建议通过 before hooks in 设置应用程序状态/support/hooks.rb

于 2013-03-22T23:22:11.317 回答
1

正如 Orde 所说,每个场景都是独一无二且独立的:

Scenario: User can register as a Free account
Given I am on the home page
When I register for a free account
Then I get a message that registration is successful
And my account is active

Scenario: Existing free account is upgraded to premium
Given I have a free account
When I updgrade my account to a premium account
Then my premium package is active

两个功能,两个完全独立的测试。如果您有一个将免费帐户注入系统的步骤鉴于我有一个免费帐户,您最终不会因为注册免费帐户的步骤失败而导致升级失败。

此外,我冒昧地减少了创建和验证帐户的步骤。场景中不需要所有导航等。这是在步骤定义中完成的。

于 2013-03-22T23:45:48.130 回答