本文整理汇总了Python中marionette.Marionette.start_session方法的典型用法代码示例。如果您正苦于以下问题:Python Marionette.start_session方法的具体用法?Python Marionette.start_session怎么用?Python Marionette.start_session使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类marionette.Marionette
的用法示例。
在下文中一共展示了Marionette.start_session方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cli
# 需要导入模块: from marionette import Marionette [as 别名]
# 或者: from marionette.Marionette import start_session [as 别名]
def cli():
parser = OptionParser(usage='%prog gaia_atoms_path app_name [app_name] ...')
options, args = parser.parse_args()
if not args:
parser.print_usage()
parser.exit()
if not os.path.isdir(args[0]):
parser.print_usage()
print 'must specify valid path for gaia atoms'
parser.exit()
if len(args) != 2:
parser.print_usage()
print 'must specify at one app name'
parser.exit()
marionette = Marionette(host='localhost', port=2828) # TODO command line option for address
marionette.start_session()
launchApp(
marionette,
gaia_atoms=args[0],
app_name=args[1])
示例2: main
# 需要导入模块: from marionette import Marionette [as 别名]
# 或者: from marionette.Marionette import start_session [as 别名]
def main(options):
print "Setting up CertTest app to device"
dm = None
if options.adb_path:
dm = mozdevice.DeviceManagerADB(adbPath=options.adb_path)
else:
dm = mozdevice.DeviceManagerADB()
if dm.dirExists("/data/local/webapps/certtest-app"):
print "CertTest app is already installed"
return
dm.pushFile("certtest_app.zip", "/data/local/certtest_app.zip")
# forward the marionette port
print "Forwarding marionette port"
ret = dm.forward("tcp:2828", "tcp:2828")
if ret != 0:
#TODO: right thing here is to keep trying local ports and pass that value in our config
raise Exception("Can't use localhost:2828 for port forwarding. Is something else using port 2828?")
# install the app
print "installing the app"
f = open("app_install.js", "r")
script = f.read()
f.close()
m = Marionette()
m.start_session()
m.set_context("chrome")
m.set_script_timeout(5000)
m.execute_async_script(script)
m.delete_session()
示例3: set_up_device
# 需要导入模块: from marionette import Marionette [as 别名]
# 或者: from marionette.Marionette import start_session [as 别名]
def set_up_device(opt):
if not opt.wifi_ssid or not opt.wifi_key or not opt.wifi_pass:
raise ValueError('Missing --wifi options')
mc = Marionette('localhost', opt.adb_port)
for i in range(2):
try:
mc.start_session()
break
except socket.error:
sh('adb forward tcp:%s tcp:%s' % (opt.adb_port, opt.adb_port))
if opt.shell:
from pdb import set_trace
set_trace()
return
# watch out! This is how gaiatest does it.
mc.__class__ = type('Marionette', (Marionette, MarionetteTouchMixin), {})
device = GaiaDevice(mc)
device.restart_b2g()
apps = GaiaApps(mc)
data_layer = GaiaData(mc)
lockscreen = LockScreen(mc)
mc.setup_touch()
lockscreen.unlock()
apps.kill_all()
data_layer.enable_wifi()
if opt.wifi_key == 'WPA-PSK':
pass_key = 'psk'
elif opt.wifi_key == 'WEP':
pass_key = 'wep'
else:
assert 0, 'unknown key management'
data = {'ssid': opt.wifi_ssid, 'keyManagement': opt.wifi_key,
pass_key: opt.wifi_pass}
data_layer.connect_to_wifi(data)
mc.switch_to_frame()
all_apps = set(a['manifest']['name'] for a in get_installed(apps))
if 'Marketplace Dev' not in all_apps:
mc.execute_script(
'navigator.mozApps.install'
'("https://marketplace-dev.allizom.org/manifest.webapp");')
wait_for_element_displayed(mc, 'id', 'app-install-install-button')
yes = mc.find_element('id', 'app-install-install-button')
mc.tap(yes)
wait_for_element_displayed(mc, 'id', 'system-banner')
print 'Pushing payment prefs'
sh('adb shell stop b2g')
sh('adb push "%s" /data/local/user.js' % (
os.path.join(os.path.dirname(__file__), 'payment-prefs.js')))
sh('adb shell start b2g')
print 'When your device reboots, Marketplace Dev will be installed'
示例4: get_new_emulator
# 需要导入模块: from marionette import Marionette [as 别名]
# 或者: from marionette.Marionette import start_session [as 别名]
def get_new_emulator(self):
_qemu = Marionette(emulator=True,
homedir=self.marionette.homedir,
baseurl=self.marionette.baseurl,
noWindow=self.marionette.noWindow)
_qemu.start_session()
self._qemu.append(_qemu)
return _qemu
示例5: create_marionette
# 需要导入模块: from marionette import Marionette [as 别名]
# 或者: from marionette.Marionette import start_session [as 别名]
def create_marionette():
"""Creates a new Marionette session if one does not exist."""
m = TestCase.stored.marionette
if not m:
m = Marionette()
m.start_session()
TestCase.stored.marionette = m
return TestCase.stored.marionette
示例6: get_marionette
# 需要导入模块: from marionette import Marionette [as 别名]
# 或者: from marionette.Marionette import start_session [as 别名]
def get_marionette(args):
mc = Marionette('localhost', args.adb_port)
for i in range(3):
try:
mc.start_session()
break
# Catching SystemExit because tracebacks are suppressed.
# This won't be necessary after
# https://bugzilla.mozilla.org/show_bug.cgi?id=863377
except (socket.error, SystemExit):
sh('adb forward tcp:%s tcp:%s' % (args.adb_port, args.adb_port))
return mc
示例7: get_new_emulator
# 需要导入模块: from marionette import Marionette [as 别名]
# 或者: from marionette.Marionette import start_session [as 别名]
def get_new_emulator(self):
self.extra_emulator_index += 1
if len(self.marionette.extra_emulators) == self.extra_emulator_index:
qemu = Marionette(emulator=self.marionette.emulator.arch,
homedir=self.marionette.homedir,
baseurl=self.marionette.baseurl,
noWindow=self.marionette.noWindow)
qemu.start_session()
self.marionette.extra_emulators.append(qemu)
else:
qemu = self.marionette.extra_emulators[self.extra_emulator_index]
return qemu
示例8: uninstall_app
# 需要导入模块: from marionette import Marionette [as 别名]
# 或者: from marionette.Marionette import start_session [as 别名]
def uninstall_app(app_name, adb_path="adb", script_timeout=5000, marionette=None):
"""
Uninstalls the given app.
NOTE: if a marionette session is passed, this function switches to the top-most frame.
"""
dm = mozdevice.DeviceManagerADB(adbPath=adb_path)
installed_app_name = app_name.lower()
installed_app_name = installed_app_name.replace(" ", "-")
if dm.forward("tcp:2828", "tcp:2828") != 0:
raise Exception("Can't use localhost:2828 for port forwarding." \
"Is something else using port 2828?")
if not marionette:
m = Marionette()
m.start_session()
else:
m = marionette
m.switch_to_frame()
uninstall_app = """
var uninstallWithName = function(name) {
let apps = window.wrappedJSObject.applications || window.wrappedJSObject.Applications;
let installedApps = apps.installedApps;
for (let manifestURL in installedApps) {
let app = installedApps[manifestURL];
let origin = null;
let entryPoints = app.manifest.entry_points;
if (entryPoints) {
for (let ep in entryPoints) {
let currentEntryPoint = entryPoints[ep];
let appName = currentEntryPoint.name;
if (name == appName.toLowerCase()) {
window.wrappedJSObject.navigator.mozApps.mgmt.uninstall(app);
return true;
}
}
} else {
let appName = app.manifest.name;
if (name == appName.toLowerCase()) {
window.wrappedJSObject.navigator.mozApps.mgmt.uninstall(app);
return true;
}
}
}
return false;
};
return uninstallWithName("%s");
"""
m.set_script_timeout(script_timeout)
m.execute_script(uninstall_app % app_name.lower())
if not marionette:
m.delete_session()
示例9: ftu_toggler
# 需要导入模块: from marionette import Marionette [as 别名]
# 或者: from marionette.Marionette import start_session [as 别名]
def ftu_toggler(skip_ftu=True):
dm = mozdevice.DeviceManagerADB(runAdbAsRoot=True)
dm.forward("tcp:2828", "tcp:2828")
m = Marionette()
m.start_session()
data_layer = GaiaData(m)
url = "null" if skip_ftu else "app://ftu.gaiamobile.org/manifest.webapp"
data_layer.set_setting('ftu.manifestURL', url)
m.close()
# restart b2g to enable
dm.reboot()
示例10: startMarionette
# 需要导入模块: from marionette import Marionette [as 别名]
# 或者: from marionette.Marionette import start_session [as 别名]
def startMarionette():
# FW port for ADB via USB
return_code = subprocess.call(["adb root"], shell=True)
if return_code:
raise Exception("Failed to start adb in root mode. Ensure device is attached to USB.")
return_code = subprocess.call(["adb forward tcp:2828 tcp:2828"], shell=True)
if return_code:
raise Exception("Failed to connect to device via ADB; ensure device is attached to USB.")
# Start Marionette
marionette = Marionette(host='localhost', port=2828)
marionette.start_session()
marionette.set_script_timeout(60000)
return marionette
示例11: dual_driving
# 需要导入模块: from marionette import Marionette [as 别名]
# 或者: from marionette.Marionette import start_session [as 别名]
def dual_driving():
mm = Marionette(host='localhost', port=2829)
mm.start_session()
md = Marionette(host='localhost', port=2828)
md.start_session()
md.set_search_timeout(1000) # especially required for webcompat.com JS-driven loading
ignored_bugs = []
buglist = []
for line in open(ignore_file, 'r'):
if line[0] == '#':
continue
ignored_bugs.append(line.strip())
if start_url:
print 'Starting from bug search %s' % start_url
md.navigate(start_url)
buglist = extract_buglist(md)
else:
buglist = extract_buglist_from_file(filename)
i = 1
for item in buglist:
if len(item) <= 1:
print 'Warning: we expect data format ID Summary URL, something is missing'
continue
if '://' not in item[0]: # assuming this is Bugzilla data from a tab-separated file - in other words a plain bug number
md.navigate('https://bugzilla.mozilla.org/show_bug.cgi?id=%s' % item[0])
else: # we've got a bug tracker URL (right?)
md.navigate(item[0])
if len(item) == 2: # URL is not in the data - let's load the bug first and try to get it from there
url = get_url_from_bugpage(md)
else:
url = item[2]
if not url:
i+=1
continue
if i<start_at or url.strip() == '':
i+=1
continue
if '://' not in url:
url = 'http://%s' % url
url = url.strip().rstrip('\r\n')
location = urlparse.urlparse(url)
hostname = location.hostname.rstrip('\r\n')
print str(i) + ' : ' + url
reset_spoof(mm)
mm.navigate(url)
print 'READY to analyze %s, \n%s' % (item[0], item[1])
options_menu(mm, url, md)
mm.delete_session()
md.delete_session()
示例12: create_marionette
# 需要导入模块: from marionette import Marionette [as 别名]
# 或者: from marionette.Marionette import start_session [as 别名]
def create_marionette():
"""Returns current Marionette session, or creates one if
one does not exist.
"""
m = TestCase.stored.marionette
if m is None:
m = Marionette()
m.wait_for_port()
m.start_session()
TestCase.stored.marionette = m
return TestCase.stored.marionette
示例13: TestConsoleLogCapture
# 需要导入模块: from marionette import Marionette [as 别名]
# 或者: from marionette.Marionette import start_session [as 别名]
class TestConsoleLogCapture():
def setup(self):
try:
self.client = Marionette(host='localhost', port=2828)
self.client.start_session()
self.client.set_pref('general.warnOnAboutConfig', False)
except:
sys.exit("Could not find Firefox browser running")
def test_push_notification_received(self):
self.client.navigate("https://people.mozilla.org/~ewong2/push-notification-test/")
unregister_button = self.client.find_element(By.ID, "unreg_btn")
if unregister_button.is_displayed() == True:
unregister_button.click()
Wait(self.client, timeout=5, interval=1).until(expected.element_not_displayed(By.ID, "unreg_btn"))
Wait(self.client).until(expected.element_displayed(By.ID, "reg_btn"))
self.client.find_element(By.ID, "reg_btn").click()
Wait(self.client).until(expected.element_displayed(By.ID, "subscribe_btn"))
self.client.find_element(By.ID, "subscribe_btn").click()
Wait(self.client).until(expected.element_displayed(By.ID, "doXhr_btn"))
self.client.find_element(By.ID, "doXhr_btn").click()
result = self.web_console_filter_for_string("Received a push message")
assert result == 1
def web_console_filter_for_string(self, console_string=None):
self.client.set_context(self.client.CONTEXT_CHROME)
handles = self.client.window_handles
chrome_handles = self.client.chrome_window_handles
browser_handle = self.client.current_chrome_window_handle
notifications = 0
for handle in chrome_handles:
if handle != browser_handle:
console_handle = handle
self.client.switch_to_window(console_handle)
time.sleep(1)
results = self.client.find_elements(By.CLASS_NAME, "console-string")
for result in results:
if console_string in result.text:
notifications = notifications + 1
self.client.find_element(By.CLASS_NAME, "webconsole-clear-console-button").click()
return notifications
def tear_down(self):
self.client.close()
示例14: launch_app
# 需要导入模块: from marionette import Marionette [as 别名]
# 或者: from marionette.Marionette import start_session [as 别名]
def launch_app(app_name, adb_path="adb", script_timeout=5000, marionette=None, device_serial=None):
"""
Launches the given app
NOTE: if a marionette session is passed, this function switches to the top-most frame.
"""
dm = mozdevice.DeviceManagerADB(adbPath=adb_path,deviceSerial=device_serial)
installed_app_name = app_name.lower()
installed_app_name = installed_app_name.replace(" ", "-")
dm.forward("tcp:2828", "tcp:2828")
if not marionette:
m = Marionette()
m.start_session()
else:
m = marionette
m.switch_to_frame()
launch_app = """
var launchWithName = function(name) {
let apps = window.wrappedJSObject.applications || window.wrappedJSObject.Applications;
let installedApps = apps.installedApps;
for (let manifestURL in installedApps) {
let app = installedApps[manifestURL];
let origin = null;
let entryPoints = app.manifest.entry_points;
if (entryPoints) {
for (let ep in entryPoints) {
let currentEntryPoint = entryPoints[ep];
let appName = currentEntryPoint.name;
if (name == appName.toLowerCase()) {
app.launch();
return true;
}
}
} else {
let appName = app.manifest.name;
if (name == appName.toLowerCase()) {
app.launch();
return true;
}
}
}
return false;
};
return launchWithName("%s");
"""
m.set_script_timeout(script_timeout)
m.execute_script(launch_app % app_name.lower())
if not marionette:
m.delete_session()
示例15: _StartProcess
# 需要导入模块: from marionette import Marionette [as 别名]
# 或者: from marionette.Marionette import start_session [as 别名]
def _StartProcess(self):
if not self.isEmulatorInitialized:
print("Starting Emulator ...")
self.emulatorProcess = subprocess.Popen(
[self.emulatorStartScript], cwd=os.path.dirname(self.emulatorStartScript), shell=True)
# adb shell setprop net.dns1 10.0.2.3
self._isBootFinished()
self.monitoringProcessId = self.adb.getPID(self.monitoredProcessName)
print("Forwarding TCP port %d ..." % self.forwardedPortADB)
self.adb.command(["forward", "tcp:%d" % self.forwardedPortADB, "tcp:%d" % self.forwardedPortADB])
self.isEmulatorInitialized = True
time.sleep(20)
if self.crashSuccess:
print("Restarting %s ..." % self.monitoredProcessName)
self.adb.killProcess(self.monitoredProcessName, True)
time.sleep(40)
self.monitoringProcessId = self.adb.getPID(self.monitoredProcessName)
self.crashSuccess = False
self.debugLogData = str()
self.adb.checkCmd(["logcat", "-c"])
print("Starting Marionette session ...")
marionette = Marionette('localhost', self.forwardedPortADB)
print(marionette.status())
marionette.start_session()
marionette.set_script_timeout(self.scriptTimeout)
marionette.switch_to_frame()
lock = gaia.LockScreen(marionette)
lock.unlock()
apps = gaia.GaiaApps(marionette)
print(apps.runningApps())
print("Launching Browser application")
apps.launch(self.appName, switch_to_frame=True)
print("Navigating to %s ..." % self.publisherURL)
marionette.execute_script("return window.wrappedJSObject.Browser.navigate('%s')" % self.publisherURL)
self.isMonitorInitialized = True