Data-Driven Testing with Eggplant Functional
The data-driven approach to testing provides an efficient, easy-to-manage method of performing repetitive tests that use a set of test data. Eggplant Functional (EPF) and SenseTalk include various features that make data-driven testing simple.
Eggplant Functional supports the use of test data from various data sources, such as plain-text files, Microsoft Excel files, and databases, and SenseTalk includes commands and functions to access, manipulate, and parse data in powerful ways. This article demonstrates how to use Eggplant Functional to incorporate data-driven testing into your scripts.
You can also perform data-driven testing by using the Tables feature in Eggplant Functional and associating a data file with a Table test.
For information about using data files to create a keyword-driven framework, see Creating a Custom Keyword-Driven Framework.
What Is Data-Driven Testing?
Data-driven testing is the concept of using an external data set as test input. The test might use input data in various ways, such as to specify text that is entered into a form on the application under test, to validate displayed values against expected values, or to establish a set of test constants.
The test is written generically using parameterization, such that it is able to receive the data in the data source. The data used by the test can be altered by manually editing the original data source, pointing the test to a new data source, or automating updates to the data source.
In the sections below on connecting to data sources, the sample SenseTalk code shows examples of using external data for data-driven testing.
Data Sources
A data source, which contains the test data for use in automation, is required for data-driven testing. Eggplant Functional supports the following data source types:
- Plain text (.txt, .csv, .xml, etc.)
- Excel (.xlsx)
- Open Database Connectivity (ODBC) databases
The data source you use determines both how you use SenseTalk to access the data source and how you parse the data.
Data Source Storage
When you use plain-text or Excel data sources, the file must be accessible to the local file system of the Eggplant Functional machine, which can include networked or shared drives.
If you're using Eggplant Functional on Windows, shared drives must be mapped to letters (e.g., D:\). UNC paths are not supported.
The suite Resources pane provides a simple method for storing plain-text and Excel data files within your suite. You can then easily reference those files from your scripts by using the ResourcePath() function.
For databases, communication between Eggplant Functional and the database is managed by an ODBC Administrator configured on the Eggplant Functional machine.
Plain-Text File Interaction
Using a plain-text file is often the simplest way to implement a data-driven testing strategy with Eggplant Functional.
File Access
For background on accessing the contents of plain-text files, see the documentation on File and Folder Interaction and Accessing a File as a Container.
When accessing the content of plain-text files, using the open file
and close file
commands is not required. However, if you're performing many rapid read/write events against the file, using the open file
and close file
commands is recommended. In most cases of data-driven testing, the file is accessed only once, or it is accessed infrequently, so these commands are not needed.
The easiest way to interact with a plain-text file is to access it as a container by using the put
or set
command. Include the file extension (e.g., .txt, .csv) when referencing the file. For example:
Set MyPrices to file ResourcePath("prices.txt") -- The data file is stored in the Resources of the suite
Set MyProducts to file "C:\Users\Carrie\Desktop\products.csv" -- The data file is stored elsewhere on the Eggplant machine
You can use chunk expressions to access parts of the file contents as containers. For example:
Set MyPrice to line 3 of file ResourcePath("prices.txt")