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);
	}

    
    

Related Posts:

  • How to pass the Parameter in BDD cucumber? How to pass the Parameter?Passing parameter by using “” (double quotes) OR <> signFrom feature file, we can pass a single parameter by using “” in the step.Example is given below.Step in Feature file Given user lo… Read More
  • What Is Hooks In Cucumber? What Is Hooks In Cucumber?Hooks is nothing but the script which run before or after each scenarios. There are some annotation which are used to execute script before or after each scenarioes.Below are the lists of cucum… Read More
  • Regular expression in step definition in cucumber Regular expression in step definitionBelow are some lists of special character that can be used while writing step definition.1. .(dot)-We can use any character in place of "." In below example, single step definit… Read More
  • Test Runner class in BDD Test Runner classTest runner class is the starting point in BDD from where the script get executed with the help of junit annotation. Test runner class use junit class annotation which is @Runwith(). This gets exec… Read More
  • What is BDD in selenium? What is BDD in selenium?BDD (Behavior Driven Development) is software development approach that allows developer or tester to create the script base on the behavior or functionality of the application.The steps of behav… Read More

2 comments:

Translate

Popular Posts

Total Pageviews

150,760