简体   繁体   English

如何从网页复制数据并将其粘贴到文件中以便与ruby,watir和cucumber一起使用?

[英]How do I copy data from web page and paste it in file for further use with ruby, watir and cucumber?

The first scenario is run as part of the feature file registration.feature (feature1) and has the following content: 第一个场景作为特征文件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 

Then I would like to run the following feature under the upgrade_accounts.feature(feature2) 然后我想在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 

My concerns are about how I implement the connection between these two features using something that applies to step: Then I copy the Free user information in a data file from feature1 and When Sign in as free account retrieved from file on feature2. 我关心的是如何使用适用于步骤的内容实现这两个功能之间的连接: Then I copy the Free user information in a data file feature 1中Then I copy the Free user information in a data file到feature1中, When Sign in as free account retrieved from file从feature2上的When Sign in as free account retrieved from file ,将其复制。

So I guess the question is: What approach(gem) would be best to use in order to copy data from web page into a file and the read it and use it again? 所以我想问题是: 最好使用哪种方法(gem)将数据从网页复制到文件中并读取并再次使用它?

Thank you! 谢谢!

In general, creating dependencies between features files is discouraged. 通常,不鼓励在功能文件之间创建依赖关系。 You want to be able to run features independently with deterministic results, so coupling features through state will likely produce brittle (and breakable) features. 您希望能够使用确定性结果独立运行要素,因此通过状态耦合要素可能会产生脆弱(且易碎)的特征。 For example, it would be impossible to successfully execute upgrade_accounts.feature without executing registration.feature . 例如,如果不执行registration.feature ,就不可能成功执行upgrade_accounts.feature

If you haven't picked up The Cucumber Book , it's good guide and resource. 如果你没有拿起黄瓜书 ,这是很好的指导和资源。 It recommends setting up application state through before hooks in /support/hooks.rb 它建议在/support/hooks.rb之前设置应用程序状态

Like Orde says, each scenario is unique & independent: 像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

Two features, two completely separate tests. 两个功能,两个完全独立的测试。 If you have one single step that injects a free account into the system Given I have a free account , you will not end up with have a failure in upgrading because the step to register the free account failed. 如果您只有一个步骤可以将免费帐户注入系统如果我有一个免费帐户 ,您最终将无法升级,因为注册免费帐户的步骤失败。

Also, I took the liberty to cut down on the steps to create and verify the account. 此外,我冒昧地减少了创建和验证帐户的步骤。 All the navigation and such are not necessary in the scenario. 在场景中不需要所有导航等。 That is done in the step definition. 这是在步骤定义中完成的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM