0% found this document useful (0 votes)
11 views13 pages

Create and Execute Cucumber Runner File

This document provides a tutorial on creating a runner file for executing multiple Cucumber feature files efficiently. It covers the steps to create a TestRunner class with necessary annotations, options for pretty output, and how to run the tests as JUnit and Maven tests. The tutorial emphasizes the importance of organizing feature files and step definitions for better test execution and readability.

Uploaded by

abhimanyu thakur
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views13 pages

Create and Execute Cucumber Runner File

This document provides a tutorial on creating a runner file for executing multiple Cucumber feature files efficiently. It covers the steps to create a TestRunner class with necessary annotations, options for pretty output, and how to run the tests as JUnit and Maven tests. The tutorial emphasizes the importance of organizing feature files and step definitions for better test execution and readability.

Uploaded by

abhimanyu thakur
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Way2Automation - Tutorial 4 – Create runner file

What you will Learn :


o Create runner file
o Execute runner file as junit test
o Print the pretty output
o Monochrome option
o Execute runner file as maven test
Create runner file
So far, we have been executing our feature file by right clicking the feature file >Run As >
Cucumber Feature

Now, if we have multiple feature files, we cannot execute our feature files using the
above method. It will be quite tedious. A better aproach would be to create a runner file.
Also, recall cucumber design flow steps. We create [Link] file to execute our
step def file

See below. Create a new package ‘TestRunner’ under src/test/java. Under this package,
create a java class ‘TestRunner’

Now we will add 2 annotations to this class: @RunWith and @CucumberOptions


Let us first add @RunWith([Link])
To resolve error, import the classes [Ctrl + Shift + O]

Let us now add the second annotation

To resolve error, import the classes [Ctrl + Shift + O]


We will now add some options. Now, how will the TestRunner file know the location of
feature file? The first option does that. We use the ‘features’ keyword

To find the location of feature file, right click the feature file > properties
The below window comes [Link] copy the path starting from src/test/java/Features

Paste it

Note that, we copied the path only upto ‘Features’ package. We could have also copied
the path upto the exact feature filename viz src/test/java/Features/[Link]
However, tomorrow if there are multiple feature files inside ‘Features’ package and we
want to execute all of them, than it would be better to mention the path ony uptill
‘Features’ package.
Next, using second option, we will tell the TestRunner where exactly the step definition
file is available. This is done using ‘glue’ keyword

Just mention the name of the ‘StepDefinitions’ package folder. The TestRunner file will
come to know that all the step definition files are present inside this package

Save the TestRunner file.


Execute runner file as junit test
Right click [Link] > Run As > Junit Test
See the console o/p below. All 3 steps are executed fine

You can also see the Junit plugin o/p. It tells us that the ‘Search course’ scenario got
executed fine
Recall that the name of our scenario is ‘Search course’

Print the pretty output


Notice that in the console output that we got above, we do not see the respective
Give/When/Then steps.

We can see the respective Give/When/Then steps in the console o/p by printing the
pretty output. This is done by adding one more cucumber option. There is a ‘plugin’
keyword that we can use, see below

Save the file.


Execute the TestRunner

Notice that the o/p is still not pretty. We do see the Given/When/Then steps but not
easily readbale, see below

Monochrome option
To make the console o/p further readbale, add another option, see below
Save the file
Execute the TestRunner

Now, the console o/p shows the readable Give/When/Then steps


Execute runner file as maven test
Let us now see how to run the same runner file as a maven test.
Before we run the maven test, we have to first rename our runner file with ‘Test’ is
prefix (otherwise you will not see the Given/When/Then steps in output)

Let us fix the error by renaming the class file

So we have

Right click project > Run As > Maven test


Below is console o/p. Notice that it the ‘Build’ got successfull and it mentions the
Given/When/Then steps
This is how we design and runner the runner file.
So so far, we have seen how to design a simple cucumber feature file, step definition file
and a runner file.
Thank you for reading!

You might also like