Data Driven Testing in Behave BDD

Tutorial​​ 13​​ -​​ Data Driven Testing in Behave​​ BDD

Welcome to the 13th article in Behave BDD series!

What you will Learn:

  • Data Driven Testing using ‘Examples’ keyword and ‘Scenario Outline’

Data Driven Testing using ‘Examples’ keyword and ‘Scenario Outline’

For data driven testing, we need the help of ‘Examples’ keyword and ‘Scenario Outline’. These 2 go hand-in-hand. You​​ cannot​​ use ‘Examples’ keyword with normal ‘Scenario’ that we have been writing so far.

Let us create a brand new​​ ‘Login’ feature​​ feature 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 we have 2 rows in our ‘Examples’ table

So, this is the concept of data driven testing.​​ 

Let us see a practical example using selenium.

Write the feature file as see below

Save the file

Write the step definition file


Run the feature file

Notice the console output. The scenario got executed twice. The username/password was picked up from the ‘Examples’ table.

Also, 10 steps got passed since we have 5 steps in a scenario. This would be multiplied by 2 rows in the table, hence 10 steps.

So, testuser3@gmail.com/​​ testuser3 was picked up in first scenario execution and testuser4@gmail.com/​​ testuser4 was picked up in second scenario execution

Below are the screenshots during run execution. As you notice, the first firefox browser executes the first set of test data. Once this gets over, another firefox browser opens to execute 2nd​​ set of data

Another browser opens

This is how we perform data driven testing using behave.

Thank you for reading!

Share On

Share on facebook
Share on twitter
Share on linkedin
Share on whatsapp
Share on tumblr
Share on email

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top

Lifetime Membership Club

LIFETIME MEMBERSHIP BIG SALE - ALL LIVE COURES JUST - 7000 RS/ 99 USD
Attend All Live courses in just 7000 rs / $99 - offer ends 1st Nov 2024