Forum Discussion

naveens33_'s avatar
3 years ago

How to set pre-conditions for execution plan before it start any Test Case

Basically, I am writing BDD test and selected the feature file to my Execution plan as different test case. But before I start any feature to get executed I need some pre-conditions to be done like created the test data to my test accounts through API. So, now how can proceed to create these preconditions for my test. 

Basically, I need solution where all my pre-conditions to be executed before my test from Execution plan starts. 

Any hope. 

2 Replies

  • Kitt's avatar
    Regular Contributor

    You can also use the 'Background' keyword to set a pre-condition before each scenario. Then create a custom step definition to do as you wish. [Gherkin Reference] 

    Feature: scenarioTEST
    # BACKGROUND: can contain one or more Given steps, which are run before each scenario.
    Background: A Browser has been launched and the data has been refreshed
    Scenario: Test User Login
    # GIVEN/WHEN/THEN: precondition/action/validate
    Given The Browser is running
    And The user wants to log into the "QA" environment
    And The user has navigated to the webpage "https://www.yourwebsite/com"
    When The user enters "" in the edit Email box
    And The user enters "********" password
    And The user clicks Log In
    Then The user should be redirected to ""
    # SCENARIO OUTLINE: keyword can be used to run the same Scenario multiple times, with different combinations of values.
    Scenario Outline: Login with various user roles (data-driven test)
    Given The <user> has logged into YourWebsite
    When The correct <email> and <password> has been used to login
    Then I should see the user <role> listed in the navigation bar
    | user | role | email | password |
    | "User1" | "Super Admin" | "" | "********1" |
    | "User2" | "Admin" | "" | "********2" |
    | "User3" | "User" | "" | "********3" |

    and your step definition inside your script unit would define what happens before each scenario:

    When("A Browser has been launched and the data has been refreshed", function (){