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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With