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
- Prerequisites
- Create web recorded tests with parameters
- Add a Data Source to your Recorded Test
- Execute your Data-Driven Test
- Data-Driven Test Automation Reports
- Enhance your Test Automation Scenarios with Nested Tests
Prerequisites
- Sign up here to TestProject. Don’t worry, it’s free!
- 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.
- 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:
First, let’s create a new test. We will start with the “Record” mode to easily add and edit our parameters:
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 a Login parameter:
Add a Password parameter:
You can now see in the Step Editor below that we have finished creating our Login and Password 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:
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:
Now, let’s open our template. In it, you will already see the parameter names you have created within your test, as seen below:
All that’s let for you to do is add different parameters to make this a data-driven test.
Let’s create a few:
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:
Then choose to override the default input parameters by selecting your data source and Click “Run”:
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:
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:
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:
Now we have two tests: One for the first “Login Page”, and another for the “Info Page”:
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:
In the next field select our “Info Page” 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.
In our case, let’s click “Yes”, since this will allow us to write the parameters for all block-tests from one main directory.
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:
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.
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!
Thanks Vladyslav Shvaitser for the blog. But I have question on ‘INFO PAGE’ Test. Is there any way to run ‘INFO PAGE’ 3 times without repeating Log in process 3 times?
e.g.
LoadUrl
Enter Log in ID
Enter Password
Click on log in
For (loop 3 times){
Select country
Enter address
Enter phone
Enter email
}
I believe I can do the same with the help of addons but i want to use TestProject Feature.
Thanks for the help!
Hey Sisirkant,
Thank you for the comment! I see you’ve received a detailed response here in our Forum – https://forum.testproject.io/t/looping-nested-test-case/1472
Happy to help anytime 🙂
Hi Vlad ,
The you entered in sheet above
Login Password ApplicationURL
Nick 12345 https://example.testproject.io/web/
John 11111 https://example.testproject.io/web/
bill 12345 https://example.testproject.io/web/
in this password is 11111 , which is wrong so my test case should fail. But it is showing passed. How this happened. Even your test also showing passed. Please let me know.
Hi dhanesh.
There is no issue, everything correct.
The test have only 4 steps, and the last one is to click on Login button.
The button can be clicked even if the password is incorrect. So the click action does what expected from it – it clicks 🙂
Of course, the second part, after login test, in this case will fail