0% found this document useful (0 votes)
23 views10 pages

Tutorial 10 Data Driven Testing in Cucumber Scenario Outline

This document explains how to implement Data Driven Testing in Cucumber using the 'Examples' keyword and 'Scenario Outline'. It details the process of creating a feature file, setting up an 'Examples' table for test data, and executing scenarios multiple times based on the data provided. The document emphasizes the importance of matching variable names in the scenario with those in the examples table for successful execution.

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)
23 views10 pages

Tutorial 10 Data Driven Testing in Cucumber Scenario Outline

This document explains how to implement Data Driven Testing in Cucumber using the 'Examples' keyword and 'Scenario Outline'. It details the process of creating a feature file, setting up an 'Examples' table for test data, and executing scenarios multiple times based on the data provided. The document emphasizes the importance of matching variable names in the scenario with those in the examples table for successful execution.

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
You are on page 1/ 10

Way2Automation - Tutorial 10 – Data Driven Testing in Cucumber

What you will Learn :


o Data Driven Testing using ‘Examples’ keyword plus ‘Scenario Outline’
Data Driven Testing using ‘Examples’ keyword plus ‘Scenario Outline’
Let us create a brand new feature file having ‘Login feature’.
If you are writing ‘Scenario Outline’, you have to use ‘Examples’ keyword, see below.
These 2 go hand-in-hand. You cannot use ‘Examples’ keyword with normal ‘Scenario’
that we have been writing so far.
So, if you really want to use the concept of data driven testing, you can achieve with the
help of ‘Examples’ keyword and you have to use ‘Scenario Outline’.

Save the file.


The ‘Examples’ table acts like a test data table for us. It contains multiple set of test data
to test our application

Now, in the above ‘Scenario Outline’, look at line numbers 7 and 8. We have written
“<Username>” and “<Password>”. So these are string values because these are written
within double quotes
Now, the <Username> that you see in the figure above is actually the column name that
we have written in the ‘Examples’ table. Similar is the case with <Password>. These
should be an exact match. You cannot write <Username> in line number 7 and
USERNAME in ‘Examples’ table.

So the entire scenario will be executed 2 times since wehave 2 rows in our ‘Examples’
table

So, this is the concept of data driven testing in cucumber.


Let us run our feature file to generate our step definition methods
Copy the methods from console

Create a step definition file and paste the above methods


Import the methods and remove the exceptions
Save the file
Let us re-run our feature file

Notice the console output. The scenario got executed twice. The username/password
was picked up from the ‘Examples’ table.
Also, 14 steps got passed since we have 7 steps in a scenario. This would be multiplied
by 2 rows in the table, hence 14 steps
So, invalidusername/98765 was picked up in first scenario execution and
way2automation/invalidpassword was picked up in second scenario execution

Let us now take another example wherein both the rows have only numeric values, see
below
Save the file and run it

Copy the step definition code


Create step def file and paste the code. Import the packages and remove the exceptions
Save the file
Re-run the feature file
Notice the console o/p. The scenario got executed twice as expected and 10 steps got
passed

So this is how we use the ‘Scenario Outline’ and ‘Examples’ keyword combination to
execute data driven testing in cucumber.
Thank you for reading!

You might also like