DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Playwright: Test Automation You Must Know
  • Exploring the Purpose of Pytest Fixtures: A Practical Guide
  • Playwright and Chrome Browser Testing in Heroku
  • Maximizing Efficiency With the Test Automation Pyramid: Leveraging API Tests for Optimal Results

Trending

  • It’s Not About Control — It’s About Collaboration Between Architecture and Security
  • Customer 360: Fraud Detection in Fintech With PySpark and ML
  • Teradata Performance and Skew Prevention Tips
  • Beyond Linguistics: Real-Time Domain Event Mapping with WebSocket and Spring Boot
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Testing, Tools, and Frameworks
  4. Windows Apps GUI Test Automation Using PyWinAuto

Windows Apps GUI Test Automation Using PyWinAuto

In this article, we will understand how to create a test automation script for Windows application using simple Python Scripting.

By 
Srilakshmi Srinadhuni user avatar
Srilakshmi Srinadhuni
·
Jun. 15, 20 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
27.1K Views

Join the DZone community and get the full member experience.

Join For Free

Overview

In this article, we will understand how to create test automation script for Windows application using simple Python Scripting. We will walk through a scenario of automating a desktop application using PyWinAuto.

Scenario

Amy is an automation tester working XYZ project. Amy has knowledge in basic python scripting and frameworks. Amy is looking for opensource tool based on python to automate desktop applications.

Amy needs help in accomplishing the test automation of windows desktop applications using PyWinAuto.

Scenario Solution

Before we start helping Amy in completing her task of automating the desktop applications, let us try to deep dive and understand important concepts of the tool PyAutoWin.

What Is PyWinAuto?

PyWinAuto is combination of few python modules to automate Windows based GUI applications. This allows to interact with Windows apps using Mouse and Keyboard actions.

PyWinAuto supports the following Windows technologies:

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

Installation of PyWinAuto

We can install PyWinAuto using the Pip install command. Let us navigate to command Prompt and execute the pip install below command :
pip install -U pywinauto --user

pip install -U pywinauto --user


In order to check the version, use the command:

print(pywinauto.__version__)

print(pywinauto.__version__)

Steps to Be Followed

Steps by step process of automating desktop application using pywinauto:

Step 1: You can use either Python IDLE as an IDE or Eclipse as an IDE by adding the Pydev Plugin.

Step 2: Run the application which you want to automate

Step 3: Define the main application window

Step 4: Inspect the necessary GUI control elements ( Text fields , drop-down list, buttons etc.)

Step 5: Perform the relevant action on that GUI control element

Step 6: Analyze the results

Demo 1

Let us see the demo of sample desktop application i.e. opening a notepad, writing content and further saving the notepad.

Let us follow the step by step process using a demo. The sample application we are using here is Notepad.

Step 1: In this demo , we have used Python IDLE as IDE to write the program

Step 2: Launching the notepad application using the below command

notepad application command

Step 3: Define the main application window

main application window

Step 4: Inspect the necessary GUI control elements ( Textfields,drop-down list, buttons etc.)

Pywinauto supports the most common GUI control elements and in order to display all available control elements for a specified window, we need to call the print_control_identifiers method.

print_control_identifiers

Step 5: Perform the relevant action on that GUI control element

Upon executing the above command, the following control identifiers are displayed

Now let us perform some action i.e write content in the notepad and save it.

save content

Save the notepad file with name

save_win

Demo 2

Let us create program on a different windows application i.e Calculator and let us use Eclipse IDE for this scenario.

Step 1: In this demo , we have used Eclipse as IDE to write the program

Step 2: Install Pydev plugin in Eclipse. In Eclipse Navigate to Help -> Marketplace-> search for Pydev

Step 3: Click on install button

PyDev

Step 4: After installing Pydev Plugin , we can start writing python programs in Eclipse IDE.

Step 5: As we have already installed PyAutoWin, the python module imports the required libraries. Below is the python script to invoke calculator application and perform addition operation on it.

@author

Finding Elements With Pywinauto

In order to inspect elements, we can either use Inspect tool or UISpy tool. In this above demo we have used the control identifiers provided by PyAutoWin built-in function.

Pywinauto offers a function called "print_control_identifiers". This will print all the information about the object that we wish to "inspect".

Below is the snapshot of the control identifiers:

control identifiers

Attributes Within Application

There are many Attributes available which can be used to inspect the different objects within the application.

Few of them are listed below:

  • class_name: Elements with this window class
  • class_name_re: Elements whose class matches this regular expression
  • parent: Elements that are children of this
  • process: Elements running in this process
  • title: Elements with this text
  • title_re: Elements whose text matches this regular expression
  • top_level_only: Top level elements only (default=**True**)
  • visible_only: Visible elements only (default=**True**)
  • enabled_only: Enabled elements only (default=False)
  • best_match: Elements with a title similar to this
  • handle: The handle of the element to return
  • ctrl_index: The index of the child element to return
  • found_index: The index of the filtered-out child element to return
  • predicate_func: A user provided hook for a custom element validation
  • active_only: Active elements only (default=False)
  • control_id: Elements with this control id
  • control_type: Elements with this control type (string; for UIAutomation elements)
  • auto_id: Elements with this automation id (for UIAutomation elements)
  • framework_id: Elements with this framework id (for UIAutomation elements)
  • backend: Back-end name to use while searching (default=None means current active backend)

Conclusion

PyWinAuto which is a set of python modules can be used to automate the Microsoft Windows GUI. This also allows users to send Mouse and keyboard actions to windows dialogs.

PyWinAuto can be considered as one of the good choices when it comes to opensource tools for Windows desktop applications.

Test automation Element application app Testing Python (language)

Opinions expressed by DZone contributors are their own.

Related

  • Playwright: Test Automation You Must Know
  • Exploring the Purpose of Pytest Fixtures: A Practical Guide
  • Playwright and Chrome Browser Testing in Heroku
  • Maximizing Efficiency With the Test Automation Pyramid: Leveraging API Tests for Optimal Results

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!