Conditional Statement -Looping and handling a list of WebElements

QAautoMATER allows you to perform actions on a list of WebElements. The looping concept is encapsulated within the handling process. With this feature, we can search for specific elements and perform actions based on their attributes

Search opeartion on List of Webelement

In the above screenshot, there are 6 products. Using the XPath of the product title, we retrieve 6 WebElements: //*[contains(@id,'title_link')]. Now, assuming we have to search for a specific product name, where the product name is represented as text, we need to pass the text property in the value section. The text property will be identical to the product name, and the tool will internally execute the search action.

For the same example, let's suppose we want to search for an element based on another element's attribute, such as its id. we have to pass id attribute with its attribute value in the value section

Example 2 - Perform action on List of Webelement based on Index

Actions can be initiated directly based on the index. For example, if we pass the index as 0, it will perform the action on the first element. Similarly, we can pass the index according to our needs.

Example 2 - Perform action on List of Webelement based on element attribute

We can perform actions based on element attributes. For example, if we have a list of WebElements and we want to perform actions based on their text property, id, or href, we have to pass the corresponding attribute in the value section.

Perform action based on and or opeartion (and opeartion for mutiple attributes)

OR Opeartion

Just suppose we want to perform an action based on multiple element attributes. For example, if I want to click on an element either with class 'MyClass' or name 'Myname', then both attributes can be passed in the value section. Please note that by default, it works as an OR operation

And Opeartion

Just suppose we want to perform an action based on multiple element attributes. For example, if I want to click on an element that has both class 'myClass' and name 'myName', and only when both attributes match, then we need to pass an additional key 'andOperation' as true

Looping for Application Method and Test Step

In an application, a method associated with a label can be iterated using a loopCounter attribute from the value section; for example, in the Amazon application, if you wish to perform the 'Add to Cart' function ten times, you need to set the loopCounter to 10 in the value section

Key Name should be loopCounter

Data Iteration

If you want to iterate your method with test data, it is possible. For example, if your method takes two arguments and you want to execute the test script twice with two different data sets, you need to pass the arguments as an array list in the data key under methodParameters

Please note:

  1. Looping a custom function will not maintain page state. For example, if the page state changes from state A to state B within the function, it is necessary to handle this transition in our application logic so that after performing all steps, the page returns to state A

  2. The best way to use this method is where the page state does not change

Test Step label Example

Json Example

{
  "loopCounter": 2,
  "methodParameters": [
    {
      "valuetobesend": "UserA"
    },
    {
      "valuetobesend": "UserB"
    }
  ]
}

Please note:

In case we want to run the function with loopCounter, the method parameter should be passed under the args value."

{
  "ARGS.Username": {
    "methodParameters": "Session.LabelName"
  },
  "ARGS.Password": {
    "methodParameters": [
      "x",
      "y"
    ]
  },
  "loopCounter": "Session.TotalLength"
}

Function Overloading for Application Method

For example, I've just created a method for filling in a form, such as a login form. Let's call this method fillLoginDetails, which takes 2 arguments.

This method can be called with 1 argument or without any arguments. If no arguments are specified, such as for the username, no activity will occur for the associated web element.

If else Statement on Test Step label

We can now use the if-else expression in the test step label. By doing so, we can pass a list of step numbers that should be executed based on the outcome (pass or fail) of a particular step. For example, in test step 1, if the condition is true (pass), we run steps 2 and 3; if the condition is false (fail), we run steps 4 and 5. We need to pass the following structure in step number 1: {"ifTrue": [2, 3], "ifFalse": [4, 5]}.

Example

Value Example

{
  "ifFalse": [
    2,
    3
  ],
  "ifTrue": [
    4,
    5
  ]
}

Please Note

1. In the above example, if you want to perform only the true case, you can just pass {"ifTrue": [2, 3]}. So, if step number 1 passes, then steps 2 and 3 will be executed; otherwise, the steps will be skipped.

Please note : Conditional expression will not applicable for custom function directly , it will applicaable on test step label

Last updated