Introduction

As we mentioned earlier in the book, the main reasons for using a data-driven test development approach are to be able to reuse test methods with multiple permutations of data, to encapsulate data in a central location, and to enforce DRY coding practices, which reduce the amount of code being written and maintained.

To correctly design and build tests that use this methodology for testing software applications, test methods must contain a predefined input, a verifiable output, and contain no hardcoded values within the test method. Data is passed into a test method at runtime, where it is then used in page object methods to perform an action and verify a result. Because the data is not hardcoded into the test, methods can be iterated with variations of datasets, extending the coverage of the test to include positive, negative, boundary, and limit testing.

This all sounds simple, but in reality, it takes quite a bit of work to convince and train an engineering organization to follow this model. With time constraints in releasing applications in continuous development environments, users often just build the test with a predefined set of data within it. Practices following a copy, paste, change one line of code approach are no longer acceptable.

Regardless of that fact, as a best practice and standard, test methods should be designed and built as generically as possible, use a data provider to extract and pass data to them, and stay small and focused on testing one function per test.

In this chapter, we will design and build data-driven tests using Java and the TestNG technologies.

As per Wikipedia:

"Data-driven testing is the creation of test scripts to run together with their related data sets in a framework. The framework provides re-usable test logic to reduce maintenance and improve test coverage. Input and result (test criteria) data values can be stored in one or more central data sources or databases, the actual format and organization can be implementation specific. The data comprises variables used for both input values and output verification values. In advanced (mature) automation environments data can be harvested from a running system using a purpose-built custom tool, and the DDT framework thus performs playback of harvested data producing a powerful automated regression testing tool. Navigation through the program, reading of the data sources, and logging of test status and information are all coded in the test script."

The reader will learn how to create data-driven test classes that follow the Selenium POM to separate page object classes from test classes and data.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.187.178