I am trying to write unit test for an application on Mac OS using python. There is one problem I encounter and have no idea how to do it. I want the testing program to check if the application is running by checking process and I also want to check if a message box is displayed. In addition, I hope testing program can automatically click button on message box. Could anyone give me some suggestions?
2 Answers
Here's one way to do it with 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 for some variations.
Comments
Check out psutil for inspecting various parts of the host system. With this python library you can inspect which processes are running.
As far as interacting with OS X itself, this thread has some nice information about controlling the mouse and keyboard using PyObjC
1 Comment
Robin W.
Thanks for your advice. After digging some time, I found using apple script in Python is easiest approach.