In a nutshell
Miscellaneous tasks are utility tasks that extend what a web test case can do beyond core interactions. The data retrieval tasks let you capture text content, attributes, element counts, and dimensions from page elements for use in subsequent steps or validations. The Handle Alert task dismisses browser pop-ups that would otherwise interrupt test flow, and the Info task logs messages or variable values at any point during execution.
Overview
Miscellaneous tasks include the following:
Note: These tasks are used for web test cases.
Get Text
This task retrieves and returns the text value of an element within the webpage. For example, this can be used to fetch product names, descriptions, or prices from an ecommerce website.
Syntax
<variable> = getText(<locator>);
Return Type
STRING
Parameter | Data Type | Description |
<variable> | STRING | Variable to store the text value of the element. This value can be a visible text data from webpages. |
<locator> | STRING | Address to locate the element from which the text should be retrieved. Note: The value to this parameter can either be supplied with recorded locators stored as elements or hard coded with the necessary locators in the format "<locator>". Learn more. |
Example: A user wants to test a product webpage inside an ecommerce website. The product webpage contains a currency type dropdown on top, to show the price of the product in either "INR" or "USD". The following script verifies whether the price of the selected product is displayed correctly based on the currency type chosen in the dropdown.
- openURL("https://zwatch.com","same window"); // Navigates to the URL. Learn more about the OpenURL task.
- currencyType = getText("li[data-theme-base-currency]"); // Stores the text values fetched from the currency type dropdown element to a variable named currencyType.
- if(currencyType == "INR") // Checks if the currency type in the dropdown displays the INR or USD price of the product.
- {
assertText("//span[@data-zs-selling-price='30000.0']", "Rs.30,000.00" ,errorhandling.STOP_ON_ERROR); // Verifies whether the price is displayed in INR.- }
- else if(currencyType == "USD")
- {
assertText("//span[@data-zs-selling-price='30000.0']", "$360.84" ,errorhandling.STOP_ON_ERROR); // Verifies whether the price is displayed in USD.- }
where:
"https://zwatch.com" | URL of the website that needs to be opened. |
"same window" | This represents that the URL needs to be opened in the same window. |
currencyType | The variable that stores the currency type chosen by the user. The user can choose between "INR" and "USD". |
"li[data-theme-base-currency]" | The inspected locator of the dropdown that contains the currency type on the website. |
"//span[@data-zs-selling-price='30000.0']" | The inspected locator of the element that contains the currency text that has to be displayed. |
"Rs.30,000.00" | The text visible in the product description, if the currency type chosen is "INR". |
errorhandling.STOP_ON_ERROR | This error handling behaviour stops the execution of the test case, if the currency isn't displayed correctly. |
"$360.84" | The text visible in the product description, if the currency type chosen is "USD". |
Get Attribute
An attribute is a characteristic or property that provides additional information about a web element and influences its behavior or appearance on a webpage. The Get Attribute task stores the specific attribute value of an element within the webpage. For example, a user wants to check if a product image on an ecommerce site is displayed correctly. You can use the task to get the value stored against the "src" attribute of the image element and then validate if it matches the expected URL.
Syntax
<variable> = getAttribute(<locator>, <attribute>);
Return Type
STRING
Parameter | Data Type | Description |
<variable> | STRING | Variable to store the attribute value of the element. |
<locator> | STRING | Address to locate the element whose attribute value has to be fetched. Note: The value to this parameter can either be supplied with recorded locators stored as elements or hard coded with the necessary locators in the format "<locator>". Learn more. |
<attribute> | STRING | Name of the attribute whose value needs to be fetched. Specify the type of attribute, as "<attribute>". |
Example: A user wants to test that a product image on an ecommerce website has appropriate and descriptive "alt" text attributes. "Alt" text is essential for web accessibility, as it provides alternative descriptions of images for users with disabilities and search engines. The following script allows the user to check whether the alt text for a product's image is displayed correctly.
altTextCheck = getAttribute("//img[@class='zpimage zpimage-style-none zpimage-space-none ']","alt"); // Stores the text value from the "alt" attribute to a variable.
if(altTextCheck != "Watch Shopping") // Checks whether the text value fetched from the alt attribute is "Watch Shopping".
{
throwError("Incorrect alt text"); //ThrowError task is used to throw an exception during the test script workflow. Learn more. }
where:
"https://zwatch.com" | URL of the website that needs to be opened. |
"same window" | This represents that the URL needs to be opened in the same window. |
altTextCheck | The variable that stores the text fetched from the alt attribute of the product's image. |
//img[@class='zpimage zpimage-style-none zpimage-space-none '] | The inspected locator of the product image. |
"alt" | The attribute from which the text value has to be fetched from. |
"Incorrect alt text" | The message that has to be displayed if the text fetched from the alt attribute matches with the expected text. |
Get Count
This task counts the occurrences of an element within the webpage. For example, to count the total items in a product list to ensure completeness.
Syntax
<variable> = getCount(<locator>);
Return Type
LONG
Parameter | Data Type | Description |
<variable> | STRING | Variable to store the count of the elements for the specified locator. |
<locator> | STRING | Address to locate the element for which the count has to be fetched. Note: The value to this parameter can either be supplied with recorded locators stored as elements or hard coded with the necessary locators in the format "<locator>". Learn more. |
Example: A user wants to test if the products are listed correctly on the ecommerce website. The following script checks if there are six products listed on the website.
- noofproducts = getCount(".theme-prod-box");
- if(noofproducts != 6)
- {
- throwError("There is a mismatch in the product count"); // ThrowError task is used to throw an exception during the test script work flow. Learn more.
- }
where:
noofproducts | The variable that stores the count of how many products are visible on the website. |
".theme-prod-box" | The inspected locator for the products listed on the website. |
"There is a mismatch in the product count" | The message that has to be displayed, if there is a product count mismatch with the expected count. |
Get Element Width
This task returns the width of an element within the webpage. For example, to validate the width of an image element for correct display on the webpage.
Syntax
<variable> = getWidth(<locator>);
Return Type
LONG
Parameter | Data Type | Description |
<variable> | STRING | Variable to store the value of width of the element. |
<locator> | STRING | Address to locate the element for which the width has to be fetched. Note: The value to this parameter can either be supplied with recorded locators stored as elements or hard coded with the necessary locators in the format "<locator>". Learn more. |
Example: A user wants to test the width of a product's image on the e-commerce website. The following script checks whether the width of the product image is equivalent to 110 pixels.
- productWidthCheck = getWidth("//img[@class='zpimage zpimage-style-none zpimage-space-none ']");
- if(productWidthCheck != 110)
- {
- throwError("Width of the product image is incorrect");
- }
where:
productWidthCheck | Variable to store the width of the product's image. |
"//img[@class='zpimage zpimage-style-none zpimage-space-none ']" | The inspected locator of the product image. |
"Width of the product image is incorrect" | The message that has to be displayed, if the width of the product image is incorrect. |
Get Element Height
The task returns the height of an element within the webpage. For example, to validate the height of an image element for correct display on the webpage.
Syntax
<variable> = getHeight(<locator>);
Return Type
LONG
Parameter | Data Type | Description |
<variable> | STRING | Variable to store the value of height of the element. |
<locator> | STRING | Address to locate the element for which the height has to be fetched. Note: The value to this parameter can either be supplied with recorded locators stored as elements or hard coded with the necessary locators in the format "<locator>". Learn more. |
Example: A user wants to test the height of a product's image on the ecommerce website. The following script checks whether the width of the product image is equivalent to 62 pixels.
- productHeightCheck = getHeight("//img[@class='zpimage zpimage-style-none zpimage-space-none ']");
- if(productHeightCheck != 62)
- {
- throwError("Height of the product image is incorrect");
- }
where:
productHeightCheck | Variable to store the height of the product's image. |
"//img[@class='zpimage zpimage-style-none zpimage-space-none ']" | The inspected locator of the product image. |
"Height of the product image is incorrect" | The message that has to be displayed, if the height of the product image is incorrect. |
Info
The task is a debugging statement which when executed displays the value of an appended expression.
Syntax
info(<message>);
Parameter | Data Type | Description |
<message> | OBJECT | The value to be displayed. You can directly specify a value, or you can also specify an expression, i.e. constants, <variables>, <operators>, <calls to functions> and so on, which evaluates to a value. |
Example 1: The following script returns the value of the variable "a".
- a = "Hello, User!";
- info(a); // Returns the value stored in the variable - a.
Example 2: A user wants to test a product page within an e-commerce website, which features a currency type dropdown at the top, allowing users to display the product price in either 'INR' or 'USD'. The following script returns the available currency types within the dropdown.
- openURL("https://zwatch.com", "same window"); // Navigates to the URL. Learn more about the OpenURL task.
- currencyType = getText("li[data-theme-base-currency]"); // Fetches the currency types from the dropdown. Learn more.
- info(currencyType);
where:
"https://zwatch.com" | URL of the website that needs to be opened. |
"same window" | This represents that the URL needs to be opened in the same window. |
currencyType | The variable that stores the currency type chosen by the user. The user can choose between "INR" and "USD". |
"li[data-theme-base-currency]" | The inspected locator of the dropdown that contains the currency type on the website. |
Handle Alert
An alert informs users of important information or requests permission for specific operations, and can also serve as a warning. This task confirms or cancels browser alerts or pop-up dialog boxes that appear on a webpage.
The Handle Alert task supports two syntaxes. The first one takes the decision to accept or reject the alert and verifies the message within the alert. When using this syntax, the task not only focuses on the decision but also validates the message. If the validation fails, the entire task fails. On the other hand, the second syntax just performs the decision to accept or reject the alert.
Syntax
handleAlert(<decision>,<message>);
Parameter | Data Type | Description |
<decision> | BOOLEAN | It takes a boolean logic value, either "TRUE" or "FALSE", which determines how the task should interact with the alert. |
<message> | STRING | Message displayed in the alert, which has to be verified. |
Syntax
handleAlert(<decision>);
| Parameter | Data Type | Description |
<decision> | BOOLEAN | It takes a boolean logic value, either "TRUE" or "FALSE", which determines how the task should interact with the alert. |
Example 1: A user wants to test the shipping confirmation alert that appears after a user completes a purchase. This alert confirms the successful shipment of an order and contains important details. The following script ensures that successful payment alert is acknowledged correctly and validates the alert message.
where:
"#zs-make-payment-button" | The inspected locator for the "Make Payment" button. |
5 | Specifying the time in seconds, for the payment to be done. |
True | The decision to accept or confirm the alert box. |
"Order #12345 has been shipped." | The order confirmation message displayed in the alert box. |