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

7 comments:

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

    ReplyDelete
  2. I have read your blog its very attractive and impressive. I like your blog. selenium Online Training Hyderabad

    ReplyDelete
  3. 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
  4. I really enjoy the blog.Much thanks again. Really Great selenium Online Training

    ReplyDelete
  5. I believe there are many more pleasurable opportunities ahead for individuals that looked at your site. Selenium Training In Bangalore | Best Selenium Training in Bangalore

    ReplyDelete
  6. 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

Selenium4: Working with two parallel windows in Selenium Automation

A new method newWindow() is introduced in Selenium 4 (Alpha). Using this method we can open a new tab or new window from the current window...