Monday, January 8, 2018

How to execute the Cucumber tests using Test Runner Class?

I would have combined writing feature file, writing step definitions and writing runner class in single post but it will become lengthy and may look like a complex process. So to make it simple i wrote three separate posts. Lets switch to runner class.

We have written Scenario, Steps and Step definitions. We can execute tests without test runner class also. In the previous post we have mapped (glued) Steps in feature file and Step definitions in the IntelliJ Edit Configuration. Now run the feature file 'gmailLoginFeature.feature'

You should see execution start, browser launch, application navigation and etc. But the advantage of using test runner class is you can configure reports, can add plugins, can change test behavior and etc.

Cucumber uses Junit runner class to execute the tests. In the runner class mainly we need specify two things:
  • @RunWith: This annotation tells Junit to run the tests as Cucumber tests
  • @CucumberOptions: Cucumber options is used to specify the features to executed, step definitions location, plugins, and etc.
Step 1: Create 'testRunnerPackage' and create a 'testRunnerClass' class in it. You can give any name.


Step 2: Add @RunWith(Cucumber.class) annotation above the class

Step 3: Add @CucumberOptions() above the class as below


feature: To specify the feature files to be executed

glue: Glue means sticking together. It is used to specify the location of the Step Definitions file.

Step 4: Execute the steps using test runner class and checkout the below video (please view in Full Screen)


Finally we completed our first cucumber test execution. Please share your feedback on this.

Thanks for reading!! #seleniumbabu #HappyLearning

6 comments:

Katalon 08: Integration of HP ALM with Katalon Studio

In this post, this post we discuss about integration of  HP ALM with Katalon Studio. If we can integrate HP ALM with Katalon we can update ...