Creating Automated UI Tests for QGIS Using AutoIt

Introduction:

Testing is a crucial part of software development, but it can be a tedious task. AutoIt is a scripting language designed for automating the Windows GUI and general scripting. In this article, we will explore how to use AutoIt to test GUIs with minimal manual input. AutoIt has been around for 20 years and offers a powerful yet simple approach to GUI testing. We will walk you through the basic ideas of AutoIt, including windows, shortcuts, passing values, and navigation. We will also provide a quick example of how to use AutoIt for a smoke test after an installation on a client. Overall, AutoIt is a useful tool for automating GUI testing and improving the efficiency of your software development process.

Full Article: Creating Automated UI Tests for QGIS Using AutoIt

AutoIt: Simplifying GUI Testing with Automation

Testing software solutions is a crucial step in ensuring their quality and performance. However, it can often be a tedious and time-consuming process. When it comes to testing graphical user interfaces (GUIs), manual input is often required. But what if there was a way to minimize manual input and automate the testing process? That’s where AutoIt comes in.

Introducing AutoIt

AutoIt editor

Recently, I came across AutoIt while reading an article about test automation in the iX magazine. The article mentioned that the German insurance company, CosmosDirect, had used AutoIt in an IT project. Intrigued by its capabilities, I decided to explore what AutoIt had to offer.

AutoIt v3 is a freeware BASIC-like scripting language designed for automating the Windows GUI and general scripting. It uses a combination of simulated keystrokes, mouse movement and window/control manipulation in order to automate tasks in a way not possible or reliable with other languages.

autoitscript.com

Understanding AutoIt: The Basics

Before diving into the details of AutoIt, it’s important to grasp the basic concepts it employs:

  • Windows: AutoIt allows you to interact with various windows and controls within them.
  • Shortcuts: You can simulate keyboard shortcuts to navigate through the GUI.
  • Passing values: AutoIt enables you to pass values to input fields and controls.
  • Navigation: With AutoIt, you can easily navigate through different windows and controls.

The underlying principle of using AutoIt can be compared to operating a software application without a mouse. There are multiple approaches to automated testing, such as using identifiers or image recognition. However, AutoIt provides a simple yet powerful solution that closely resembles manual testing. Remarkably, AutoIt has been around for more than 20 years.

When using AutoIt for automated test runs, you must write test scripts. These scripts can be executed directly from the editor or compiled into an executable file (AutoIt only runs on Windows).

AutoIt in Action: A Quick Example

To demonstrate the capabilities of AutoIt, let’s consider a smoke test scenario after installing a client application:

  • Open the latest stable executable.
  • Maximize the window to full screen.
  • Create a new geopackage point layer.
  • Start an edit session.
  • Create a point and add attributes.
  • Save the layer.
  • Quit the application.

In this example, the AutoIt script utilizes the “Send” command to navigate through the GUI using keyboard shortcuts like “TAB,” “DOWN_KEY,” and “ENTER.” The script includes variables for the username and the QGIS window. The entire test run takes only 13 seconds to execute, effectively covering the basic functionality. It can be easily expanded to incorporate additional features, such as using Grass or Python tools.

#include <AutoItConstants.au3> ; This library is required for mouse clicks

Run("C:Program FilesQGIS 3.4binqgis-ltr-bin-g7.exe") ; Start the program
Local $qgis = WinWaitActive("Unbenanntes Projekt - QGIS")
WinSetState ($qgis, "", @SW_MAXIMIZE) ; Maximize the working window
Send("^+n"); Use Ctrl+Shift+N to create a new geopackage layer
WinWaitActive("Neuer GeoPackage-Layer") ; Wait for the window to appear
Send("{TAB 3}") ; Press the DEL key 3 times
; Handle the navigation for creating a geopackage layer
Send("Test_Table") ;
Send("{TAB}")
Send("{DOWN}")
Send("{TAB 4}")
Send("Name") ;
Send("{TAB 2}")
Send("255")
Send("{TAB}")
Send("{SPACE}")
Send("{TAB}")
Send("C:Users" &amp; @UserName &amp; "DocumentsGIS DataBasetest")
Send("{ENTER}")
; The layer should be ready now
WinWaitActive($qgis)
Send("!l") ; Switch to the Layer menu using ALT+L
Send("{DOWN 8}")
Send("{ENTER}"); Open edit mode
Send("^."); Create a new point
WinWaitActive($qgis)
MouseClick($MOUSE_CLICK_LEFT, 559, 411, 1) ; Create a point on the map pane at a specific location
WinWaitActive("Test_Table - Objektattribute")
Send("{TAB}"); We don't set a fid
Send("This is my name")
Send("{ENTER}"); Close the attribute entry window
WinWaitActive($qgis)
Send("!l") ; Switch to the Layer menu using ALT+L
Send("{DOWN 8}")
Send("{ENTER}"); Close edit mode
WinWaitActive("Bearbeitung beenden")
Send("{ENTER}") ; Save edits
WinWaitActive($qgis)
WinClose($qgis)
WinWaitActive("Projekt speichern")
Send("{TAB 1}")
Send("{SPACE}")

Verifying the Results

As with any testing program, running the AutoIt script without any errors (exit code of 0) indicates a successful test. However, it’s also important to verify the desired outcome. In our case, we want to check if a new file has been created at the designated location. Here’s a function that can be used to achieve this:

#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>

FileChecker()

Func FileChecker()
    Local $filePath = "C:Users" &amp; @UserName &amp; "DocumentsGIS DataBasetest.gpkg"
    Local $iFileExists = FileExists($filePath)
    ; Display a message indicating whether the file exists or not
    If $iFileExists Then
        MsgBox($MB_SYSTEMMODAL, "", "The file exists." &amp; @CRLF &amp; "FileExist returned: " &amp; $iFileExists)
    Else
        MsgBox($MB_SYSTEMMODAL, "", "The file doesn't exist." &amp; @CRLF &amp; "FileExist returned: " &amp; $iFileExists)
    EndIf
    ; Delete the file:
    FileDelete($filePath)
EndFunc

The complete file can be found as a gist on GitHub.

AutoIt has an extensive online documentation and an active forum community. So, if you’re interested in exploring more about AutoIt and its capabilities, don’t hesitate to dive in. Happy coding!

Summary: Creating Automated UI Tests for QGIS Using AutoIt

Testing software solutions is crucial, but it can be a tedious process. AutoIt is a freeware scripting language that automates Windows GUI and general scripting. It simulates keystrokes, mouse movement, and window/control manipulation to automate tasks. This article explains the basic concepts of AutoIt and provides an example of using AutoIt for testing QGIS. AutoIt is an effective tool for automating software testing processes.




Frequently Asked Questions – Automated UI tests with AutoIt for QGIS

Automated UI tests with AutoIt for QGIS

Frequently Asked Questions

1. What are automated UI tests?

Automated UI tests refer to the process of automating user interface interactions to validate the functionality and performance of software applications.

2. Why use AutoIt for automated UI tests in QGIS?

AutoIt is a scripting language that allows automation of repetitive tasks and controls external applications. It is commonly used for UI testing as it supports simulating user actions, handling windows and controls, and capturing data from application interfaces.

3. How do I install AutoIt for QGIS?

To install AutoIt for QGIS, follow these steps:

  1. Download the AutoIt installer from the official website
  2. Run the installer and follow the on-screen instructions
  3. Once installed, make sure AutoIt is added in the system PATH environment variable

4. Can AutoIt be used for cross-platform UI testing?

No, AutoIt is primarily designed for Windows-based environments and cannot be used for cross-platform UI testing. It relies on native Windows controls and functions.

5. How can I write automated UI tests with AutoIt for QGIS?

To write automated UI tests with AutoIt for QGIS, follow these steps:

  1. Identify the specific actions and interactions you want to automate
  2. Use the AutoIt Window Info tool to inspect the target application’s controls and properties
  3. Write AutoIt scripts to simulate the desired user actions and verify expected outcomes
  4. Execute the scripts using AutoIt’s command-line interface or integrate them into a test automation framework

6. Are there any alternatives to AutoIt for automated UI testing in QGIS?

Yes, there are several alternative tools/frameworks available for UI testing in QGIS, such as Selenium WebDriver, Appium, and Sikuli. These tools provide cross-platform support and offer different features for UI automation.

7. Can AutoIt scripts be used for load testing or performance testing?

No, AutoIt is primarily focused on UI automation and is not suitable for load testing or performance testing. There are specialized tools available, like JMeter or Gatling, that are more suitable for these types of tests.

8. How can I handle unexpected pop-up windows during automated UI testing with AutoIt?

To handle unexpected pop-up windows during automated UI testing with AutoIt, you can use the WinWait or WinExists functions to detect the presence of the window and the WinActivate or ControlClick functions to interact with it programmatically.

9. Are there any best practices for writing maintainable AutoIt scripts for UI tests?

Some best practices for writing maintainable AutoIt scripts for UI tests include:

  • Using descriptive variable names
  • Adding comments to explain complex logic or actions
  • Separating test data from the script logic
  • Creating reusable functions for common actions
  • Using version control to track changes and collaborate with a team

10. Where can I find additional resources and tutorials for automated UI testing with AutoIt in QGIS?

For additional resources and tutorials on automated UI testing with AutoIt in QGIS, you can refer to the official AutoIt website, the QGIS documentation, and various online forums and communities dedicated to UI testing and automation.