[KShare] Switching Desktop Windows 400x Faster using Custom Keyword 🚀

Forum thumbnail

Hi Community members, :wave:

Today, we are back with the last KShare article in our Desktop Testing series, where we will show you how to can achieve up to 400x faster speed and time for Switching Desktop Windows (**0,075 second is our current record) using Custom Keyword.

400x Faster :rocket:

The result above was recorded in the usual working condition, with the below specs:

  • OS: Windows 10 Pro
  • RAM: 16.0 GB
  • Opening the applications below
    • 2 Explorer windows
    • 5 Browser windows
    • 1 Katalon Studio window
    • 1 WinAppDriver window
    • 1 Notepad++ window
    • 1 AUT application window
    • 1 Eclipse IDE window

How does it work under the hood?

The old approach

In the old keyword, Katalon will search for all <window/> and <panel/> elements in the whole element tree of all opening windows on your desktop. The more complex the element tree is and the more applications running on the desktop, the more time it will take.

The new approach

But things will be easier if we only search in the top-level windows and not the whole element tree, right?

And yes, we have tried it, and it ran a lot faster (~10 seconds, 3x faster). Using Appium to find only the top-level windows with the locator "/window|/panel".

The fastest way to locate an application window

t can now run a lot faster, but can we make it even faster?

So, we start thinking about the fastest method to locate a window. And the name WinAPI just came into mind. It is a core framework that is available on all Windows machines today. Written in C/C++, results in excellent performance.

michael fassbender perfection GIF

Searching on the internet, we found these three WinAPI methods that could help us look for a desired window.

Implement some more logic. And voilà, we get the “400x faster-switching window keyword” that we have seen at the beginning of this article.

Title pattern matching & Other utilities

Another limitation of the old keyword is that it only supports searching for windows whose title contains some specific string. But not when we want to switch to some window with a more complex title pattern.

That is why we also developed some more keywords here that support finding windows with Regular Expressions or windows with title that exactly match a specific string.

 * Start single instance application
CustomKeywords.'WindowsImprovedKeywords.startSingleInstanceApplicationWithTitle'(appPath, 'Login Stage')
CustomKeywords.'WindowsImprovedKeywords.startSingleInstanceApplicationWithTitleContains'(appPath, 'Login')
CustomKeywords.'WindowsImprovedKeywords.startSingleInstanceApplicationWithTitlePattern'(appPath, 'Login Sta.*')

 * Start a new application
CustomKeywords.'WindowsImprovedKeywords.startApplicationWithTitle'(appPath, 'Login Stage')
CustomKeywords.'WindowsImprovedKeywords.startApplicationWithTitleContains'(appPath, 'Login')
CustomKeywords.'WindowsImprovedKeywords.startApplicationWithTitlePattern'(appPath, 'Login Sta.*')

 * Switch to the window with the title or Start an active application
CustomKeywords.'WindowsImprovedKeywords.switchToWindowWithTitle'('Login Stage')
CustomKeywords.'WindowsImprovedKeywords.switchToWindowWithTitlePattern'('Login Sta.*')

The Guideline for using the above keywords

  • “Start single-instance application with title…” keywords
    • Only keep one instance of the target application at a time.
    • If the application has been started, switch to that application window instead of starting a new instance.
  • “Start application with title…” keywords
    • Start a new instance of the target application and switch to the window with the desired title
  • “Switch to window with title…” keywords
    • Start the appium driver to the desktop context (Root) and switch to the window with the desired title
    • The tests will fail if the application has not been stated yet.

:information_source: You can find the sample project here, including the keywords for an exciting exploration.

If you find this article helpful, then don’t forget to leave us a like :+1: or a heart :heart: and share it with your colleagues and teammates.

:information_source: To see more KShare article, simply navigate to our Product Insights category.


Thank you very much the Product Support team (@support.squad), Linh Nguyen (@linh.nguyen) and Thong Tran (@thong.tran) for yet another informative article on Desktop Testing! :raised_hands:

Linh Nguyen Thong Tran
Linh Nguyen (@linh.nguyen) - Product Support Manager at Katalon Thong Tran (@thong.tran) - Senior Software Engineer at Katalon
Linh is the Product Support team Manager at Katalon. She spent many years working as an Automation Testing QA before joining Katalon Product Support as a technical support expert. Based on her experiences, she usually provides consumers with highly applicable solutions. She now manages her team with a user-centric approach to guarantee customers greater success with Katalon Products. A passionate Katalon developer with a wealth of programming and testing expertise. Thong has been dedicated to providing exceptional enterprise support for the past five years, helping Katalon’s customers achieve their testing goals with ease.