我如何从网页复制数据,并粘贴在文件中,以进一步使用ruby, watir和黄瓜



第一个场景是作为特性文件注册的一部分运行的。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

我关心的是如何使用适用于步骤的东西实现这两个特性之间的连接:Then I copy the Free user information in a data file来自feature1, When Sign in as free account retrieved from file来自feature2。

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

谢谢!

一般来说,不鼓励在特性文件之间创建依赖关系。您希望能够独立运行具有确定性结果的特性,因此通过状态耦合特性可能会产生脆弱(和易破坏)的特性。例如,如果不执行registration.feature,则不可能成功执行upgrade_accounts.feature

如果你还没有拿起黄瓜书,这是一个很好的指南和资源。它建议通过/support/hooks.rb

中的before钩子设置应用程序状态。

就像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

两个特性,两个完全独立的测试。如果你有一个单一的步骤,注入一个免费帐户到系统假设我有一个免费帐户,你不会以升级失败告终,因为注册免费帐户的步骤失败。

同时,我冒昧地减少了创建和验证帐户的步骤。在这个场景中,所有的导航等都不是必需的。

最新更新