本文整理汇总了Python中marionette_driver.marionette.Marionette.execute_script方法的典型用法代码示例。如果您正苦于以下问题:Python Marionette.execute_script方法的具体用法?Python Marionette.execute_script怎么用?Python Marionette.execute_script使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类marionette_driver.marionette.Marionette
的用法示例。
在下文中一共展示了Marionette.execute_script方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup
# 需要导入模块: from marionette_driver.marionette import Marionette [as 别名]
# 或者: from marionette_driver.marionette.Marionette import execute_script [as 别名]
def setup(self):
I18nSetup.locale_path = os.path.join(site.getsitepackages()[0], 'OWDTestToolkit/locale')
if not I18nSetup.configured:
marionette = Marionette()
marionette.start_session()
# Configure the translation to be used based on the previously retrieved language. Should
# the translation is not found, the fallback will prevent a failure
lang = marionette.execute_script("""return window.navigator.language;""")
translation = gettext.translation('default', I18nSetup.locale_path, languages=[lang], fallback=True)
I18nSetup._ = translation.ugettext
I18nSetup.configured = True
return I18nSetup._
示例2: Marionette
# 需要导入模块: from marionette_driver.marionette import Marionette [as 别名]
# 或者: from marionette_driver.marionette.Marionette import execute_script [as 别名]
#!/usr/bin/python2.7
#
# Script to work around Marionette bug 879816 (cannot click the modal 'ok' button
# following clicking something else).
#
from marionette_driver.marionette import Marionette
marionette = Marionette(host='localhost', port=2828)
marionette.start_session()
marionette.switch_to_frame()
marionette.execute_script("document.getElementById('modal-dialog-prompt-ok').click();")
示例3: B2GDesktopReftest
# 需要导入模块: from marionette_driver.marionette import Marionette [as 别名]
# 或者: from marionette_driver.marionette.Marionette import execute_script [as 别名]
class B2GDesktopReftest(RefTest):
build_type = "desktop"
marionette = None
def __init__(self, marionette_args):
RefTest.__init__(self)
self.last_test = os.path.basename(__file__)
self.marionette_args = marionette_args
self.profile = None
self.runner = None
self.test_script = os.path.join(here, 'b2g_start_script.js')
self.timeout = None
def run_marionette_script(self):
self.marionette = Marionette(**self.marionette_args)
assert(self.marionette.wait_for_port())
self.marionette.start_session()
if self.build_type == "mulet":
self._wait_for_homescreen(timeout=300)
self._unlockScreen()
self.marionette.set_context(self.marionette.CONTEXT_CHROME)
if os.path.isfile(self.test_script):
f = open(self.test_script, 'r')
self.test_script = f.read()
f.close()
self.marionette.execute_script(self.test_script)
def run_tests(self, tests, options):
manifests = self.resolver.resolveManifests(options, tests)
self.profile = self.create_profile(options, manifests,
profile_to_clone=options.profile)
env = self.buildBrowserEnv(options, self.profile.profile)
kp_kwargs = { 'processOutputLine': [self._on_output],
'onTimeout': [self._on_timeout],
'kill_on_timeout': False }
if not options.debugger:
if not options.timeout:
if mozinfo.info['debug']:
options.timeout = 420
else:
options.timeout = 300
self.timeout = options.timeout + 30.0
log.info("%s | Running tests: start.", os.path.basename(__file__))
cmd, args = self.build_command_line(options.app,
ignore_window_size=options.ignoreWindowSize,
browser_arg=options.browser_arg)
self.runner = FirefoxRunner(profile=self.profile,
binary=cmd,
cmdargs=args,
env=env,
process_class=ProcessHandler,
process_args=kp_kwargs,
symbols_path=options.symbolsPath)
status = 0
try:
self.runner.start(outputTimeout=self.timeout)
log.info("%s | Application pid: %d",
os.path.basename(__file__),
self.runner.process_handler.pid)
# kick starts the reftest harness
self.run_marionette_script()
status = self.runner.wait()
finally:
self.runner.check_for_crashes(test_name=self.last_test)
self.runner.cleanup()
if status > 0:
log.testFail("%s | application terminated with exit code %s",
self.last_test, status)
elif status < 0:
log.info("%s | application killed with signal %s",
self.last_test, -status)
log.info("%s | Running tests: end.", os.path.basename(__file__))
return status
def create_profile(self, options, manifests, profile_to_clone=None):
profile = RefTest.createReftestProfile(self, options, manifests,
profile_to_clone=profile_to_clone)
prefs = {}
# Turn off the locale picker screen
prefs["browser.firstrun.show.localepicker"] = False
if not self.build_type == "mulet":
# FIXME: With Mulet we can't set this values since Gaia won't launch
prefs["b2g.system_startup_url"] = \
"app://test-container.gaiamobile.org/index.html"
prefs["b2g.system_manifest_url"] = \
"app://test-container.gaiamobile.org/manifest.webapp"
# Make sure we disable system updates
prefs["app.update.enabled"] = False
prefs["app.update.url"] = ""
prefs["app.update.url.override"] = ""
# Disable webapp updates
#.........这里部分代码省略.........
示例4: MuletReftest
# 需要导入模块: from marionette_driver.marionette import Marionette [as 别名]
# 或者: from marionette_driver.marionette.Marionette import execute_script [as 别名]
class MuletReftest(RefTest):
build_type = "mulet"
marionette = None
def __init__(self, marionette_args):
RefTest.__init__(self)
self.last_test = os.path.basename(__file__)
self.marionette_args = marionette_args
self.profile = None
self.runner = None
self.test_script = os.path.join(here, 'b2g_start_script.js')
self.timeout = None
def run_marionette_script(self):
self.marionette = Marionette(**self.marionette_args)
assert(self.marionette.wait_for_port())
self.marionette.start_session()
if self.build_type == "mulet":
self._wait_for_homescreen(timeout=300)
self._unlockScreen()
self.marionette.set_context(self.marionette.CONTEXT_CHROME)
if os.path.isfile(self.test_script):
f = open(self.test_script, 'r')
self.test_script = f.read()
f.close()
self.marionette.execute_script(self.test_script)
def run_tests(self, tests, options):
manifests = self.resolver.resolveManifests(options, tests)
self.profile = self.create_profile(options, manifests,
profile_to_clone=options.profile)
env = self.buildBrowserEnv(options, self.profile.profile)
self._populate_logger(options)
outputHandler = OutputHandler(self.log, options.utilityPath, symbolsPath=options.symbolsPath)
kp_kwargs = { 'processOutputLine': [outputHandler],
'onTimeout': [self._on_timeout],
'kill_on_timeout': False }
if not options.debugger:
if not options.timeout:
if mozinfo.info['debug']:
options.timeout = 420
else:
options.timeout = 300
self.timeout = options.timeout + 30.0
self.log.info("%s | Running tests: start." % os.path.basename(__file__))
cmd, args = self.build_command_line(options.app,
ignore_window_size=options.ignoreWindowSize,
browser_arg=options.browser_arg)
self.runner = FirefoxRunner(profile=self.profile,
binary=cmd,
cmdargs=args,
env=env,
process_class=ProcessHandler,
process_args=kp_kwargs,
symbols_path=options.symbolsPath)
status = 0
try:
self.runner.start(outputTimeout=self.timeout)
self.log.info("%s | Application pid: %d" % (
os.path.basename(__file__),
self.runner.process_handler.pid))
# kick starts the reftest harness
self.run_marionette_script()
status = self.runner.wait()
finally:
self.runner.check_for_crashes(test_name=self.last_test)
self.runner.cleanup()
if status > 0:
self.log.testFail("%s | application terminated with exit code %s" % (
self.last_test, status))
elif status < 0:
self.log.info("%s | application killed with signal %s" % (
self.last_test, -status))
self.log.info("%s | Running tests: end." % os.path.basename(__file__))
return status
def create_profile(self, options, manifests, profile_to_clone=None):
profile = RefTest.createReftestProfile(self, options, manifests,
profile_to_clone=profile_to_clone)
prefs = {}
# Turn off the locale picker screen
prefs["browser.firstrun.show.localepicker"] = False
if not self.build_type == "mulet":
# FIXME: With Mulet we can't set this values since Gaia won't launch
prefs["b2g.system_startup_url"] = \
"app://test-container.gaiamobile.org/index.html"
prefs["b2g.system_manifest_url"] = \
"app://test-container.gaiamobile.org/manifest.webapp"
# Make sure we disable system updates
#.........这里部分代码省略.........
示例5: GCli
# 需要导入模块: from marionette_driver.marionette import Marionette [as 别名]
# 或者: from marionette_driver.marionette.Marionette import execute_script [as 别名]
#.........这里部分代码省略.........
'(default: %(default)s)')
def add_commands(self, parser):
subparsers = parser.add_subparsers(
title='Commands', metavar='<command>')
for (name, props) in sorted(self.commands.iteritems()):
subparser = subparsers.add_parser(name, help=props['help'])
if props.get('args'):
for arg in props['args']:
kwargs = {k: v for k, v in arg.items() if k is not 'name'}
subparser.add_argument(arg['name'], **kwargs)
subparser.set_defaults(func=props['function'])
def connect_to_wifi(self, args):
network = {
'ssid': args.ssid,
'keyManagement': args.security or 'NONE'}
if args.security == 'WEP':
network['wep'] = args.password
elif args.security == 'WPA-PSK':
network['psk'] = args.password
self.data_layer.connect_to_wifi(network)
def disable_wifi(self, args):
self.data_layer.disable_wifi()
def enable_wifi(self, args):
self.data_layer.enable_wifi()
def forget_all_wifi_networks(self, args):
self.data_layer.forget_all_networks()
def get_setting(self, args):
print '%s: %s' % (
args.name,
self.data_layer.get_setting(args.name))
def home(self, args):
self.device.touch_home_button()
def hold_home(self, args):
self.device.hold_home_button()
def hold_sleep(self, args):
self.marionette.execute_script(
"window.wrappedJSObject.dispatchEvent(new Event('holdsleep'));")
def kill_all_apps(self, args):
self.apps.kill_all()
def known_wifi_networks(self, args):
networks = [n for n in self.data_layer.known_networks if 'ssid' in n]
if len(networks) > 0:
for i, network in enumerate(networks):
print '%s: %s' % (i + 1, network['ssid'])
else:
print 'No known networks.'
def launch_app(self, args):
for name in args.name:
self.apps.launch(name)
def list_all_apps(self, args):
for i, app in enumerate(sorted(self.apps.installed_apps,
key=lambda a: a.name.lower())):
print '%d: %s' % (i + 1, app.name)
def list_running_apps(self, args):
for i, app in enumerate(sorted(self.apps.running_apps,
key=lambda a: a.name.lower())):
print '%d: %s' % (i + 1, app.name)
def lock(self, args):
self.device.lock()
def screenshot(self, args):
self.marionette.execute_script(
"window.wrappedJSObject.dispatchEvent(new Event('volumedown+sleep'));")
def send_sms(self, args):
self.data_layer.send_sms(args.number, args.message)
def set_setting(self, args):
self.data_layer.set_setting(args.name, args.value)
def sleep(self, args):
self.marionette.execute_script(
"window.wrappedJSObject.dispatchEvent(new Event('sleep'));")
def unlock(self, args):
self.device.unlock()
def volume(self, args):
self.marionette.execute_script(
"window.wrappedJSObject.dispatchEvent(new Event('volume%s'));" %
args.direction)
def wake(self, args):
self.marionette.execute_script(
"window.wrappedJSObject.dispatchEvent(new Event('wake'));")
示例6: Wait
# 需要导入模块: from marionette_driver.marionette import Marionette [as 别名]
# 或者: from marionette_driver.marionette.Marionette import execute_script [as 别名]
passwordLogin.send_keys(config.get('Login', 'pass'))
# Click on the Log in button to connect
client.find_element(By.ID, 'wp-submit').click()
time.sleep(1)
Wait(client).until(logged_in)
except:
print "Already logged"
# Move to the term
term = args.search
# encode the term and change the space ('%20') in a '+'
term = urllib.quote_plus(term, safe='')
client.navigate("https://translate.wordpress.org/consistency?search=" + term + "&set=" + args.lang + "%2Fdefault")
# Remove the strings different from our
removeOtherStrings = "var right = document.querySelectorAll('table td:nth-child(2) .string');for (var i=0; i<right.length; i++){if(right[i].innerHTML!=='" + cgi.escape(args.remove.replace("'","\\'")) + "') {td = right[i].parentNode;tr = td.parentNode;tr.outerHTML=''}}"
result = client.execute_script(removeOtherStrings)
# Force to open the link in another tab with a little hack in js
addTarget = "var anchors = document.querySelectorAll('table td:nth-child(2) .meta a');for (var i=0; i<anchors.length; i++){anchors[i].setAttribute('target', '_blank');}"
result = client.execute_script(addTarget)
# Open all the links
openPages = client.find_elements(By.CSS_SELECTOR, 'table td:nth-child(2) .meta a')
print('Find ' + str(len(openPages)) + ' wrong strings for ' + args.search + ' with -> ' + args.remove)
i = 0
j = 0
for openPage in openPages:
original_window = client.current_window_handle
openPage.click()
# Wait page load, glotpress is very slow
time.sleep(1.5)
all_tab = client.window_handles
if all_tab[-1] != original_window: