Creating a data-driven test in Python

Python is also a widely used language for building Selenium WebDriver tests. It offers various ways to parameterize tests.

In this recipe, we will parameterize a Selenium WebDriver test written in Python, using a CSV file.

How to do it...

Let's create a simple Python test for parameterization, using the following steps. This test will read test data from the CSV file used in the Reading test data from a CSV file using JUnit recipe earlier.

  1. Create a Ruby test by importing the following modules:
    from selenium import webdriver
    import csv, sys
  2. Declare the following variables to print a summary of the test combinations executed from the test data source:
    #Variables for Printing Test Summary test_executed = 0 test_passed ...

Get Selenium Testing Tools Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.