Command Templates (BETA)

Command Templates are used to simplify authoring some repetitive steps which can include several interactions at once where these steps include some similarities in their locator definition. They can also be extended to specific commands and by doing so, the default command options can be overridden to use the extension. The commands to which functions can be extended are (Click / Check / Drag_and_Drop / Fill / Hover / Hover_and_Click / Select ).

 

Test Scenarios

 

Date Selector: For this scenario, we will be using the Birthday selector on Ref App.

  1. Create a test case to log into a user and navigate to Profile > Edit Profile.

  2. Define steps for clicking on the date selector shown below

1.png
 

3. Define a step for clicking on the year button shown below. The hint/label provided for this element must be something generic (not MAY 1991) so that if a different date appears, the XPath will still be able to find the required element.

2.png
 

4. Define a step to click on 1991 so that you can see the years. Same as noted in step 3, the hint/label must not be 1991 ('year' or 'years' can be used).

3.png
 

5. Now you will be taken to Years view. Define a step to click on any one of them. You can use a specific hint/label this time, like 1988 for example.

4.png
 

6. After that, you will be taken to the Months view. Define a step to click on a specific month, like June for example.

5.png
 

7. Finally, you will be taken into Days view. Define a step to click on a specific day, like 24 for example. Note that there are some days entered twice here, like 29-31 or 01-09. If your XPath is too generic like //span[contains(text(),'29')], it is going to find 2 matches and pick the first one which may not be the desirable one. So in such cases, you will need to strengthen your XPath to reference specific elements by using an attribute that belongs only to such items, like 'class' below.

 
1//span[@class='ng-binding' and contains(text(),'29')]
6.png
 

8. Now going back to the platform, you will have created all the needed steps. We will be returning to the last 3 steps to modify their XPaths.

9. Let’s select all repetitive steps that we plan on using in future tests. In the above example, they will be 9-14 (clicking on calendar and ending with selecting a day). 

10. Let’s group these steps info a function by selecting them and clicking on the icon shown below. You can select steps 9 to 14 and you will be prompted to range all steps in between. When you are asked to replace the existing steps with the function, click No.

 

11. Now that the function is created, let’s navigate to Library > Functions and open the function.

12. After opening the function, click Show Function Info so that we can see the information below.

13. Now we click on + next to Parameters.

14. We will see the following options:

A. BOOLEAN: This will allow you to select either True or False values.

B. CHOICE: This will allow you to enter your own choices and select them from the step before you execute your test. Default values can also be specified.

C. TEXT: This will allow you to enter any text as a default value, or you can leave it empty and enter a text before you execute your test.

15. The best option for a date selector will be to pick CHOICE and created 3 parameters for Day/Month/Year

16. You can click + next to Parameters to add two more options and then click + next to Choices to begin adding your choices:

NOTE: The values to enter as choices must match exactly how they appear on the application in order to make sure your dynamic XPath picks the correct option.

17.Let’s enter 01-31 in Day, January-December in Month and 1981-2000 in Year. You can modify and of the data by clicking on the textbox and changing it. To delete data, you can click on the delete icon next to it. Once the data is ready, you can save your function.

18. Next step will be to change the XPaths for the last 3 steps so that they will automatically pick up the option you will select. To do that, we have to go to the locator definition page for each step. The example below shows how to do it for the year selection:

19. Now we will see the XPath we collected earlier for the year which says 1988. We will need to change it to reference the variable Year which is the name of the Parameter in step 16.

20. Delete ‘1988' and enter '@’, this will display a list of all the variables defined in the function parameters. We can select Year from the list and so our XPath will become:

 
1//span[contains(text(),'@Year')]/ancestor::button
 

21. Repeat the same steps for the remaining steps for Days and Months.

22. Once finished, you can extend the function to the command Click by selecting it from the dropdown as shown below and save.

23. Once you are finished, go back to the test case. Now you can delete all the previous steps, define a new step with Click command, pick Extension from the dropdown list and select the function (command template) created earlier.

24. Now you will see all the choices you created as well as their values added in dropdown lists.

25. You can make a different selection if you like before you run your test case locally

26. Once execution starts, the dynamic XPath will function according to any selection you make above. So if you pick April 25th, 1986, the date will be automatically picked in your test case to match your selection.

 
 
Verify and Click: For this scenario, we will be using the the main page on Ref App.
  1. Create a test case that navigates to the site https://reference.subject-7.com

  2. Generate XPaths for some links you see on the page and save them for later.

    21.png
     

3. On the platform, define two steps with a dummy XPath. One of Verify_Element command and the other for Click command.

4. Let’s group these steps info a function by selecting them and clicking on the icon shown below. When you are asked to replace the existing steps with the function, click No.

5.Now that the function is created, let’s navigate to the function and click Information tab.

6. Let’s use TEXT parameter and enter a parameter name XPath. You can enter any XPath value as a default, or leave it empty.

7. Now let’s remove the dummy XPath for the web locator and replace it with ‘@XPath’ which is the variable from the parameter.

8. Let’s extend the test case to Click command and save it.

9. Let’s get back to the test case, delete Verify_Element and Click steps, add a new step with Click command, select Extension option from the dropdown list and select the function.

10. After we select the extension, we will see the XPath field we created earlier. Now you can enter any of the XPaths you collected, so it can be verified once and clicked once.

11. Run your test case to ensure everything is working as expected.

12. If you have several elements on the page that require verifying and clicking, you can copy the Click step in your test case and add the other XPaths to the step. This will save you time from creating different web locators with different XPaths.

 

 

Value Templatization

  1. You can create data templates and datasets for each parameter and the same values (on the function/extension) can be added to the datasets. This way, you can click Raw option next to each parameter and inject the data template. This will make it easier to select your datasets before you execute the test cases, either locally or in cloud.
  2. In the following image, you will notice that the fields are templatized and Raw option is disabled. If you would like to revert to the options from the function/extension, remove the template from the box by clearing the text so that Raw option is clickable. Then disable it and pick the option you desire.
  3. Dataset selection view from test case:

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

Please sign in to leave a comment.