This list of tasks help create robust and flexible automation scripts that can adapt to various conditions and handle exceptions effectively. Logic tasks include the following:
- Execute JS
- Conditional statements - IF, ELSE IF, and ELSE
- Set Variable
- Call Function
- Finally
- Continue On Error
1. Execute JS
The task executes Javascript code on the currently selected window or frame within a webpage. This is particularly valuable for performing advanced validations, or custom actions that cannot be achieved using other standard tasks inside Zoho QEngine. For example, this task can be used to manipulate dynamically changing elements on a webpage, such as custom drop-downs.
Syntax
executeJS(<script>);
Return Type
STRING
Parameter | Data Type | Description |
<script> | STRING | This contains the JavaScript code snippet. It should be written within (" ") and must adhere to JavaScript syntax rules.
Note: There won't be a screenshot preview for this task, as the execution takes place directly in the browser console. |
2. Conditional statements - IF, Else IF, Else
Zoho QEngine offers tasks that help us write conditional statements that are essential to implement decision logic, allowing different code blocks to be executed based on varying conditions or criteria. The following are the conditional statement variants to build your business logic:
Note: Conditional Statements examine specified criteria, and act in one way if the criteria are met, or in another way if the criteria are not met. The criteria is mandatory for all conditional statements except the "else" conditional statement. The "else" conditional statement does not accept any criteria.IF
Validates given criterion and performs specified actions if the criterion is met. The "If" conditional statement can be followed by "else if" and "else" conditional statements(not mandatory). If the criterion is not met, the actions are skipped, and the program moves on to the next task.
Syntax
if(<variable> <operator> <expression>)
{
<Actions>
}
Parameter | Description |
<variable> | Variable that stores the value that needs to be compared to a specified value. |
<operator> | Operator to compare the variable's value against the specified value. |
<expression> | It may directly be a value, or an expression evaluating to the required value, which needs to be compared with the specified value stored in the variable. |
<Actions> | Set of conditions to be executed when the specified criteria are met. This can also be other Zoho QEngine tasks. |
Else IF
The "else if" conditional statement is always preceded by an "if" conditional statement. It executes given statements when the preceding "if" conditional statement fails and the "else if" criterion is met. If the "else if" criterion is also not met, the actions are skipped, and the program moves on to the next task.
Syntax
else if(<variable> <operator> <expression>)
{
<Actions>
}
Parameter | Description |
<variable> | Variable that stores the value that needs to be compared to a specified value. |
<operator> | Operator to compare the variable's value against the specified value. |
<expression> | It may directly be a value, or an expression evaluating to the required value, which needs to be compared with the specified value stored in the variable. |
<Actions> | Set of conditions to be executed when the specified criteria are met. This can also be other Zoho QEngine tasks. |
Else
The "else" conditional statement is always preceded by an "if" or an "else if" conditional statement. It executes given statements when the preceding "if" and "else if" conditional statements fail. The "else" statement, if present, must always be the last in a set of conditional statements, i.e., it must not be followed by the "if" or the "else if" condition in that set of statements.
Syntax
else
{
<actions>
}
Example: A user wants to test a form. The following script checks if the entered name and email are valid.
- openURL("www.zwatch.com" , "same window"); // Navigates to the URL. Learn more about openURL task
- enteredname = getText(ui.zwatch.username_field);
- enteredemail = getText(ui.zwatch.email_field);
- validuname = "Chris Morgan";
- validemail = "Chrismorgan@gmail.com";
-
- if(enteredname == validname && enteredemail==validemail) // Validates the entered email and name in the login form matches with the actual.
- {
- info("Entered name and email matched the valid username and email.");
- }
- else if(enteredname == validname && enteredemail != validemail)
- {
- info("Email is incorrect");
- }
- else if(enteredname != validname && enteredemail == validemail)
- {
- info("Name is incorrect");
- }
- else
- {
- info("Both name and email are incorrect.");
- }
where:
"www.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. |
enteredname | The local variable that stores the entered user name from the name field in the login form. |
ui.zwatch.name_field | The recorded element for the name field of the login form. |
enteredemail | The local variable that stores the entered email from the email field in the login form. |
ui.zwatch.email_field | The recorded element for the email field of the login form. |
validname | The local variable that stores the actual name to login. |
"Chris Morgan" | The valid name saved to perform the validation. |
validemail | The local variable that stores the actual email to login. |
"Chrismorgan@gmail.com" | The valid password saved to perform the validation. |
"Entered name and email matched the valid name and email." | The message displayed when the name and email entered in the login form matches with the actual. |
"Email is incorrect" | The message displayed when the email which is entered in the login form doesn't match with the actual. |
"Name is incorrect" | The message displayed when the name which is entered in the login form doesn't match with the actual. |
"Both name and email are incorrect." | The message displayed when the name and email entered in the login form doesn't match with the actual. |
3. Set Variable
The Set Variable task assigns a given expression or value to a local variable, which is accessible only within the respective test case. A local variable declared in this way ensures that its scope is limited to the test case where it is defined.
Syntax
<variable> = <expression>;
Parameter | Description |
<variable> | Variable which will hold the given value. |
<expression> | Value to be assigned to the variable. |
Example 1: The following script assigns the value 0 to variable - temp:
Example 2: A user wants to check the add to cart functionality of a website. The following script verifies whether a product is added to the cart.
- cart_count = getCount(ui.zwatch.cart); // Stores the count fetched from the cart. Learn more about the Get Count task
-
- // Check whether the selected product is added to the cart.
- if(cart_count == 1)
- {
- info(cart_count +" "+ "product has been added to the cart."); // Here, the + operator is used to concatenate the variable value and the string text.
- }
- else
- {
- info("Failed to add the product to the cart.");
- }
where:
cart_count | The local variable that stores the count of products added to the cart. |
ui.zwatch.cart | The recorded element for the cart of the e-commerce website. |
cart_count +" "+ "product has been successfully added to the cart." | The concatenated expression that has to be displayed if the product is added to the cart. |
"Failed to add the product to the cart." | The message that has to be displayed if the product isn't added to the cart. |
4. Call Function
Functions created within a project are accessible across all the test cases within the project. This task invokes a custom function defined inside the respective project.
Syntax
<module_linkname>.<function_linkname>(<parameters>);
(or)
<variable> = <module_linkname>.<function_linkname>(<parameters>);
Parameter | Description |
<module_linkname> | Link name of the module in which the function has been defined. |
<function_linkname> | Name of the function to be invoked. |
<parameters> | The arguments that are passed to the function at the time of invocation. An argument is a variable declared while defining a function.
 Note:
The usage of a parameter depends on whether arguments are specified while defining the function. A parameter can be a variable or an expression that evaluates to a value.
The number of parameters and their data types must match the arguments specified in the function definition. Any mismatch will result in an error, and the script will not be saved.
|
Example: A user wants to test the add to cart functionality of an e-commerce website. The following script calls a user defined function "zaccounts.login()" to login to an e-commerce website. After logging in, the user wants to add a product to the cart.
where:
zaccounts.login(); | The login function called inside the test script. |
"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. |
ui.zwatch.zwatch_Daytona | The recorded element for the selected product. |
ui.zwatch.add_to_cart_button | The recorded element for the "Add To Cart" button. |
5 | The time it waits for the webpage to add the product to the cart. |
5. Finally
The task executes the script block regardless of whether the preceding test steps succeed or encounter exceptions. This script block will be executed as a final step, providing a way to ensure that certain actions are taken irrespective of the test case outcome. For example, cleanup operations that have to be performed irrespective of the test case outcome.
Syntax
finally
{
<action>
}
Parameter | Description |
<action> | Custom logic or function to be executed irrespective of the test case results. This can also be Zoho QEngine tasks. |
6. Continue On Error
The task executes the enclosed script blocks irrespective of the error that occurs during test case execution. For example, it is used to prevent a single error from interrupting the entire test case workflow.
Syntax
continueOnError
{
<code>
}
Parameter | Description |
<code> | Custom logic or functions to be enclosed to prevent it from test case termination. |