Leapwork makes desktop application automation an effortless task. However, following best practices is essential to avoid challenges while testing with multiple platforms and configurations. This article covers some of the basics of working with Desktop Automation.
In the following article, we'll present some best practices and solutions for tackling some key challenges inherent to Desktop Automation.
Some of the best practices that will be addressed in this article are listed below:
- How to handle synchronization
- How to tackle dynamically changing Desktop elements
- What to avoid while automating Desktops
- Handling common errors
- Handling scroll on Desktop window
How to handle synchronization?
Synchronization and timeouts govern the stability of our test cases but when it comes to desktop automation, they are also often the most challenging to get it right.
Leapwork has in-built features to handle synchronization and timeout challenges in any type of desktop test case scenario. The below fields are accessible via relevant building blocks in the Leapwork studio:
- Timeout in (secs): The maximum time spent searching for the desktop element before giving up and triggering “Not found”. This is an implicit timeout.
- Await no Change: When checked, the building block will wait for any changes happening on the screen within the specified timeout before performing the expand operation on the selected element.
How to tackle dynamically changing Desktop elements?
Leapwork allows the user to capture desktop elements manually or with a recorder. While capturing a single desktop element, Leapwork's smart algorithm intelligently generates multiple strategies for the same element, and by default picks the best-suited strategy for the task at hand.
In some cases, it’s been observed that the selected strategy works the first time, but stops working later on. This is a classic example of a dynamic element with a changing element property in the application's back-end.
Let's take the example below:
Leapwork picked a cart element by Id (in this case, the Id equals sq3r4t3422444adsesa) but that Id is dynamic in nature (i.e. the Id changes after release/deployment), so the next time the Id becomes sq974t67856785adsesa.
To handle such scenarios, Leapwork has a strategy editor that suggests all other locators in the left-hand-side panel. As a user, we can pick one of the most static strategies to make sure that the element is captured correctly every time.
The strategy editor also has its own editor interface (seen below on the right), where we can create our own unique and reliable strategies by choosing a Unique Id, XPATH, Custom Attribute, or Text.
For more information about how to use Leapwork's strategy editor, please follow the link below:
What to avoid while automating Desktops?
Leapwork provides multiple building blocks for desktop automation, to help to handle a variety of situations:
The following best practices must be followed while automating desktop applications:
- Avoid using the ‘Wait’ block: The Wait block will force a test to stop for a specific time. The Wait block also usually slows the test and increases the time of execution, so it’s advisable to avoid using this particular functionality in test automation.
- Strategies to be avoided: Avoid having text and image-based strategies on the desktop, as text-based strategies might fail if the language in the application is changed (g. English to Danish). Similarly, desktop tests are responsive in nature, which means the images and applications are subject to change with the resolution.
Handling Common Errors
Below are the four most common errors and how to resolve them:
- The UI Element not found in 10 seconds: If this error message appears, it could be due to a synchronization handling issue. Click here to look for steps to resolve this issue.
Handling the Scroll Function on Desktop Applications
By default, "Click UI Element" & "Set UI Element" automatically scroll to the element where it needs to perform click or type operations. However, there can be many scenarios where the user needs to perform a scroll without the need to click or type. In that kind of scenario, the user can choose one of two methods:
Scroll to find:
The Scroll to Find option can be found in all input blocks as a drop-down (see the picture below) and can be used to scroll up or down. This can be useful when searching in long-form content such as desktop application windows where elements are loaded asynchronously, e.g. using infinity scroll. Once we select one of the drop-down options, we will see three options that can be used as per our requirements:
- Max repeats: The maximum number of times to perform a scroll before giving up searching for the desktop element
- Amount: The amount of scrolling that will be performed on each scroll
- Delay (sec): The delay in seconds between each of the scroll amounts
With a combination of the above methods the user can easily handle all scroll up/down and scroll into view operations.
Finding images that move:
One situation that can occur for all types of applications is that an image is shown first in one place and is then moved to another. For example, on some applications, all resources are first loaded into the window and are then "boot-strapped" into position.
Another example could be a dialog box in a desktop application that is shown and then centered on the screen.
In both cases, Leapwork can find the image in the initial position and then continue the test flow. However, if the image changes position as part of the application, the automation flow will fail.
Checking the “Await no changes” property on the Desktop UI Building Block solves this problem. This will tell the image recognition engine to wait until the screen has not changed for a period of time before starting to search for the image.
For any clarification, please contact our Priority Support