The I.fill command in UIlicious is handy for filling out Contact Us and Signup forms. But what happens when you want to input random values rather than set a specific value in fields such as a name, email address, and even phone number? Luckily, in UIlicious, you can! Let me fill you in with the details.
Table of Contents:
Using single values for the I.fill command
One of the most important aspects of automation testing is that there may be instances where testers will need to test features such as Contact Us and Sign Up forms multiple times. During those testing moments, you may need to use data within the form fields that you may not want to declare as a set value.
One example is with the I.fill command. We can input a simple command such as:
I.fill("Username", "[email protected]");
The code above is a prime example of what I am referring to with a set of values. In the form, we say I want to fill the Username field with [email protected]. However, there may be instances where testing a form field multiple times may require unique values entered into the form fields. Plus, having the ability to generate random values means we will have a variety of test results with our automation scripts when running multiple times.
It’s okay to be random
Knowing how to write a test script that will generate random values, including names, email addresses, and phone numbers adds a nice variety to your automation testing results.
In this How-To, I will show you five examples of using value randomizations for filling out forms.
Let’s start with using a website that has a Sign-up form. For this example, I am using the form on PHPTravels.
I.goTo("https://www.phptravels.net/signup");
I will use the following form fields for this example: First Name, Last Name, Phone, Email, and Password.
What’s my name?
Before using the I.fill command, we need to do something first for each form field. We need to put in a variable with the form field, using the command SAMPLE and the field's name. Every SAMPLE command generates a new randomized value.
Let us start with the first two fields, First and Last Name.
To generate randomized data for the first name, we would do the following:
Var (variable) first (first name field) = SAMPLE.first() (this is saying put random data in the first name field. Then we use the I.fill command, but when we use this command, we will do something different.
Usually, with the I.fill command, we fill in the form field name followed by the value such as:
I.fill("First Name", "[email protected]");
However, we do the following instead when using randomized data: I.fill("First Name", first); . The difference here is we are not using a specific value for the field. Instead, we are saying we want to insert the generated first name in the first name field.
This is how it would all look together:
var first = SAMPLE.first()
I.fill("First Name", first);
Now, when I run this specific script, the data will be generated differently every time for the First Name form field.
The rest of the form fields are similar. We just have to use different names to reflect the form fields.
We will use a similar script to the First Name for the Last Name field, except we use last instead of first.
var last= SAMPLE.last()
I.fill("Last Name", last);
This will generate a randomized last name. If there is one form field with both the first and last names combined, we will use a Full Name assertion instead of a first or last name.
var name= SAMPLE.name()
I.fill("Full Name", name);
The rest of the fields
Now that we have the naming fields, we can focus on the rest of the three remaining form fields: Phone, Email, and Password.
We are almost done with the remaining three fields to automate!
The following field, the Phone text field, is the next one on our list to automate for testing. The code is similar but a little different from the variable. Instead of using var or variable, we will use let, which signifies that we are letting the UIlicious automation tool randomly generate a set of numbers for our phone number.
let name= SAMPLE.phone()
I.fill("Phone Number", phone);
With our phone number now in place, we have an email and password remaining. Again, these are very similar to our previous first and last name scripts since we are using a variable.
var email= SAMPLE.email()
I.fill("Email", email);
And
var name= SAMPLE.id(12)
I.fill("Password", password);
If we take the concept from the first and last name script and apply the same logic to email, we can see that the test script declares a randomized email sample such as:
"email": "[email protected]"
For the final example, the Password, we see something new in that script: an id and a number.
I fill "Password": "QaCAaWtJs2VX"
In this, we are saying our sample password id will be 12 characters long, consisting of both numbers and alphabetical characters. This is perfect for testing character limitations within your password field since some fields will have a character minimum and maximum.
And now that we have our script built let’s see how it looks all together!
I.goTo("https://www.phptravels.net/signup")
var first = SAMPLE.first()
I.fill("First Name", first);
var last= SAMPLE.last()
I.fill("Last Name", last);
var name= SAMPLE.phone()
I.fill("Phone Number", phone);
var email= SAMPLE.email()
I.fill("Email", email);
var name= SAMPLE.id(12)
I.fill("Password", password);
Here is an example of the script after it is used in a test:
I go to "https://www.phptravels.net/signup"
I fill "first name": "Mitchell"
I fill "last name": "Koster"
I fill "Phone Number": "(205) 826-6016"
I fill "email": "[email protected]"
I fill "Password": "QaCAaWtJs2VX"
Final Thoughts
Now, you know how to write some fun test scripts that will generate unique results. This gives your automation testing a nice variety of testing forms and logins. Don’t hesitate to try it now on your own UIlicious projects.
Happy Testing! :)