6 from AppKit import NSRunningApplication
7 from AppKit import NSScreen
8 from Quartz.CoreGraphics import CGEventCreateMouseEvent
9 from Quartz.CoreGraphics import CGEventPost
10 from Quartz.CoreGraphics import kCGEventMouseMoved
11 from Quartz.CoreGraphics import kCGHIDEventTap
12 from Quartz.CoreGraphics import kCGMouseButtonLeft
13 from browser_driver import BrowserDriver
16 _log = logging.getLogger(__name__)
19 class OSXBrowserDriver(BrowserDriver):
20 bundleIdentifier = None
26 def closeBrowsers(self):
27 self.terminateProcesses(self.bundleIdentifier)
30 def launchProcess(cls, buildDir, appName, url, args):
32 buildDir = '/Applications/'
33 appPath = os.path.join(buildDir, appName)
35 _log.info('Launching "%s" with url "%s"' % (appPath, url))
37 # FIXME: May need to be modified for a local build such as setting up DYLD libraries
38 args = ['open', '-a', appPath] + args
39 cls.launchProcessWithCaffinate(args)
42 def terminateProcesses(cls, bundleIdentifier):
43 _log.info('Closing all terminating all processes with the bundle identifier %s' % bundleIdentifier)
44 processes = NSRunningApplication.runningApplicationsWithBundleIdentifier_(bundleIdentifier)
45 for process in processes:
49 def launchProcessWithCaffinate(cls, args, env=None):
50 process = subprocess.Popen(args, env=env)
51 subprocess.Popen(["/usr/bin/caffeinate", "-disw", str(process.pid)])
55 def moveCursor(cls, x, y):
56 moveEvent = CGEventCreateMouseEvent(None, kCGEventMouseMoved, (x, y), kCGMouseButtonLeft)
57 CGEventPost(kCGHIDEventTap, moveEvent)
61 return NSScreen.mainScreen().frame().size