How to use python to determine if an application is running and whether a message box is displayed in the MAC OS

I am trying to write unit test for an application on Mac OS using python. There is one problem that I am facing and have no idea how to do this. I want the testing program to check if the application is running by checking the process, and I also want to check if the message box is displayed. In addition, I hope that the testing program can automatically click a button in the message box. Can someone give me some suggestions?

+4
source share
2 answers

Check psutil to check for different parts of the host system. With this python library you can check which processes are running.

As for interacting with OS X itself, this thread contains some nice information about mouse and keyboard controls using PyObjC

0
source

Here is one way to do this using AppleScript:

import subprocess def is_runnning(app): count = int(subprocess.check_output(["osascript", "-e", "tell application \"System Events\"", "-e", "count (every process whose name is \"" + app + "\")", "-e", "end tell"]).strip()) return count > 0 print is_runnning("iTunes") 

See also this one for some options.

0
source

All Articles