Solution To Common Test Automation Problems – Using Katalon Studio
The advancements in web development technologies make web-based applications more feature-rich, hence it becomes more challenging to automate your web testing. Web technology features like multi-platform support, cross-browser, responsive design could add more challenges and require more effort to implement your Web UI test automation strategies. So if you’re a beginner and starting with web UI test automation, here are some examples on how to handle common automation problems that may help applying your test automation more effective.
Common challenges of (web) UI test automation
- Wait-time issues
- Iframe issues
- Pop-up issues in automation
- Issues in locating deeply nested elements
Wait-time issue and suggested solution
What is Wait?
A Wait is a tactic used in test automation scripts to create a pause in-between script steps as you wait for web elements to load or for an application to respond.
If there is no wait or a short wait between steps and the target web application needs longer time to load its elements, then the test will fail. This failure is due to the script rather than an error in the target application. And this failure is called false failure, and it should be avoided in the test script.
These are some common examples of what can cause a false failure:
- False Fail: One of the biggest failures we see is when a script fails “false fail” due to waiting on the application. It is often caused by network latency, database requests, or simply the system needs more time to process and response to the request.
- Targeted element not present on the page: This kind of failure occurs while waiting for elements to be displayed OR render in the browser. The application may be up and running but certain elements may not be loaded yet makes your test script failed.
How to address these failures related to Wait?
Instead of adding random 5-10 second waits for each step, you can try one of the following options:
- Global variable – A global variable is a variable that has the global scope, meaning that it is visible throughout the program. You may consider defining 3 kind of global variables in your test scripts, with each for a short wait, a medium wait and a long wait. Use these variables in your test scripts according to the response time of your web application.
- Wait For Page Load – This logic will wait for a page to completely load before running a step in your script.
- Wait For Element Present – It happens sometimes that web elements take longer time to appear on the page when you are navigating through pages or clicking on buttons or doing something else. The “WaitForElementPresent” command will pause Selenium until the targeted element appears on the page. Once element appears, Selenium continues to execute the next command.
Figure 1: Katalon Studio test script
This script shows the usage of a global variable and Katalon Studio built-in keywords.
Iframe issue and suggested solution
What is iframe?
An iframe (Inline Frame) is an HTML document embedded in another HTML document. The iframe HTML element is often used to insert the content from another source, such as an advertisement, into a Web page.
Why is it important to know how to test iframes?
Verifying text and objects within iframes can be a challenge. Even though you (as a human tester) can see text displayed in an iframe, automation tools may not be able to detect the text. You have to tell your script how to traverse a website’s iframes and select the correct Iframe where the text and its object are present.
- An iframe on the Katalon Forum’s webpage
Figure 2: Detecting iframe on the Katalon Forum’s webpage
You can see that Katalon Object Spy selects the iframe in the red highlighted area.
Figure 3: Katalon Object Spy
Katalon Object Spy detects, captures the Comment iframe (Figure 2) and shows its elements in Figure 3.
- JQueryUI’s Drag and Drop example:
Figure 4: JQueryUI’s Drag and Drop iframe area selection
You can drag the ‘Drag me around’ object to other areas on the iframe.
Figure 5: Katalon Studio Object spy
Katalon Object Spy detects and captures the iframe (Figure 4) and shows its elements in Figure 5.
A suggested solution for testing Iframes using Katalon Studio:
Below are a few tips on interacting with the drag and drop object in an Iframe using Katalon Studio.
Figure 6: Katalon Studio generated test script from record and playback function.
The test script generated above is meant for the drag-drop function. Katalon Studio allows you to edit your verification steps in-between the script to verify a particular object in iframe.
Pop-up issues and suggested solution
What is pop-up?
A pop-up is a graphical user interface (GUI) display area, usually a small window that appears (“pop-up”) in the foreground of the visual interface.
Issue with pop-up?
As a human, you have the ability to react to actions that occur during your testing, such as a pop-up window unexpectedly occurring. But as code that a coder has written, you can only do what your coder has told you to do and that limits your ability to react to the unexpected behaviors, such as a pop-up.
Below are a few commonly used pop-ups which might cause problems in your test web automation:
- New browser window.
- Alert: An alert box is often used to make sure that information comes through to the user.
- Custom modal dialog: A modal dialog is a dialog box/pop-up window that is displayed on top of the current page.
- Native pop-up dialog.
Suggested solution for handling Pop-up with Katalon Studio:
Below are a few tips for handling the pop-up issue using Katalon Studio.
Figure 7: Katalon Studio test script
Test script generated above showing the usage of Katalon Studio built-in keywords.
Ex: switchToWindowTitle built-in keyword helps you to handle the pop-up issue.
XPath nesting issue and suggested solution
What is XPath?
An XPath expression is a mechanism for navigating through and selecting a node in the XML document or it can be used to locate HTML elements. Here is an example of a nested element:
Download link in the script below.
<div class="navbar-collapse navbar-right" aria-expanded="true">
<ul class="nav navbar-nav">
<a class="pbtn-download" href="#katalon-download">Download</a> <!-- Deeply nested element -->
It’s difficult to identify a deeply nested element, such as the ‘<a>’ element in the script above. You may find it difficult to write the XPath manually if you don’t have solid XPath knowledge in order to access that particular ‘<a>’ element.
How to identify nested elements easily?
- Use XPath: using XPath is an effective way to find elements if they can’t be identified by ID, Name, or another attribute AND when they are deeply nested. However manually identifying the path is difficult if not using a right tool.
- Use Katalon Studio: Katalon Studio can generate and optimize XPaths for HTML elements, regardless how deeply nested they are. You can use these XPaths to identify elements and you don’t need to search through the DOM tree.
Figure 8: Katalon Object Spy
Katalon Studio generates and optimizes an XPath automatically when you spy on the “Sign up now” object as shown above.
While automating your web testing can be difficult, we hope that the solutions suggested in this article may help you to handle the common test automation problems in web test automation and bring value to your test automation.
“If an end user perceives bad performance from your website, her next click will likely be on your-competition.com.”? Ian Molyneaux