Skip to main content

Creating Test data

Introduction#

To create tests scripts for our web shopping app, we will need to create test data that can be sent to the user-entry forms of the user screens of the web shopping web app. We can ofcourse code test data into our test scripts using fixed values, but we would then miss out on the power of variability when running Vitaq with multiple seed runs.

Our current Vitaq test activity is focused on creating tests for our simple web shopping app, Swaglabs. The test data needed for this can easily be identified by looking at the login screen, products screen and the checkout screen.

We need to generate user input data for usernames, sortOrder, first names, last names, and postcodes.

Activity Variables#

Test data is defined in our test activity in the Activity Variables tab on the top right hand-side of your Vitaq Test Automation window. The type of test data needed for the user forms is easily identifiable by looking at the user screens and determining if it is text, integer numbers, decimal numbers or true/false selection.

If it is text, we can define a list of text values for Vitaq to choose from, so let’s start by defining the test data for the accepted usernames. We will call the Activity Variable 'userNames'. Click on the ‘down arrow’ of the Action Properties selector and select ‘from list’. Click the + button and fill in the ‘Add from List’ form with the variable name userNames, you do not need units for this variable as it is just plain text, then provide a list of possible text values for Vitaq to select from such as stardard_user, locked_out_user, problem_user, performance_glitch_user then click ok.

warning

Remember to use the correct syntax (which follows Python coding rules). If you make a mistake then Vitaq will inform you and display a red box around the entry that is incorrect.

Activity Variable units#

Please note: the units in the Activity Variables are for label purposes only. For example if you are creating an Activity Variable called length, then you will want to know what units that length is identifying, such as mm, cm, m, or km for example.

Activity Variable tab#

The ‘Must Have’ Activity Variables needed for our web shopping App Test Activity are: userNames, sortOrder, firstNames, lastNames and postCodes.

The only variable in this list that is not a text list is sortItems, which is a integer number for selecting the index in the drop down menu or sort items. To generate a integer number using Vitaq we need to use a Integer Number variable. Click on the Activity Variables pull down menu and select Integer Number and then click on the + button to add the variable. Fill out the form as it is shown below. This gives us a integer number with a range of 1 to 4.

Complete the list of Activity Variables as below. If you make a mistake, then double click on the Activity Variable and the edit form will pop-up for you to make changes.

You can reorder, delete and collapse the activity variable using the menu bar as shown below.

Weighting the automatic selection of Activity Variable data#

As well as weighting the automatic selection of next allowable Test Actions, Vitaq users can intelligently weight the automatic selection of Activity Variable data values.

To increase the probability of Vitaq selecting a particular element in an Activity Variable list, you need to follow the List item name with a : and then number to denote the % probability of Vitaq selecting it. It is good practice to make sure that all of your % Probability values add up to 100 and hence the % Value directly represents a portion of that 100%, as shown below.

Generating test data in test action scripts#

Now we have defined the test activity diagram and activity variables, it is time to complete the WebdriverIO Spec Action scripts for Vitaq to auto-generate test data using the Activity Variables to test the web shopping App.

Accessing Activity Variables in webDriverIO test action scripts#

To access the Vitaq Test Activity variable generated data in the WebdriverIO Spec Action JavaScript code you need to use the vitaq method as shown below:

Note

If you execute another await requestData(usernames) in the same Spec Action script or in another Spec Action script, Vitaq will generate a new value.

When you want to use a value from one Vitaq Spec Action code script in another Spec Action then you can use the SendDataToVitaq() and readDataFromVitaq() methods in Vitaq Library Methods for Test Data

Vitaq methods in WebdriverIO Spec Action scripts#

To use a Vitaq method from either Vitaq Library Methods for Test Actions or Vitaq Library Methods for Test Data use the 'vitaq.' as shown below in the example for the set_enabled method

await vitaq.setEnabled("onesie", false);

This will disable the test action called onesie in the Vitaq test activity run.

Using constraints to control generation of random test data values#

There will be situations where once a variable has been selected it can then not be used again. To do this we can use the Vitaq library methods Vitaq Library Methods for Test Data that perform constraints on lists of items (or ranges of values). For example we can ‘allowOnlyList’ for a generation of a name from the userNames Vitaq Test Activity variable in our example web shopping app Test Activity once it has already been selected in login Spec Action script.

await vitaq.allowOnlyList("userNames", ['standard_user', 'problem_user']);
let username = vitaq.requestData("userNames");

A full list of Vitaq library methods that provide constraints on data generation can be found in Vitaq Library Methods for Test Data

Dynamically disabling Test Actions#

We discussed how to disable a Test Action before running a Test Activity earlier. There will be situations in which it will be useful to disable a Test Action during the running of a Test Activity, we call this dynamically disabling a Test Action. To do this we use the Vitaq method

await vitaq.setEnabled("nameOfVitaqSpecAction", false);