本文整理汇总了Python中emulator.Emulator.setup方法的典型用法代码示例。如果您正苦于以下问题:Python Emulator.setup方法的具体用法?Python Emulator.setup怎么用?Python Emulator.setup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类emulator.Emulator
的用法示例。
在下文中一共展示了Emulator.setup方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Marionette
# 需要导入模块: from emulator import Emulator [as 别名]
# 或者: from emulator.Emulator import setup [as 别名]
class Marionette(object):
"""
Represents a Marionette connection to a browser or device.
"""
CONTEXT_CHROME = 'chrome' # non-browser content: windows, dialogs, etc.
CONTEXT_CONTENT = 'content' # browser content: iframes, divs, etc.
TIMEOUT_SEARCH = 'implicit'
TIMEOUT_SCRIPT = 'script'
TIMEOUT_PAGE = 'page load'
def __init__(self, host='localhost', port=2828, app=None, app_args=None, bin=None,
profile=None, emulator=None, sdcard=None, emulatorBinary=None,
emulatorImg=None, emulator_res=None, gecko_path=None,
connectToRunningEmulator=False, homedir=None, baseurl=None,
noWindow=False, logcat_dir=None, busybox=None, symbols_path=None,
timeout=None, device_serial=None):
self.host = host
self.port = self.local_port = port
self.bin = bin
self.instance = None
self.profile = profile
self.session = None
self.window = None
self.emulator = None
self.extra_emulators = []
self.homedir = homedir
self.baseurl = baseurl
self.noWindow = noWindow
self.logcat_dir = logcat_dir
self._test_name = None
self.symbols_path = symbols_path
self.timeout = timeout
self.device_serial = device_serial
if bin:
port = int(self.port)
if not Marionette.is_port_available(port, host=self.host):
ex_msg = "%s:%d is unavailable." % (self.host, port)
raise MarionetteException(message=ex_msg)
if app:
# select instance class for the given app
try:
instance_class = geckoinstance.apps[app]
except KeyError:
msg = 'Application "%s" unknown (should be one of %s)'
raise NotImplementedError(msg % (app, geckoinstance.apps.keys()))
else:
instance_class = geckoinstance.GeckoInstance
self.instance = instance_class(host=self.host, port=self.port,
bin=self.bin, profile=self.profile, app_args=app_args)
self.instance.start()
assert(self.wait_for_port()), "Timed out waiting for port!"
if emulator:
self.emulator = Emulator(homedir=homedir,
noWindow=self.noWindow,
logcat_dir=self.logcat_dir,
arch=emulator,
sdcard=sdcard,
emulatorBinary=emulatorBinary,
userdata=emulatorImg,
res=emulator_res)
self.emulator.start()
self.port = self.emulator.setup_port_forwarding(self.port)
assert(self.emulator.wait_for_port()), "Timed out waiting for port!"
if connectToRunningEmulator:
self.emulator = Emulator(homedir=homedir,
logcat_dir=self.logcat_dir)
self.emulator.connect()
self.port = self.emulator.setup_port_forwarding(self.port)
assert(self.emulator.wait_for_port()), "Timed out waiting for port!"
self.client = MarionetteClient(self.host, self.port)
if emulator:
self.emulator.setup(self,
gecko_path=gecko_path,
busybox=busybox)
def __del__(self):
if self.emulator:
self.emulator.close()
if self.instance:
self.instance.close()
for qemu in self.extra_emulators:
qemu.emulator.close()
@staticmethod
def is_port_available(port, host=''):
port = int(port)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.bind((host, port))
return True
except socket.error:
return False
finally:
s.close()
#.........这里部分代码省略.........
示例2: Marionette
# 需要导入模块: from emulator import Emulator [as 别名]
# 或者: from emulator.Emulator import setup [as 别名]
class Marionette(object):
CONTEXT_CHROME = 'chrome'
CONTEXT_CONTENT = 'content'
TIMEOUT_SEARCH = 'implicit'
TIMEOUT_SCRIPT = 'script'
TIMEOUT_PAGE = 'page load'
def __init__(self, host='localhost', port=2828, bin=None, profile=None,
emulator=None, sdcard=None, emulatorBinary=None,
emulatorImg=None, emulator_res='480x800', gecko_path=None,
connectToRunningEmulator=False, homedir=None, baseurl=None,
noWindow=False, logcat_dir=None, busybox=None):
self.host = host
self.port = self.local_port = port
self.bin = bin
self.instance = None
self.profile = profile
self.session = None
self.window = None
self.emulator = None
self.extra_emulators = []
self.homedir = homedir
self.baseurl = baseurl
self.noWindow = noWindow
self.logcat_dir = logcat_dir
self._test_name = None
if bin:
self.instance = GeckoInstance(host=self.host, port=self.port,
bin=self.bin, profile=self.profile)
self.instance.start()
assert(self.wait_for_port())
if emulator:
self.emulator = Emulator(homedir=homedir,
noWindow=self.noWindow,
logcat_dir=self.logcat_dir,
arch=emulator,
sdcard=sdcard,
emulatorBinary=emulatorBinary,
userdata=emulatorImg,
res=emulator_res)
self.emulator.start()
self.port = self.emulator.setup_port_forwarding(self.port)
assert(self.emulator.wait_for_port())
if connectToRunningEmulator:
self.emulator = Emulator(homedir=homedir,
logcat_dir=self.logcat_dir)
self.emulator.connect()
self.port = self.emulator.setup_port_forwarding(self.port)
assert(self.emulator.wait_for_port())
self.client = MarionetteClient(self.host, self.port)
if emulator:
self.emulator.setup(self, gecko_path=gecko_path)
if busybox:
self.emulator.install_busybox(busybox)
def __del__(self):
if self.emulator:
self.emulator.close()
if self.instance:
self.instance.close()
for qemu in self.extra_emulators:
qemu.emulator.close()
@classmethod
def getMarionetteOrExit(cls, *args, **kwargs):
try:
m = cls(*args, **kwargs)
return m
except InstallGeckoError:
# Bug 812395 - the process of installing gecko into the emulator
# and then restarting B2G tickles some bug in the emulator/b2g
# that intermittently causes B2G to fail to restart. To work
# around this in TBPL runs, we will fail gracefully from this
# error so that the mozharness script can try the run again.
# This string will get caught by mozharness and will cause it
# to retry the tests.
print "Error installing gecko!"
# Exit without a normal exception to prevent mozharness from
# flagging the error.
sys.exit()
def wait_for_port(self, timeout=3000):
starttime = datetime.datetime.now()
while datetime.datetime.now() - starttime < datetime.timedelta(seconds=timeout):
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((self.host, self.port))
data = sock.recv(16)
sock.close()
if '"from"' in data:
time.sleep(5)
return True
#.........这里部分代码省略.........
示例3: Marionette
# 需要导入模块: from emulator import Emulator [as 别名]
# 或者: from emulator.Emulator import setup [as 别名]
class Marionette(object):
CONTEXT_CHROME = "chrome"
CONTEXT_CONTENT = "content"
TIMEOUT_SEARCH = "implicit"
TIMEOUT_SCRIPT = "script"
TIMEOUT_PAGE = "page load"
def __init__(
self,
host="localhost",
port=2828,
app=None,
bin=None,
profile=None,
emulator=None,
sdcard=None,
emulatorBinary=None,
emulatorImg=None,
emulator_res=None,
gecko_path=None,
connectToRunningEmulator=False,
homedir=None,
baseurl=None,
noWindow=False,
logcat_dir=None,
busybox=None,
symbols_path=None,
timeout=None,
):
self.host = host
self.port = self.local_port = port
self.app = app
self.bin = bin
self.instance = None
self.profile = profile
self.session = None
self.window = None
self.emulator = None
self.extra_emulators = []
self.homedir = homedir
self.baseurl = baseurl
self.noWindow = noWindow
self.logcat_dir = logcat_dir
self._test_name = None
self.symbols_path = symbols_path
self.timeout = timeout
if bin:
port = int(self.port)
if not Marionette.is_port_available(port, host=self.host):
ex_msg = "%s:%d is unavailable." % (self.host, port)
raise MarionetteException(message=ex_msg)
if app:
# select instance class for the given app
try:
instance_class = geckoinstance.apps[app]
except KeyError:
msg = 'Application "%s" unknown (should be one of %s)'
raise NotImplementedError(msg % (app, geckoinstance.apps.keys()))
else:
instance_class = geckoinstance.GeckoInstance
self.instance = instance_class(host=self.host, port=self.port, bin=self.bin, profile=self.profile)
self.instance.start()
assert self.wait_for_port()
if emulator:
self.emulator = Emulator(
homedir=homedir,
noWindow=self.noWindow,
logcat_dir=self.logcat_dir,
arch=emulator,
sdcard=sdcard,
emulatorBinary=emulatorBinary,
userdata=emulatorImg,
res=emulator_res,
)
self.emulator.start()
self.port = self.emulator.setup_port_forwarding(self.port)
assert self.emulator.wait_for_port()
if connectToRunningEmulator:
self.emulator = Emulator(homedir=homedir, logcat_dir=self.logcat_dir)
self.emulator.connect()
self.port = self.emulator.setup_port_forwarding(self.port)
assert self.emulator.wait_for_port()
self.client = MarionetteClient(self.host, self.port)
if emulator:
self.emulator.setup(self, gecko_path=gecko_path, busybox=busybox)
def __del__(self):
if self.emulator:
self.emulator.close()
if self.instance:
self.instance.close()
for qemu in self.extra_emulators:
qemu.emulator.close()
#.........这里部分代码省略.........