blank Skip to main content

How to Automate GUI Testing of Windows Apps with Pywinauto: Expert Advice

Want more posts like this?

Sign up for our updates.

Graphical user interface testing is an essential part of quality assurance testing as it lets you look at your application from the user’s perspective. In this article, we’ll discuss how to automate desktop application GUI testing using Python and Pywinauto. This article will be helpful for quality assurance specialists who are looking for tools to automate Windows GUI testing.

Graphical user interface testing is aimed at ensuring that the graphical user interface (GUI) meets specifications. User interface (UI) testing covers the user’s interactions with the application through a command line or graphical controls. During GUI testing, a quality assurance (QA) specialist tests the functionality of the application through its graphical controls (icons, text fields, buttons) and evaluates the controls. This type of testing can be both manual and automated. Windows GUI testing automation using Python emulates a user’s interaction with the GUI using automation tools.

According to Mike Cohn’s book Succeeding with Agile, UI testing is at the top of the test automation pyramid:

Automation testing pyramid

This means that UI tests should take less time and effort in comparison with unit and service tests. While unit and service tests are more isolated, they uncover application bugs at the early stages of software development. In contrast, UI tests can be conducted only at the latest stages of the development lifecycle.

The main advantage of GUI testing automation with Python is that it looks at the application under test from the user’s perspective. In this way, desktop application testing automation using Python complements unit tests and service or API tests.


Installing pywinauto

Steps of GUI test automation with Pywinauto

  Running the application under test

  Windows Specification


  Waiting for long-running operations

Checking the GUI test automation results


Installing pywinauto

Pywinauto is a set of libraries for Windows GUI testing automation with Python.

You can install the Pywinauto package by running a standard pip command:

pip install pywinauto

Note that installing the 64-bit version requires running the 64-bit Python interpreter:

C:pathtopython_64bit.exe -m pip install pywinauto

Pywinauto supports the following Windows GUI technologies:

  • Win32 controls through the Win32 API: MFC, VB6, VCL
  • MS UI Automation: WinForms, WPF, Qt5, browsers, store apps

However, it doesn’t support Tkinter, Java AWT/Swing, or GTK+.

GUI tests take the form of Python scripts that consist of Pywinauto library methods, which emulate user actions like mouse clicks/movements and keyboard key presses.

These Python GUI testing automation libraries provide an important benefit of accessing the GUI control elements with the help of attributes. For instance:


Here, we use the full stop to access the Save button that’s located in the Save As dialog window and call the click method.

Related services:

Specialized Quality Assurance & Testing Solutions

Steps of GUI test automation with Pywinauto

There are five main steps of writing a GUI test with Pywinauto:

  1. Run an application or access a running one.
  2. Define the main application window.
  3. Find the necessary control element (button, text field, drop-down list, etc.).
  4. Perform a user action on the control element (click on the button, enter text, etc.).
  5. Check the results.

Let’s automate Windows GUI application testing using Python and Pywinauto. Here are the main steps of of editing and saving a Notepad file:

  1. Open a text file in Notepad.
  2. Enter a text and apply formatting to it: for instance, Comic Sans, bold, size 18.
  3. Save the file in PDF format with the following settings: landscape orientation, paper size A3.
  4. Check if the PDF file was saved.

Below, we provide a guide for executing this test with pywinauto.

Read also:
GUI Testing: Basic tips

Running the application under test

To call the main Notepad window and its control elements, we need to run the application and create a new text file in it. The Notepad file is initialized in the following way:

# Import pywinauto Application class
from pywinauto.application import Application
# Start a new process and specify a path to the text file
app = Application().start('notepad.exe', timeout=10)

In this example, pywinauto runs notepad.exe and opens a new file with a 10-second timeout. This way, we can make the testing process a bit smoother, as the application under test can display its windows and GUI elements with a certain delay. By default, pywinauto looks for an open dialog window and control elements during a certain period of time (approximately 5 seconds) and repeats the search if it fails.

There are also several alternative ways of accessing an application that’s already running. You can specify the process ID (PID), path to the executable, or regular expression for window name identification.

# Connect to already running process:
# By PID
app = Application(backend="uia").connect(process=1234)
# By path to executable
app = Application(backend="uia").connect(path=r"C:WindowsSystem32Notepad.exe")
# By regular expression
app = Application(backend="uia").connect(title_re=".*Notepad*")

The name of the window or control element can be specified with a regular expression or a name written without spaces or other breaking symbols. Pywinauto will automatically search for the element that most closely matches the name among all opened windows.

Windows Specification

To access control elements, you need to let Pywinauto define the application window with these elements. In our case, it’s the Notepad window.

Windows Specification is an object that describes either the application window or the control element. In our scenario, the window can be specified in the following way:

# Main window specification
main_dlg = app.UntitledNotepad

Alternatively, you can describe the window with a regular expression of the title, or specify a particular name:

main_dlg = app.window(title='Untitled - Notepad')


Pywinauto supports the most common GUI control elements, including:

  • Button
  • CheckBox
  • RadioButton
  • GroupBox
  • ComboBox
  • Edit
  • Header
  • ListBox
  • ListView
  • PopupMenu
  • Static
  • StatusBar
  • TabControl
  • Toolbar
  • ToolTips
  • TreeView
  • UpDown

In order to display all available control elements for a specified window, you need to call the print_control_identifiers method:

# Print all controls on the dialog

This method allows you to see which control elements pywinauto has access to and which of those controls need further desktop automation using Python.

You can call the control as an attribute of the window where the control is placed. A user action is applied to the element by calling the method.

In our case, after running notepad.exe, we should enter any text and apply formatting to it.

Enter text in the open document:

main_dlg.Edit.type_keys("Hello pywinauto!nt It’s a sample text^A",

As a result, we’ll get entered text and indentation (due to the ^A command):

Notepad file GUI testing with pywinauto

Now we’ll open the Font dialog window and edit the text font:

font_menu = main_dlg.menu_select('Format->Font...')
font_dlg = app.Font
font_type = font_dlg.ComboBox'Comic Sans MS')
font_style = font_dlg.ComboBox2'Bold')
font_size = font_dlg.ComboBox3

Here, we used access to the following controls: the main window menu, ComboBox, and Button:

Font testing with pywinauton

Now, we need to save the file in PDF format with landscape orientation and A3 paper size.

To do so, select a virtual printer through the Notepad menu:

{code}# Select Print menu item. Wait for the dialog to appear
print_menu_item = main_dlg.menu_select('File->Print...')
print_dlg = app.Print
# Select PDF printer
button = print_dlg.GroupBox
syslistview = print_dlg.ListView
listview_item = syslistview.get_item('Microsoft Print to PDF')

Then specify the document settings: landscape orientation, paper size A3:

# Open print preference
preference =
print_pref_dlg = app.window(title='Printing Preferences')
# Set landscape'Landscape')
#Open advanced settings
adv_dlg = app.window(title='Microsoft Print To PDF Advanced Options')
# Select A3 size and save
paper_size = adv_dlg['2', 'ComboBox']'A3')

Executing the script makes the following dialog windows open sequentially:

Print, PrintingPreference, and Microsoft Print to PDF Advanced Options.

There’s one peculiarity about the way Notepad runs processes and opens dialog windows: If we start Notepad in the 64-bit version of Windows with the help of the 32-bit Python interpreter and pywinauto, then notepad.exe is WoW64, or a 32-bit process, while the Print dialog window is a separate 64-bit process called splwow64.exe. This means that we can’t call the Print process from notepad.exe, but we can access it through a separate invocation by the process name or its PID.

However, we can call the dialog window from notepad.exe if we’re working on 32-bit Windows or run notepad.exe on 64-bit Windows through the 64-bit Python interpreter.

This peculiarity also relates to other applications where dialog windows are implemented in a similar way.

GUI testing of Notepad paper size settings

Finally, save the document and close Notepad:

# Save the file
save_dlg = app.window(title='Save Print Output As')
file_path = 'C:Testtxt_to_pdf.pdf'
file_name_field = save_dlg['5']
# Clear the text and close Notepad

Waiting for long-running operations

When you conduct GUI testing, you often have to wait for certain events to complete, such as file loading, window rendering, and switching between windows.

In these cases, pywinauto can wait for an event or you can set a timeout:

# Open a large file
# Wait for the dialog to become invisible
# Wait for up to 10 seconds until Report.txt is loaded
app.window(title='Report.txt - Notepad').wait('ready', timeout=10)

Checking the GUI test automation results

You can also automate checking of the GUI test results depending on what is under the test. In our case, we can check the existence of the PDF file on the disk with standard Python methods, for instance, by calling os.path.exists.

Read also:
Windows Driver Testing Basics: Tools, Features, and Examples


Pywinauto Windows GUI automation can be a helpful addition to unit tests and API tests. However, when choosing automation tools, pay attention to their capabilities and usability features. Windows GUI automation with Python and Pywinauto is quite easy. Pywinauto covers a huge number of Windows GUI technologies while providing easy access to graphical elements of tested applications.

Apriorit has a team of dedicated quality assurance testers whose qualifications are confirmed with ISTQB certification. Contact us if you want to launch bug-free software.

Tell us about your project

Send us a request for proposal! We’ll get back to you with details and estimations.

By clicking Send you give consent to processing your data

Book an Exploratory Call

Do not have any specific task for us in mind but our skills seem interesting?

Get a quick Apriorit intro to better understand our team capabilities.

Book time slot

Contact us