6 from AppKit import NSRunningApplication
7 from AppKit import NSScreen
8 from Quartz import CGWarpMouseCursorPosition
9 from browser_driver import BrowserDriver
12 _log = logging.getLogger(__name__)
15 class OSXBrowserDriver(BrowserDriver):
16 bundleIdentifier = None
18 def prepareEnv(self, deviceID):
20 CGWarpMouseCursorPosition((10, 0))
22 def closeBrowsers(self):
23 self.terminateProcesses(self.bundleIdentifier)
26 def launchProcess(cls, buildDir, appName, url, args):
28 buildDir = '/Applications/'
29 appPath = os.path.join(buildDir, appName)
31 _log.info('Launching "%s" with url "%s"' % (appPath, url))
33 # FIXME: May need to be modified for a local build such as setting up DYLD libraries
34 args = ['open', '-a', appPath] + args
35 cls.launchProcessWithCaffinate(args)
38 def terminateProcesses(cls, bundleIdentifier):
39 _log.info('Closing all terminating all processes with the bundle identifier %s' % bundleIdentifier)
40 processes = NSRunningApplication.runningApplicationsWithBundleIdentifier_(bundleIdentifier)
41 for process in processes:
45 def launchProcessWithCaffinate(cls, args, env=None):
46 process = subprocess.Popen(args, env=env)
47 subprocess.Popen(["/usr/bin/caffeinate", "-disw", str(process.pid)])
52 return NSScreen.mainScreen().frame().size