Data Driven Testing with Data Sets | Bondar Academy
Course: Mastering testRigor
Module: Reusability and Optimization
Instructor: Artem Bondar
Lesson Summary
In this lesson, we explore how to utilize data sets for data-driven testing in TestRigor . The focus is on automating a login scenario that involves validating error messages based on different input values. Test Scenario Overview The login page contains fields for email and password . Various invalid inputs trigger specific error messages: Invalid email format: "Email should be real one." Empty password: "Password is required." Password length issues: "Password should contain from four to 50 characters." Instead of creating separate test cases for each scenario, we can consolidate them into a single test case that executes with different data sets. Creating the Data Set To begin, we create a new data set named LoginScreenErrorMessagesValidation with a description for clarity. The following variables are defined: emailInputValue emailErrorMessage passwordInputValue passwordErrorMessage We then create three rows in the data set representing different scenarios: Valid values with no errors. Three-character email and password with respective error messages. No values provided, triggering both error messages. Implementing the Test Case Next, we create a test case that navigates to the login page, inputs values from the data set, and triggers error messages. It is crucial to link the data set to the test case to ensure proper execution. Validation of Error Messages Assertions are added to check for the presence of error messages. We utilize the caption class to validate that the appropriate error messages appear when expected. The test is run, and results are reviewed using a dropdown to select different data sets. Conclusion This lesson demonstrates how to efficiently use data sets in TestRigor to manage repetitive test scenarios with varying inputs, enhancing both testing efficiency and accuracy.
Video Transcript
In this lesson, we will talk about how to use data sets to perform data-driven testing in TestRigor. So let's get into it. So let's automate the following scenario. Here in our test application, we have ALT menu, and here is the login page. On this login page, we have email and password fields. But if you will provide not valid password or email, you will see error messages related to this validation. For example, if I provide something like this, one, two, and try to click to password, we see the error message, email should be real one. Or if I click to password and will not type anything into password, we should see a message, password is required. If I type something like one, two, we see different error message that password should contain from four to 50 characters. And if I remove everything, we see the messages email is required and password is required. So we have here at least three different test cases where providing a different input values is triggering different error messages on the page. And we need to validate all those three conditions. So one way of doing this is, of course, creating three different test cases and in one test case, type the email with just one character and one password and validate the message. Another test case is to provide just the empty values and validate the message. And the other test case is the happy pass when you provide a valid email and message should disappear. So the message should not exist. And this also should be a part of your validation. So instead of creating three different test cases, you can create just one test case, but execute it with a different data set and perform the validations like this. So let's do this. Going back to the test trigger. And first of all, let's create the data set that we're going to use for this test. I'm going to the test data one more time. And instead of global variables, navigate to data sets. So here you need to create a new data set. And for example, we will name it LoginScreenErrorMessagesValidation. And some description, you can add test data to validate error messages of the login screen, something like this. And when you add it, you will have a nice description here in data sets. The name and the description of what this data set is about. Try to keep the naming and description meaningful, so later when you have more data sets, it will be easier for you to navigate. So going here. Now we need to create variables and rows. So first we need to start with the variables. Which variables will we need here? So our variables are this one, the values that we will type in the email and password field and the error messages that will show up as a result. So we will need four variables. One variable for email address. Second variable for error message for the email. Then variable for value we type in the input password. And another variable for the error message related to the password field. So let's create those four variables. So add text type of the variable, variable name, email input value. Create another one, email error message. Create another one, password input value. And the last one, password error message. All right, four variables created. And now we will use those variables in the rows of the data set. So I'm going to rows and I create the row number one. Add row. So let's say that we will start with a happy path, with a valid scenario when no messages should be displayed on the page. And I will name it, for example, valid values with no errors. Something like this. So the email input value will be test at test.com. Error message in this case should be empty. We don't expect any errors. And the password, for example, hello. This is also a valid password, because our password should be more than three characters and less than 15 characters. And the error should not also be displayed. So I keep it blank and create at. All right, those values are added under this row. So let's create the second row. And the second one, three characters value. And then input value, for example, will be qwe. And error message in this example should be qwe. And email should be real one. I take this value and paste it over here. Then password, I also type something like this. And the error message should be, password should contain from four to 50 characters. And enter it here and save. Second row is created and the third row when no values are provided. No values provided. So input value is empty. The error message should be email is required. Like this. And for password value is empty as well. And the error message should be password is required. Done and done. That's it. So we created three data sets. If you open each of them, you can see which data will be used for every test. Now let's go back to the test cases and create a new test. So add custom test cases. Login screen. Errors. Validation. All right, the first step we need to navigate to this ALF and login page. Click ALF and click login. All right, the next step. And now I need to type value into email address. And in order to trigger the error message, I need to perform some action on this page. For example, I can click after that into the password field. And that way the error message will be triggered. And after I type something into the password field, I will click on the email. So it will be triggered as well. So let's do this. And we will use just these placeholders, email address and password. This should work just fine. Going back and I type enter stored value. And let me close this. And I open our data set in a new tab. So I will have a visibility to the names of the variables. So data set. Here are our variable names. So test going back. Okay. Stored value. First we type the email. And we type email input value. Into email address. Then I need to click on input password to trigger the error message. And the second step, I need to enter stored value of password input value. Password input value into password. And then click on the email just to trigger the error message. And this is email address. All right. So I believe that's it. Let's just run it to see if it's working. And then later we will add the assertions. So click and run. All right. Test completed. But it is failed. Because it was complaining on the variable that was not set prior to entering the value. It is because we didn't link the data set. So we need to click on this link data set icon. And we need to select the data set that we want to link. Click link. Close. Now we can see the data set is linked to these test cases. And I will just retest. Click retest button. And let's wait one more time the execution. All right. The execution was completed successfully. Now look how the user interface changed a little bit. So we have here a dropdown where we can select what data set we want to review. So, for example, this one is valid values with no errors. We open the screenshot. We can see that values are added. And we don't have any error messages. If I switch to the three characters value, this is exactly the same test. But was executed with a different data set. Here we go. And you can see the three values are entered. And both error messages are triggered. And if I look into the third one, no values provided, we have a third set of the screenshots with the test when we did not provide any values. And we triggered the messages that we want to validate. So this is how data set works. You provide three different data set and run exactly the same script in parallel using three different test data sets. And the last step that we need to complete here is just to add the validation in our current test. So how would we validate those error messages? Let's go back to test application. Make right click inspect. And we see that when error message is showed up, it creates the special class caption. So if I type something like test at test.com, you can see the caption disappears. But if I remove, then where is it? Then the class caption shows up over here with the error message inside of it. So what we want to do, we want to use this caption class, because when the caption class will not exist on the page, we don't want to perform this validation of the error message because nothing to validate. In order to make our test flexible enough to validate when the message exists, and to not validate when message do not exist, we need to use this class. And let's write this assertion. Check that caption below email contains stored value and we provide the variable name. And for the email, it will be email error message. And we need to provide extra prompt if exist. So this if exist prompt will validate that if this caption below email exists, then we want to validate that this error message is the part of this caption. If it does not exist, for us, it is a signal and validation that everything working as expected. The same validation we need to create for password below. Password contains stored value and stored value would be password error message. Again, if exist. All right, that's it. So let's run this test. All right, everything is passed. And let's see. So this is the happy path when no error messages validation pass successfully. For the three characters, we see the messages and validation of the messages. And for the no values, we see that no values were provided and error messages were validated. Also, if, for example, you are reviewing the test result and one of the data set failed while the other pass, instead of rerunning the entire data set, you can rerun test combination. And for example, select which value you want to run over here. Use the button retest combination. Click on that and select which combination would you like to run out of three. This will save you a little time to retest and easier to debug if something goes wrong. All right, that's it. So let's quickly summarize what we did in this lesson. So when you have a scenario, when you have a repetitive step for the test execution, but have a slightly different validation points, you can use a test rigor data set to data drive your scenario using exactly the same script, but with a different data. In order to do that, you need to go to the test data and create a new data set right here. You create a data set, define the variables, and then create the rows, including those variables. Each test row represents a single test run of your test with a particular set of data. And inside of the test case, you just create the reference to the stored value of your variables and make the assertion using the variables as well. If you want to review the test, you can use this dropdown over here to select which data set you want to run. You need to map your data set to your test case in order this to work. And if you want to rerun the particular set of data, you can use retest combination button to run the particular set of data. All right, that's it, guys, and see you in the next lesson.