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?

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

Thanks for your advice. After digging some time, I found using apple script in Python is easiest approach.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.