Reputation: 8175
I have a legacy Windows application which performs a critical business function. It has no API or official support for automation. This program requires a human to perform a sequence of actions in order to convert files in a particular input format into a PDF, from which we can scrape content and then process the data normally.
The business literally cannot function without some calculations/reports that this software performs, but unfortunately, those calculations are poorly understood and we don't have the kind of R&D budget that would allow us to re-implement the software.
The software reads in a proprietary file format and generates a number of PDF reports in an industry-approved format, from which we can scrape the images and deal with them in a more conventional way.
It has been proposed that we wrap up the application inside some kind of API, where I might submit some input data into a queue, and somewhere deep within this, we automate the software as if a human user was driving it to perform the operations.
Unfortunately, the operations are complex and depend on a number of inputs, and also the content of the file being processed. It's not the kind of thing that we could do with a simple macro - some logic will be required to model the behavior of a trained human operator.
So are there any solutions to this? We'd like to be able to drive the software as quickly as possible, and since we have many Python developers it makes sense to implement as much as possible in Python. The outer layers of this system will also be in Python, so that could cut out the complexity. Are there any tools which already provide the bulk of this kind of behavior?
Upvotes: 4
Views: 2666
Reputation: 21
Below is an example code using pywinauto. From my experience this solves a lot of issues, when we use any other tool, especially in the case of CI/CD.
from pywinauto.application import Application
def open_app(file_path = "notepad.exe"):
app = Application().start(file_path)
return app
def select_menu(app_object = app.UntitledNotepad, menu_item = "Help->About Notepad"):
app_object.menu_select(menu_item)
def click_item(app_object = app.AboutNotepad.OK):
app_object.click()
def type_in(app_object = app.UntitledNotepad.Edit., data = "pywinauto Works!"):
app_object.type_keys(data, with_spaces = True)
Upvotes: 1
Reputation: 3925
The easiest approach to automating an application is to send keystrokes to it. If you can drive the target application by keystrokes alone, operating it becomes manageable without needing to fight screen resolutions, large fonts and mouse positions. [1]
The harder part is recognizing the displayed state of the application. Ideally, you can read the content of the controls using Python [2], to at least detect error conditions and reset the program to a known good state. If resetting the program by conventional navigation fails, consider killing the target process and relaunch the process.
[1] How to send simulated keyboard strokes to the active window using SendKeys
[2] Problem when getting the content of a listbox with python and ctypes on win32
Upvotes: 4
Reputation: 2960
You have multiple options:
1. winshell: A light wrapper around the Windows shell functionality
2. Automa: Utilty to automate repetitive and/or complex task
3: PyAutoGUI is a Python module for programmatically controlling the
mouse and keyboard.
4. Sikuli automates anything you see on the screen http://www.sikuli.org/
5. pure Python scripting. example below:
import os os.system('notepad.exe')
import win32api
win32api.WinExec('notepad.exe')
import subprocess
subprocess.Popen(['notepad.exe'])
Upvotes: 3
Reputation: 19
Try out Robotic automation tools, which can mimic or record human interactions with computer and repeat over time. It can be made for handling more complex tasks using scripts depends on that software. Example selecting different inputs, browser components and also windows application.
Upvotes: 1