How to use the scenario as prerequisite of another scenario

Viewed 572

first feature file

Feature: CRMSmokeTest
    In order to make sure that CRM Key functionalities working as expected.
Background:     
    Given I have entered the CRM URL

Scenario Outline:Quick Search using AccountID
    Given AccountID is selected in The Quick Search
    When user enter the <AccountID> in search field
    And Click on Quick Search button
    And Close the Alerts
    Then Title of the page contains <AccountID>
    Examples:
    | AccountID |
    | 116999    |

Second Feature File

Feature: CRM Ticket Open, Add and Amend
    In order to verify thay user able to open and amend existing ticket
    Also to verify that user is able to create a new Ticket
Background: 
Given I have entered the CRM URL
And AccountID is selected in The Quick Search
@mytag
Scenario Outline: Add a new Ticket
    When user enter the <AccountID> in search field
    And  Click on Quick Search button
    And  Close the Alerts
    Then Title of the page contains <AccountID>
    When User click on Add New link on Ticket Section
    And Select the <Departmnet> and <SubTeam> from the list
    And Enter the <Subject> of the ticket
    And Select the <Product>
    And Select the <TicketCategory> and <TicketSubCategory>
    And Enter the <Comments> and <PersonSpokeTo>
    And Click on Finish
    Then A new Ticket is created
Examples: 
| AccountID | Department        | SubTeam         | Subject     | Product        | TicketCategory     | TicketSubCategory | Comments      |
| 116999    | Customer Services | ContractEnquiry | Test Ticket | Home Insurance | Account Management | Customer Zone     | Test Comments |

I would like to use the Scenario in my first feature file as the prereq of my scenario in second feature file.

  1. What is the best practice to so

  2. Also When filling a big data form what is the best approach to write scenario. The way I have written the scenario in second feature file is the only approach or we can write this better way?

1 Answers

Calling a different scenario because it satisfies the prerequisites of the current scenario breaks the isolation required to make each scenario runnable on its own. No scenario should rely on any other scenario.

Instead of copying and pasting the steps from the first scenario, write a short Given step that performs the same things as the first scenario.

Judging on the scenario title, create a Given step similar to:

Scenario Outline: Add a new Ticket
    # New 'Given' step that basically does the same thing as scenario #1
    Given user performed a quick search for account <AccountID>

    # Now continue on with the rest of the scenario
    When User click on Add New link on Ticket Section
    And Select the <Departmnet> and <SubTeam> from the list
    And Enter the <Subject> of the ticket
    And Select the <Product>
    And Select the <TicketCategory> and <TicketSubCategory>
    And Enter the <Comments> and <PersonSpokeTo>
    And Click on Finish
    Then A new Ticket is created

Examples: 
    | AccountID | Department        | SubTeam         | Subject     | Product        | TicketCategory     | TicketSubCategory | Comments      |
    | 116999    | Customer Services | ContractEnquiry | Test Ticket | Home Insurance | Account Management | Customer Zone     | Test Comments |

The implementation of this step will depend on the architecture of your tests, but the step should:

  1. Go to the CRM URL
  2. Select AccountId in the quick search
  3. Enter the given Account Id in the search box
  4. Click the quick search button
  5. Close the alerts when the show up

If you find yourself writing code that seems to exist in your other steps consider refactoring your code into Page Models, and then initializing those page models and calling methods on them from your step definitions. The basic control flow of your test will go:

Feature file --> Step definition --> Page model --> Selenium --> Web browser
Related