Follow

Writing Steps in a BDD Test Suite

Sample Behavior Driven Test Suite

    SCENARIO: LoginOperation
    META-DATA: {"description":"LoginOperation","groups":["SMOKE"]}

    login with username Infostretch and password Infostretch123
    then go to login page

    END

How to use test steps in BDD?

For Writing Behaviour Driven test cases with QMetry Automation Studio use .bdd file.
For writing test cases/scenarios use already created behaviours/test-steps to create test scenarios.

How to use Test-Steps?

1. Provide @QAFTestStep annotation to any method and that method can be used as Test-Step.
2. Make sure that method name annotated with @QAFTestStep is unique.
3. Provide description to the @QAFTestStep annotation using description field.
4. If Test-Step method is expecting parameters, description must have same number of arguments. For specifying parameters in description use curly braces e.g. ‘{0}’.

How To Use Test-Steps in Behaviour Tests?

Precondition: To use Test-Step in Behaviour Tests, Test-Steps must have description assigned to it.
1. Use Description of Test-Step as a Behaviour name.
2. Provide required parameters (Parameters type can be of any of wrapper class, array and map).

Syntax for defining BDD Scenario

SCENARIO : SCENARIO_NAME

Syntax for defining BDD Scenario Metadata

Meta-Data:< META DATA FOR THE SCENARION IN JSON STRING >
This metadata can have desc, groups, priority, key (for data driven scenarios) etc... and all other supported by TestNG.

Syntax for writing Test-Steps

Condition : If Test-Step required parameters to pass it can be passed with single quotes
Example:
Suppose Test-Step is
@QAFTestStep(description="search for {0}")
public void doSearch(String searchText){
getSeachTextBox().sendKeys(searchText);
getSeachBtn().click();
}

To call this from behaviour driven Test syntax would be
When search for 'QA Services & Solutions'

 

Various input parameters

1. To refer property parameter from another step as in parameter use ${parameter_name}.
2. To provide list or array argument value, enclose comma separated values with [], For example
      [1,2,3] represent array/ collection / list of int
      [“aaa”,”bbb”] represents array / collection / list of String
3. To provide map use {} representation key value pair of map for example
    Map<string, object=""> implementation is {'company':'Infostretch';'location':'ahmedabad'}
4. Date: Date must be provided in dd-mm-yyyy format.
5. Single quote(') is escape character.So if you want to use single quote (') in argument then use extra back slash .For example,
      your actual argument is Infostretch's Location then write Infostretch\'s Location

Example :

  1. @QAFTestStep(description = "verify web result card at index {0}", stepName = "verifyResultCardAtGivenIndex")
    public void verifyCard(int i) {
             ---
             ---
    }
    Step Call Syntax :
    verify web result card at index 255

  2. @QAFTestStep(description = "search flight {0}", stepName = "searchFlight")
    public void searchFlight(String value) {
             ---
             ---
    }
    Step Call Syntax :
     search flight Ahmedabad
     search flight O''Fallon
  3. @QAFTestStep(description = "get ages {0}", stepName = "getAges")
    public void getAges(int[] values) {
             ---
             ---
    }
    Step Call Syntax :
    get ages [1,2,4,6]

  4. @QAFTestStep(description = "search flights for {0}", stepName = "searchFlightsFor")
    public void searchFlightsFor(String value[]) {
             ---
             ---
    }
    Step Call Syntax :
    search flights for ["aaa","bbb","ccc"]

  5. @QAFTestStep(description = "search flight for Date {0}", stepName = "searchFlightForDate")
    public void stepForDate(Date d) {
             ---
             ---
    }
    Step Call Syntax :
    search flight for Date 25-05-1922
  6. @QAFTestStep(description = "Login with username and password {0}", stepName = "verfiyLogin")
    public void verifyLogin(Map<String, String> map) {
             ---
             ---
    }
    Step Call Syntax :
    Login with username and password {'username':'Infostretch','password':'Infostretch123'}

How to use Property value :

For example:
Given store {'company':'Infostretch';'location':'ahmedabad'} into 'data' Then COMMENT: '${data}'

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

0 Comments

Article is closed for comments.
Powered by Zendesk