Saturday, April 22, 2023

 

Test Runner class

Test 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 execution once we execute the script. There is one another annotation with the name @cucumberOptions. This is use to do some configuration before running the script.

Some options are given below.

a) features:- This option is used to provide the feature file path.

b) glue:- This option is used to provide the step definition file path.

c) tags:- This option is used to provide the tag name in feature file. With the help of this it will execute only those scripts which will match to these tags. In general, we may have many scenarios such as regression, functional or sanity scenario in feature file. This can be executed separately by using tag name.

We can use “and “, “or “,”not” operator while writing tag name. Example given below.

tags= "not @test# This will run scenario other than tag name @test from feature file.

tags= "@test and @test1" #This will run the scenario which have both the tag name “@test” and “@test1” from feature file.

tags= "@test or @test1" # This will run all the scenario which has tag name “@test” or “@test1” in feature file. See below example.

        //tags= "not @test",
		//tags= "@test and @test1"
		//tags= "@test1 or @test"
        

d) Monochrome:- This option is to print the output on console in readable format. The value should be set to true for this. This can have true or false value.

e) Strict:- This option is used to check if any method is missing in step definition file. And if any step is not defined then it will stop the execution of program. This can have true or false value.

f) dryRun:- This option is used to check if all the steps are defined in step definition file or not. The value of this option should be set as true to check if all the steps are defined in step definition or not. Once it is verified that all the steps are defined then the value can be set as false.

g) Plugin/Format: - This option is use to specify different formatting options to show output report. The reports are generally created in HTML format or Json format. See below example.

For HTML format
plugin= {"pretty","html:target/cucumber-reports/index.html"},

For json formate
plugin= {"pretty","json:target/cucumber-reports/Cucumber.json"}

Runner class

import org.junit.runner.RunWith; import io.cucumber.junit.Cucumber; import io.cucumber.junit.CucumberOptions; @RunWith(Cucumber.class) @CucumberOptions( features = {"src/test/java/org/cuck"}, glue = {"org.Teststep"} , //plugin= {"pretty","html:target/cucumber-reports/index.html"} plugin= {"pretty","json:target/cucumber-reports/Cucumber.json"} , tags= "not @test", //tags= "@test and @test1" //tags= "@test1 or @test" dryRun = true, monochrome = true ) public class RunnerTest { }

Cucumber runner class maven dependency

    <dependency>
            <groupId>io.cucumber </groupId>
            <artifactId>cucumber-java </artifactId>
            <version>6.10.4 </version>
            <scope>test </scope>
     </dependency>

      <dependency>
            <groupId>io.cucumber </groupId>
            <artifactId>cucumber-junit </artifactId>
            <version>6.10.4 </version>
             <scope>test </scope>
      </dependency>

     <dependency>
            <groupId>junit </groupId>
            <artifactId>junit </artifactId>
            <version>4.13.2 </version>
             <scope>test </scope>
     </dependency>
        

Related Posts:

  • SDET Interview Question: Explain the Page Object Model (POM) in Test Automation 🚀 SDET Interview Question: Explain the Page Object Model (POM) in Test Automation✅ What is POM?The Page Object Model (POM) is a design pattern in test automation that provides an abstraction layer between test scripts … 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
  • 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

0 comments:

Post a Comment

Translate

Popular Posts

Total Pageviews

152,098