๐Data Driven Framework
Here is an in-depth expert level explanation of the Data Driven framework with a complex example for CNBC using Java:
๐ Data Driven Framework - Expert Guide
The Data Driven framework separates test data from test logic for maximum reusability.
๐ Externalizing Test Data
Test data is stored in external sources like:
JSON
XML
Databases
Excel (XLS, XLSX)
CSV
Config files
Allows managing data separately from scripts.
JSON and Databases provide structured storage.
๐ Reading Test Data
Test scripts use a Reader class to access external data.
Readers implemented for each data source e.g. JSONReader, DBReader etc.
-decouples test scripts from underlying data storage.
๐งช Multiple Iterations
Scripts can loop through data sets using
for
loops.Each iteration executes same test steps with different data.
Runs expand easily by adding data records.
๐ Using an External Database in Data Driven Framework
In a Data Driven Framework, the test data can be stored in various external data sources, including databases. Using an external database as the data source provides several benefits, such as centralized data management, easy data retrieval, and the ability to handle large data sets. Here's how an external database can be used in a Data Driven Framework:
Database Connection: The test script establishes a connection to the external database using a JDBC driver. The connection string contains the database URL, username, and password. Once the connection is established, the test script can execute SQL queries to retrieve the test data[1][4][5].
SQL Query Execution: The test script executes SQL queries to retrieve the test data from the external database. The SQL queries can be customized to retrieve specific data based on the test requirements. The retrieved data is stored in variables in the test script for further processing[1][4][5].
Test Script Execution: The test script uses the test data retrieved from the external database to perform the corresponding actions. The test execution engine or the automation framework interprets the test data and executes the associated functions or actions defined in the test script. The test script uses the test data from the external database as inputs for the actions performed during the test execution[1][4][5].
๐จโ๐ Example for CNBC
Here's an example Java block for a Data Driven Framework that automates the end-to-end flow of the CNBC website using an external MySQL database as the data source:
This Java block automates the following actions:
Open the CNBC website.
Click on the "Sign In" link.
Enter the username and password.
Click on the "Login" button.
Search for a stock.
Click on the "Sign Out" link.
Close the browser.
The test data used in this example is stored in an external MySQL database named "testdata". The database contains a table named "users" with three columns: username, password, and stock. The test script reads the test data from the database and uses it to perform the corresponding actions.
Using an external database as the data source provides several benefits, such as centralized data management, easy data retrieval, and the ability to handle large data sets. It also allows for easy modification and customization of test cases without the need to modify the underlying code. Testers can update the test data in the database, enabling quick changes to the test script behavior[1][4][5].
It's important to note that the specific components and their implementation may vary depending on the testing tool or framework being used. The examples provided in the search results demonstrate different approaches to implementing a Data Driven Framework using various tools and technologies.
Last updated