Saturday, April 22, 2023

 

How to pass the Parameter?

Passing parameter by using “” (double quotes) OR <> sign

From feature file, we can pass a single parameter by using “” in the step.Example is given below.

Step in Feature file

 Given user logged with "userID"
 

We can also repeat the same step with different parameter by using “Scenario Outline” and “Example” keywords. In below example, a single step will repeat 2 times with 2 different inputs parameter. Scenario will repeat for all the parameter we mentioned in “Examples” keyword.

Step in Feature file

Feature: This is my first feature
Scenario Outline: This shopping scenario
When user select item <number>

Examples:
|number|
|one|
|two|

Step definition (This step definition can used for above both the feature file examples)

@When("^user select item (.*)$")
public void navigate_to_home_page2(String number) {
System.out.println(number);
	}
    

Passing group of conditions in Step definition.

Some time we have to pass a group of condition in step definition. Example is given below.

Step in Feature file

Then apple is sweet
    

Step definition

@Then (“^(?:apple|mango|cherry) is sweet$”)

public void apple_is_sweet() {
System.out.println("fruits");	
}

Passing the list of parameter from feature file.

pipe (|) line can also be used for passing lists of items in specific test step. Example is given below.

Step in Feature file

    
 And the lists are given below:
|Laptop|
|Kitchen|
|home_Appliances|

     

Step definition

    
@And("the list are given below:(.*)")
    
public void ListOfItem(List<String> list) {
System.out.println(list);
	}

    
    

2 comments:

Translate

Popular Posts

Total Pageviews