Generate Test Data | Bondar Academy
Course: Mastering testRigor
Module: Advanced Tricks and Techniques
Instructor: Artem Bondar
Lesson Summary
Lesson Overview: This lesson focuses on generating unique test data for test cases using TestRigger . It covers how to automate the testing of a signup feature by creating unique usernames, emails, and passwords. Generating Unique Test Data To test the signup feature, it is essential to provide unique credentials each time. TestRigger offers commands to generate this data easily: Generate Unique Name: Use generate unique name to create a unique username. Generate Unique Email: Use generate unique email for a unique email address. Password: A hard-coded password can be used, e.g., welcome . Creating Articles with Random Data In addition to user credentials, you can generate random data for articles: Generate from Template: Use generate from template to create titles and descriptions. For example, ****testing generates random characters followed by "testing". Character Types: # for numbers (e.g., phone numbers). $ for lowercase letters. % for uppercase letters. Using Regular Expressions For more complex data generation, you can use regular expressions : generate from regex [A-Z]{50} This command generates a string of 50 uppercase letters. Summary of Key Commands generate unique name - Generates a unique username. generate unique email - Generates a unique email address. generate from template - Creates random strings based on specified templates. generate from regex - Generates strings based on regular expressions. This lesson demonstrates how to effectively use TestRigger to automate the generation of test data, enhancing the efficiency of your testing process.
Video Transcript
In this lesson we will talk about how to generate a unique test data for your test cases. So TestRigger has a special commands for that and it's very easy to use. So let's get into it. This is our test application and previously we executed all of our tests as a logged in user. But how about if we want to test let's say a signup feature over here. That signup feature of our application works well. To test this feature we need to provide a unique username and password every time otherwise you will not be able to create the same account again and again. And to test this kind of scenario we need a generator that will automatically generate for us a test data for username, email and maybe for the password. So let's automate this scenario of testing signup feature for the test application. So going back to our framework and I create a new test signup. So the first thing we need to click on sign up to open the signup screen. This one and then we need to type username, email and password into the fields. So how would I type a unique username? So TestRigger has a unique command for that. Generate unique name. So simple. Then enter into username and after that we can save the generated value into variable because we want to validate this value later on the home page. And save as test username. Something like this. The same we can do for the email. Generate unique email then enter into and then enter into email. We don't need to save it because we will not validate the email later on. And then the last step we need to type password. Let's use just a hard-coded password for this scenario and enter let's say welcome into password and after that we want to click to click what sign up below password. Click sign up roughly below password. That's it. So let me quickly run this test to see if it is working. All right and that's worked successfully. So if I open the screenshot look at this. So it's generated a random string for the username. It's just alphabetical characters and for the email is generated numeric and alphabetical characters at testriggeremail.com. So TestRigger has these two commands unique name and unique email as predefined commands to generate a test data. Because this is one of the most typical use case when you need a random user just to continue your flow. But if you need more than that and want to generate other types of data for your for example different forms you can do that as well. And let's just continue with scenario with creation of the new article and we will create this article with randomly generated title description and body as well. So I click on click new article and after that what I need to do so you All right new article. So let's type some random string into article title. How would I do this? So I would call command generate again but generate from template. And then I provide the template that I want to have. And here are the special characters. So if you want to generate the string with just random letters or numbers you just provide the asterisks and the length of the string will be defined by the number of asterisks you provide inside of the string. And this is how it works. And for example asterisks and then you want to add something like this testing. So these will be a random characters and then testing will clearly define that this is related to testing. So generate from template and enter into article title. Article title. Another example let's say that you would like to generate a numbers only. So for that you have another type of the character which is a hash sign. So sometimes you need to generate the phone number for example and you can use a hash sign which will represent only the number. So it can be something like 1 2 3, 1 2 3, 1 2 and 1 2. So this is template for the phone number. Or maybe you need to enter any other types of the numbers or code or something like this. You can use a hash sign for that. Let's say that we will type this into the article about. Article about. And now let's talk about the body. For example we generate the template one more time. And another example of template. If you want to generate only the letters that are capital case then you use a dollar sign. If you want to use the letters only the lowercase then you use the percentile sign. Something like this. So in this example we will generate five symbols of the capital case and how many is it six symbols of the lowercase. And after that we need to click on publish article. That's it. So let's run this test one more time. So the new user will be created and after that this user will create a new article. And by the way we forgot to add the assertion. Let's add the assertion over here. So click sign up and after that check the page contains stored value. This is the store value over here to the right of settings. All right and let's run this test. Update and retest. All right so let's check it out. So here is our assertion that stored value of newly created user is displayed on the home page when new user is created. Then we created a new article. So we have the random string of different letters and numbers dash testing. But something didn't work with these two. Okay we made somewhere a mistake. Let's look at this. So okay article is about and here we need to provide body. So this is write your article. Okay write your article and article title article about write your article and publish the article. Okay let's run this one more time. All right article was created. Let's check the screenshot. Yeah I know everything works correct. So we created a random title dash testing. Then the brief description is just number that we provided. And the last string we provided characters in the lowercase and the capital case exactly as according to our template. And one more example. So let's say that you need to provide a long string or a string of the specific type of the format that you cannot type like like this. In this case you can use a regular expressions. For example so let me type a different value into the article body. So I'll comment this code and we'll replace this template. So instead of generate from template I will use generate from regex regular expression. And then inside of the string I need to provide the regular expression. Let's say that I want to type A to Z capital case characters. So my string has to be created only from A to Z characters capital case. And the length of the string has to be for example 50 characters something like this. And here I need to remove one from. So generate from regex A to Z 50 characters and enter write your article. So let's run this one more time. All right test completed. Let's check it out. And now you can see the body of the article has the long string only capital case characters and the length of 50 characters long. So this is how you can use general expression to generate a longer values if you need those. All right so let's quickly summarize what we did in this lesson. TestRigor has two unique commands to generate names and emails. Just simply generate unique name and generate unique email as your test credentials for the test data on your test scenario. You can also save those values as variables and then use those variables later inside of your test for example to make assertion how we did it over here. Also if you need a different combinations of the random string you can use templates like this. The asterisks will represent any type of character lowercase uppercase or the number. You can combine this random string with your own values of the string. You can generate the numbers using hash sign. You can generate a lowercase letters using dollar sign and capital case using a percentile sign. And also you can use a regular expressions to make a more custom random strings of different length in case you need that for your test scenario. All right that's it guys and see you in the next lesson.