2

Description: As a test developer, I would like to use a single scenario to test 3 different environments.

Simplified Scenario example:

  @smoke
  Scenario: Login to the login page and assert that the user is logged in
    Given User navigates to the page
    And User enters valid login credentials
    When User clicks on the login button
    Then Landing page can be seen

Data ( These are grabbed from a property file - converted to POJO ) :

Env1.class
url = www.environment1.com
username = john
password = doe1

Env2.class
url = www.environment2.com
username = john2
password = doe2

Env2.class
url = www.environment3.com
username = john3
password = doe3

Test Setup

  1. Each environment has its own test runner ( failsafe )
  2. Each environment runs in parallel.
  3. Test runs and is built via ~mvn clean verify
  4. Tests are property file dependant as environments may change.

Potential solution: Is there a way to pass POJOs in the Example Table? or Cucumber's data table?

I am new to BDD and Cucumber - any help would be great. Thank you.

TLDR: is there a way to pass the Prop File variable in the Examples Table in Cucumber?

| URL | Username | Password | 
| env1.getUrl | env1.getUsername | env1.getPassword |

So it'll be

 @smoke
  Scenario: Login to the login page and assert that the user is logged in
    Given User navigates to the page <URL>
    And User enters valid login credentials <Username> and <Password>
    When User clicks on the login button
    Then Landing page can be seen
  • When you say that each environment has its own test runner, how is the environment passed down to the runner? Is it maven which is running the same scenario for all three environments? Is there a way to know the current environment at runtime in the Step Definition code? – cbliard Jan 09 '20 at 09:21
  • I am using a prop file per environment. And each runner is triggered via `verify` – Gheeno San Pascual III Jan 09 '20 at 16:40

2 Answers2

1

You can use the scenario outline to run the same scenario with different data for each run. But it will be not parallel. It is sequential. The feature file is,

  @smoke
  Scenario Outline: Login to the login page and assert that the user is logged in
    Given User navigates to the page <URL>
    And User enters valid login credentials <Username> and <Password>
    When User clicks on the login button
    Then Landing page can be seen
  Example:
  |URL                 |UserName|Passowrd|
  |www.environment1.com|john1   |doe1    |
  |www.environment2.com|john2   |doe2    |    
  |www.environment2.com|john3   |doe3    |

You can use a single runner class. No need to use either property file nor pojo class.

Murthi
  • 5,299
  • 1
  • 10
  • 15
0

You can achieve that using cucumber extension for BDD2. By using it you can have external examples or you can use properties in example as below:

| URL | Username | Password | 
| ${env1.getUrl} | {env1.getUsername} | ${env1.getPassword} |

Alternate is you can use CSV or XML data provider.

In order to use pojo, you need to modify your step definition to accept either DataTable or POJO as argument. When accepting POJO as argument you need to write transformer.

When you use cucumber extension you can also use QAFTestStep which accepts POJO without addition effort. Here you can find step examples and feature file.

user861594
  • 5,733
  • 3
  • 29
  • 45