6 from browser_driver import BrowserDriver
9 _log = logging.getLogger(__name__)
12 class OSXBrowserDriver(BrowserDriver):
16 def prepare_env(self, device_id):
18 from Quartz import CGWarpMouseCursorPosition
19 CGWarpMouseCursorPosition((10, 0))
21 def restore_env(self):
24 def close_browsers(self):
25 self._terminate_processes(self.process_name)
28 def _launch_process(cls, build_dir, app_name, url, args):
30 build_dir = '/Applications/'
31 app_path = os.path.join(build_dir, app_name)
33 _log.info('Launching "%s" with url "%s"' % (app_path, url))
35 # FIXME: May need to be modified for a local build such as setting up DYLD libraries
36 args = ['open', '-a', app_path] + args
37 cls._launch_process_with_caffinate(args)
40 def _terminate_processes(cls, process_name):
41 _log.info('Closing all processes with name %s' % process_name)
42 subprocess.call(['/usr/bin/killall', process_name])
45 def _launch_process_with_caffinate(cls, args, env=None):
46 process = subprocess.Popen(args, env=env)
47 subprocess.Popen(["/usr/bin/caffeinate", "-disw", str(process.pid)])
51 def _screen_size(cls):
52 from AppKit import NSScreen
53 return NSScreen.mainScreen().frame().size