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

Get Learning Selenium Testing Tools with Python now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.