O'Reilly logo

Learning Selenium Testing Tools with Python by Unmesh Gundecha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using external data sources for data-driven tests

In the previous example, we supplied the test data in the test code. However, you will find situations where you already have test data defined in external sources such as text files, spreadsheets, or databases. It is also a good idea to separate the test data from the code and put it in an external source for easy maintenance and avoid changes to the test code each time you want to update the values.

Let's explore how we can read the test data from the Comma separated values (CSV) files or Excel spreadsheets and supply it to ddt.

Reading values from CSV

We will use the previous test case and move the data that we supplied to the @data decorator into a separate CSV file called testdata.csv instead ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required