0

The first scenario is run as part of the feature file registration.feature (feature1) and has the following content:

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)

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.

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?

Thank you!

Bastian
  • 101
  • 2
  • 4
  • 1
    Does anything in this other [question/answer](http://stackoverflow.com/questions/11325947/can-i-copy-a-text-on-a-webpage-and-paste-it-in-a-text-file?rq=1) help? – summea Mar 22 '13 at 21:34

2 Answers2

1

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.

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

orde
  • 5,233
  • 6
  • 31
  • 33
  • Agree strongly here. Sometimes you can break this rule, especially with regard to things like say an admin account that may be difficult to create, and is never deleted or altered. I make the use of some pre-created data, but only for situations where I am not creating or destroying. It saves time, but use with care For other things all my data object (like a 'user' object) know how to create themselves in the system, usually via UI or direct DB calls if supported. – Chuck van der Linden Mar 27 '13 at 00:30
1

Like Orde says, each scenario is unique & independent:

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.

Dave McNulla
  • 2,006
  • 16
  • 23