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

4 comments:

  1. This is one awesome blog article. Much thanks again. selenium Online course Bangalore

    ReplyDelete
  2. Excellent post on selenium related Read Selenium interview questions with answers scenario based and Get selenium online training by the most experienced and expertise trainer in india.

    ReplyDelete
  3. Such great information for blogger iam a professional blogger thanks…

    Looking for Hadoop Admin Training in Bangalore, learn from Softgen Infotech provide Hadoop Admin Training on online training and classroom training. Join today!

    ReplyDelete

DevOps 01: What is DevOps and How it benefits organizations?

DevOps is a culture in an organization, where the development team and operations team help each other by sharing information, process and t...