5

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?

Robin W.
  • 361
  • 1
  • 3
  • 14

2 Answers2

4

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.

Hugo
  • 27,885
  • 8
  • 82
  • 98
0

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

Community
  • 1
  • 1
Matt Sweeney
  • 2,060
  • 1
  • 14
  • 19
  • Thanks for your advice. After digging some time, I found using apple script in Python is easiest approach. – Robin W. Feb 24 '13 at 12:13