Goal

Understand how to

  • Randomize tests
  • Create multiple scenarios using 1 single test using scenario outlines
  • Use random variables

We will test using the Search and View service for the lesson.

Starting code

Start tag: lesson/09 (Configurators can use lesson/08)

Steps

Now we are in lesson 4 we can identify new core services like search and view. We are going to write a test once and run it with different combinations. We will also create random variables as part of the test run so that the test scenarios can be executed with different combinations of test data and not just a single value each time the test is run.

Scenario description

We are going to create 2 scenarios for this lesson

  • Scenario outline: Login as External User, Submit a complete form and View the completed form after submission
  • Scenario: Login as External User, Submit a complete form, search the validate filing history

The first scenario will be created in H004 folder with name HappyPathOutline.feature and the second FilingHistoryValidation.feature

Scenario Outline and Create random variables

Scenario Outline takes user data in the form of the Example table and runs the scenario with different combinations.
As we mentioned earlier the file name for the first scenario will be HappyPathOutline and we are going to include the scenario description below
Scenario Description: The scenario name must be short and descriptive of what needs to be achieved.
Scenario Outline: Login as External User, Submit a complete form and View the completed form after submission
Actions: Generate 2 combinations of tests for the Register super hero scenario using random names Datatable A data table is one of the most commonly used methods for passing test data from feature files to the tests. We can pass parameters from feature files in tabular format and we can then use this data in step definition methods in the form of Lists and Maps. The way to create a datatable is the following example:
Examples:
  | YearArrival | uniform | cape | powers         |
  | 1980        | Yes     | Yes  | Agility        |
  | 1981        | Yes     | No   | Fighting Skill |
Let’s create a scenario that uses only a datatable, which enters the same name for 2 different scenarios.
  Scenario Outline: Login as External User, Submit a complete form and Search/View the completed form after submission
    Given I set application to heroes
    When I logon as External01@fostermoore.com with password External01
      And I click menu Online Services
      And I click menu Register a Super Hero
      And I enter text VERNEMAX in Super Hero Name
      And I enter text <YearArrival> in Year of Arrival on Earth
      And I select radio button <uniform> in radio button group Do you have a uniform, costume or outfit?
      And I select radio button <cape> in radio button group Do you usually or intend to don a cape?
      And I select option <powers> from dropdown Hero Powers
      And I click button Submit
    Then I expect no invalid config
      And I expect service-title Success
      And I expect text Your super hero is now registered and ready to save the world!
      And I expect text Super Hero Name > VERNEMAX 
      And I expect text Registration Date > #FORMATTED_TODAY#dd MMMM yyyy#FORMATTED_TODAY#
      And I expect text Year of Arrival on Earth > <YearArrival>
      And I expect text Uniform/costume/outfit? > <uniform>
      And I expect text Including a cape? > <cape>
      And I expect text Hero Powers > <powers>
    When I click button Back
      And I click menu Online Services
      And I click menu Search Super Heroes
    Then I expect service-title Search Super Heroes
    When I enter text VERNEMAX in Name
      And I click button Search
      And I click link VERNEMAX

    Examples:
      | YearArrival | uniform  | cape | powers         | 
      | 1980        | Yes      | Yes  | Agility        |
      | 1981        | Yes      | No   | Fighting skill |

In this case when the test execution completes we will have 2 identical results for 2 different test combinations. However we want to uniquely identify the outcome of each combination by using different names. This is where variables come in.

Randomization it’s very important from testing perspective.

In the following following example we are going to randomize the name so we can validate the scenarios easily.

Create variables
Users are able to create random variables using different formats, for example (uppercase |lowercase |titlecase |mixedcase ) also by types (character|digit|letter). The variable generation can help to randomize the names that later on the workflow can be searched, changes, etc.
In order to call the variables the user must create the variable and call via ${}. In the example above where the variable created is superheroname we can call using ${superheroname}

And I create a random 10 character variable called superheroname
And I enter text ${superheroname} in Super Hero Name

Scenario Outline: Login as External User, Submit a complete form and Search/View the completed form after submission
    Given I set application to heroes
    Then I logon as External01@fostermoore.com with password External01
      And I click menu Online Services
      And I click menu Register a Super Hero
    When I create a random 10 character variable called superheroname
      And I enter text ${superheroname} in Super Hero Name
      And I enter text <YearArrival> in Year of Arrival on Earth
      And I select radio button <uniform> in radio button group Do you have a uniform, costume or outfit?
      And I select radio button <cape> in radio button group Do you usually or intend to don a cape?
      And I select option <powers> from dropdown Hero Powers
      And I click button Submit
    Then I expect no invalid config
      And I expect service-title Success
      And I expect text Your super hero is now registered and ready to save the world!
      And I expect text Super Hero Name > ${superheroname}
      And I expect text Registration Date > #FORMATTED_TODAY#dd MMMM yyyy#FORMATTED_TODAY#
      And I expect text Year of Arrival on Earth > <YearArrival>
      And I expect text Uniform/costume/outfit? > <uniform>
      And I expect text Including a cape? > <cape>
      And I expect text Hero Powers > <powers>
    When I click button Back
      And I click menu Online Services
      And I click menu Search Super Heroes
    Then I expect service-title Search Super Heroes
    When I enter text ${superheroname} in Name
      And I click button Search
    Then I click link ${superheroname}
      And I expect no invalid config
      And I expect service-title Super Hero
      And I do not expect text Your super hero is now registered and ready to save the world!
      And I expect text Super Hero Name > ${superheroname}
      And I expect text Registration Date > #FORMATTED_TODAY#dd MMMM yyyy#FORMATTED_TODAY#
      And I expect text Year of Arrival on Earth > <YearArrival>
      And I expect text Uniform/costume/outfit? > <uniform>
      And I expect text Including a cape? > <cape>
      And I expect text Hero Powers > <powers>
    Then I click button Back
      And I expect service-title Search Super Heroes

    Examples:
      | YearArrival | uniform  | cape | powers         |
      | 1980        | Yes      | Yes  | Agility        |
      | 1981        | Yes      | No   | Fighting skill |

Recap

In this lessons we learnt the below:

  • Usage of data tables
  • We used 1 test and created 2 different combinations of tests using data tables
  • We used a random variable to randomize our names
  • Search and View services
0
0

Jump to Section