logo logo

Build Data-Driven Test Automation Building Blocks with Selenium and TestProject for Web Apps

main post image

In this tutorial you will learn how to build your first data-driven test by utilizing Selenium and TestProject, without a single line of code and in less than 10 minutes! You will also learn how to easily maintain your tests and save a lot of effort during your test automation projects by utilizing nested tests.

Let’s get started!

Overview

  1. Prerequisites
  2. Create web recorded tests with parameters
  3. Add a Data Source to your Recorded Test
  4. Execute your Data-Driven Test
  5. Data-Driven Test Automation Reports
  6. Enhance your Test Automation Scenarios with Nested Tests


Prerequisites

  1. Sign up here to TestProject. Don’t worry, it’s free!
  2. Login to TestProject and install the TestProject Agent (it incorporates all of the Selenium drivers according to the browsers you have installed, in one small desktop local component). Watch this short video to see how easily you can setup your Agent.
  3. That’s it! Now that you have your TestProject Agent all setup and ready to go – you can start creating recorded data-driven tests and even generate Selenium code if needed.


Create Web Recorded Test with Parameters

In this tutorial, we will use a TestProject example web page of a login scenario, that looks as follows:

TestProject Example Web App

First, let’s create a new test. We will start with the “Record” mode to easily add and edit our parameters:

TestProject Recorded Test

In this case, we need to create parameters for the Login field and Password field (as seen in the web example page above). In order to create them, we need to click here:

Add Parameters to TestProject Recorder Add Parameters to TestProject Recorder

Add a Login parameter:

Add Parameters to TestProject Recorder

Add a Password parameter:

Add Parameters to TestProject Recorder

You can now see in the Step Editor below that we have finished creating our Login and Password parameters:

TestProject Step Editor Parameters

Let’s start recording our test steps using these parameters we’ve created, and use these parameters in both the user name and password textbox fields, and hit the Login button. Here are our test steps:

Step Editor TestProject

 

Add a Data Source to your Recorded Test

Once we’ve completed our test, let’s go back to our Project area and download a Data Source template of our test. All you need to do is simply click these “…” and select “Data Source Template” as seen in the image below:

Data Source Template

Now, let’s open our template. In it, you will already see the parameter names you have created within your test, as seen below:
Data Source Template

All that’s let for you to do is add different parameters to make this a data-driven test.
Let’s create a few:
Data-driven Test

Each new line will launch an additional test run with the selected parameters.
In this example, we have 3 parameters, meaning that we will have a total of 3 test executions.

Once you finish adding your parameters, simply save the CSV file and upload it as a new Data Source in your project, as seen in the images below:

 

Execute your Data-Driven Test

Now we can execute our automated test while using the attached data source file.
Click the play button next to your test:

Execute Test in TestProject

Then choose to override the default input parameters by selecting your data source and Click “Run”:

Execute data-driven test

 

Data-Driven Test Automation Reports

Once the test execution is completed, we can go to the Reports dashboard and see all of the test iterations with our selected parameters:

TestProject Reports Dashboard

 

Enhance your Test Automation Scenarios with Nested Tests

We’ve completed our first data-driven test! Another cool option that can enhance your automation scenarios is to create Nested Tests.
Nested tests are basically reusable testing blocks that are great from a maintenance perspective and save you a lot of effort during your test automation projects.

For example, many apps have a login page, but you don’t want to create that scenario over and over again, right? To avoid such a hassle, you can simply create the login test once, and then add it as a step to any of your tests that require that login phase in the data-driven test we have created before.

In our example site we’ve used above, let’s say we want to test the following information page that is presented after the login is completed, as seen below:

TestProject Example Web Page

 

 

 

 

 

 

 

 

 

Let’s create a new data-driven test for this part, without the login actions (that we described above in our first Login test). We will fill out the fields below and call our test “Info Page” test:

TestProject Example Web Page

 

Now we have two tests: One for the first “Login Page”, and another for the “Info Page”:

TestProject Tests

 

 

 

Let’s combine these two tests by adding the “Info Page” test as a step to our “Login Page” test.
Click on the “Login Page” test and click “Add step”. Then, change the type of this step from default “Element action” to “Test” as seen below:

TestProject Nested Test

 

 

 

 

 

 

 

 

 

 

In the next field select our “Info Page” test:

TestProject Nested Test

 

Once Selecting our “Info Page” test, the following popup message will ask us if we want to create the same parameters of our “Info Page” test in our “Login Page” Flow.

TestProject Nested Test

 

 

 

 

 

In our case, let’s click “Yes”, since this will allow us to write the parameters for all block-tests from one main directory.

TestProject Nested Test

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Now we can save our test and go back to our project area. Before we go ahead and execute it, let’s download its data source template and add our parameter values:

data source parameters

 

Then, upload the data-source (as described above) and use it to override the default parameters when executing our complete Login Flow. Once the execution is complete, we can go to the Reports dashboard and see the test had two iterations, and that both of our tests have been completed as part of one main test, thus implementing the nested tests feature. You can also use the same test-blocks with multiple tests, and start reusing your tests for better efficiency and fast deliveries.

Data driven test reports

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

HAPPY TESTING!  😎

Share in the comments below your experience with creating data-driven tests and how do you maintain your test automation? We’d love to hear your tips!

 

Vladyslav Shvaitser

About the author

Vladyslav Shvaitser

Test automation solution architect and Customer Success at TestProject.

Join TestProject Community

Get full access to the world's first cloud-based, open source friendly testing community. Enjoy TestProject's end-to-end test automation Platform, Forum, Blog and Docs - All for FREE.

Join Us Now

Comments

5 1 comment

Leave a Reply

Join TestProject Newsletter

Join a 20K community of readers! Always stay up-to-date with all the latest test automation trends, best practice and tips shared by leading software testing community experts across the globe!

FacebookLinkedInTwitterEmail