本文整理汇总了Python中mozdevice.DeviceManagerADB.forward方法的典型用法代码示例。如果您正苦于以下问题:Python DeviceManagerADB.forward方法的具体用法?Python DeviceManagerADB.forward怎么用?Python DeviceManagerADB.forward使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mozdevice.DeviceManagerADB
的用法示例。
在下文中一共展示了DeviceManagerADB.forward方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_marionette_exists
# 需要导入模块: from mozdevice import DeviceManagerADB [as 别名]
# 或者: from mozdevice.DeviceManagerADB import forward [as 别名]
def check_marionette_exists(adb="adb"):
dm = DeviceManagerADB(adbPath=adb)
if dm.dirExists(INSTALL_DIR):
return True
else:
dm.forward("tcp:2828", "tcp:2828")
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('localhost', 2828))
data = sock.recv(16)
sock.close()
if 'root' in data:
return True
except socket.error:
return False
return False
示例2: TestRun
# 需要导入模块: from mozdevice import DeviceManagerADB [as 别名]
# 或者: from mozdevice.DeviceManagerADB import forward [as 别名]
#.........这里部分代码省略.........
entry = "%s_%s" % (self.app_name, self.attempt)
self.test_results[entry] = values
def launch_with_manifest(self, manifest):
self.m.switch_to_frame()
result = self.m.execute_async_script("GaiaApps.launchWithManifestURL('%s')" % manifest, script_timeout=30000)
if result == False:
raise Exception("launch timed out")
app = GaiaApp(frame=result.get('frame'),
src=result.get('src'),
name=result.get('name'),
origin=result.get('origin'))
if app.frame_id is None:
raise Exception("failed to launch; there is no app frame")
self.m.switch_to_frame(app.frame_id)
return app
def uninstall_with_manifest(self, manifest):
self.m.switch_to_frame()
script = """
GaiaApps.locateWithManifestURL('%s',
null,
function uninstall(app) {
navigator.mozApps.mgmt.uninstall(app);
marionetteScriptFinished(true);
});
"""
result = self.m.execute_async_script(script % manifest, script_timeout=60000)
if result != True:
self.add_result(status="Failed to uninstall app with url '%s'" % manifest)
return app
def forward_port(self):
# get unused port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('localhost', 0))
addr, port = s.getsockname()
s.close()
dm_tries = 0
self.run_log.info("using port %s" % port)
while dm_tries < 20:
if self.dm.forward("tcp:%d" % port, "tcp:2828") == 0:
break
dm_tries += 1
time.sleep(3)
else:
return False
self.port = port
return True
def restart_device(self, restart_tries=0):
self.run_log.info("rebooting")
# TODO restarting b2g doesn't seem to work... reboot then
while restart_tries < 3:
restart_tries += 1
self.dm.reboot(wait=True)
self.run_log.info("forwarding")
if not self.forward_port():
self.run_log.error("couldn't forward port in time, rebooting")
continue
self.m = Marionette(port=self.port)
if not self.m.wait_for_port(180):
self.run_log.error("couldn't contact marionette in time, rebooting")
continue