本文整理汇总了Python中marionette.Marionette.import_script方法的典型用法代码示例。如果您正苦于以下问题:Python Marionette.import_script方法的具体用法?Python Marionette.import_script怎么用?Python Marionette.import_script使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类marionette.Marionette
的用法示例。
在下文中一共展示了Marionette.import_script方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: B2gExecutor
# 需要导入模块: from marionette import Marionette [as 别名]
# 或者: from marionette.Marionette import import_script [as 别名]
class B2gExecutor(Executor):
def __init__(self, app_name, app_id, device=False):
self.device = device
if self.device:
call(['adb', 'forward', 'tcp:2828', 'tcp:2828'])
self._app_name = app_name
self._app_id = app_id
self._marionette = Marionette()
self._marionette.start_session()
# https://github.com/mozilla-b2g/gaia/blob/b568b7ae8adb6ee3651bd75acbaaedff86a08912/tests/python/gaia-ui-tests/gaiatest/gaia_test.py
js = os.path.abspath(os.path.join(__file__, os.path.pardir, 'atoms', "gaia_apps.js"))
self._marionette.import_script(js)
js = os.path.abspath(os.path.join(__file__, os.path.pardir, 'atoms', "gaia_data_layer.js"))
self._marionette.set_context(self._marionette.CONTEXT_CHROME)
self._marionette.import_script(js)
self._marionette.set_context(self._marionette.CONTEXT_CONTENT)
'''
# C:\Users\Jun-Wei\Desktop\b2g\battery\manifest.webapp
#app = GaiaApps(self._marionette).launch(self._app_name)
#app = GaiaApps(self._marionette).launch('Battery', manifest_url='C:/Users/Jun-Wei/Desktop/b2g/battery/manifest.webapp', entry_point='/index.html')
app = GaiaApps(self._marionette).launch('Battery')
print app.frame
print app.src
print app.origin
print app.name
#print g_app.manifest_url
#self._app_frame = g_app.frame
self._app_frame_id = app.frame
self._app_src = app.src
self._app_origin = app.origin
#self.app_manifest_url = g_app.manifest_url
#self.gaia_apps = GaiaApps(self.__marionette)
#print self.gaia_apps.displayed_app.name
#print self.gaia_apps.installed_apps
#print self.gaia_apps.running_apps()
#js = os.path.abspath(os.path.join(__file__, os.path.pardir, 'atoms', "gaia_apps.js"))
#self.__marionette.import_script(js)
'''
def fire_event(self, clickable):
logger.info('fire_event: id: %s (xpath: %s)', clickable.get_id(), clickable.get_xpath())
try:
# id staring with DomAnalyzer.serial_prefix is given by our monkey and should be ignored when locating
if clickable.get_id() and not clickable.get_id().startswith(DomAnalyzer.serial_prefix):
self._marionette.find_element('id', clickable.get_id()).tap()
elif clickable.get_xpath():
self._marionette.find_element('xpath', clickable.get_xpath()).tap()
else:
logger.error('No id nor xpath for the clickable: id: %s (xpath: %s)', clickable.get_id(), clickable.get_xpath())
sys.exit()
except (ElementNotVisibleException, InvalidElementStateException, NoSuchElementException):
logger.info('Element is not interactable in fire_event(): id: %s (xpath: %s)', clickable.get_id(), clickable.get_xpath())
except Exception as e:
logger.error('Unknown Exception: %s in fire_event(): id: %s (xpath: %s)', str(e), clickable.get_id(), clickable.get_xpath())
sys.exit()
def fill_form(self, clickable):
for f in clickable.get_forms():
for input_field in f.get_inputs():
try:
if input_field.get_id() and not input_field.get_id().startswith(DomAnalyzer.serial_prefix):
self._marionette.find_element('id', input_field.get_id()).send_keys(input_field.get_value())
elif input_field.get_xpath():
self._marionette.find_element('xpath', input_field.get_xpath()).send_keys(input_field.get_value())
else:
logger.error('No id nor xpath for an input field in the form id: %s (xpath: %s)', f.get_id(), f.get_xpath())
sys.exit()
except (ElementNotVisibleException, InvalidElementStateException, NoSuchElementException):
logger.info('Element is not interactable in fill_form(): id: %s (xpath: %s)', f.get_id(), f.get_xpath())
except Exception as e:
logger.error('Unknown Exception: %s in fill_form(): id: %s (xpath: %s)', str(e), f.get_id(), f.get_xpath())
sys.exit()
def empty_form(self, clickable):
for f in clickable.get_forms():
for input_field in f.get_inputs():
try:
if input_field.get_id() and not input_field.get_id().startswith(DomAnalyzer.serial_prefix):
self._marionette.find_element('id', input_field.get_id()).clear()
elif input_field.get_xpath():
self._marionette.find_element('xpath', input_field.get_xpath()).clear()
else:
logger.error('No id nor xpath for an input field in the form %s (%s)', f.get_id(), f.get_xpath())
sys.exit()
except (ElementNotVisibleException, InvalidElementStateException, NoSuchElementException):
logger.info('Element is not interactable in empty_form(): id: %s (xpath: %s)', f.get_id(), f.get_xpath())
except Exception as e:
logger.error('Unknown Exception: %s in empty_form(): id: %s (xpath: %s)', str(e), f.get_id(), f.get_xpath())
sys.exit()
def get_source(self):
return self._marionette.page_source.encode(sys.stdout.encoding, 'ignore')
def get_screenshot(self, clickable=None):
element = None
#.........这里部分代码省略.........
示例2: waitFor
# 需要导入模块: from marionette import Marionette [as 别名]
# 或者: from marionette.Marionette import import_script [as 别名]
waitFor(
function() {
window.wrappedJSObject.LockScreen.unlock();
waitFor(
function() {
finish(window.wrappedJSObject.LockScreen.locked);
},
function() {
return !window.wrappedJSObject.LockScreen.locked;
}
);
},
function() {
return !!window.wrappedJSObject.LockScreen;
}
);
"""
from marionette import Marionette
marionette = Marionette('localhost', 2828)
marionette.start_session()
marionette.import_script('gaia_apps.js')
marionette.set_script_timeout(60000)
marionette.execute_script(unlock)
result = marionette.execute_async_script("GaiaApps.launchWithName('%s')" % "MozCampAsia-QualityApps")
marionette.switch_to_frame(result.get("frame"))
pdb.set_trace()
示例3: TestCase
# 需要导入模块: from marionette import Marionette [as 别名]
# 或者: from marionette.Marionette import import_script [as 别名]
class TestCase(tornado.testing.AsyncTestCase):
def __init__(self, *args, **kwargs):
#self.config = kwargs.pop("config")
self.handler = kwargs.pop('handler')
self.io_loop = kwargs.pop('io_loop')
self.cert_test_app = None
super(TestCase, self).__init__(*args, **kwargs)
def setUp(self):
super(TestCase, self).setUp()
# import environment
# from environment import InProcessTestEnvironment
# self.environment = environment.get(InProcessTestEnvironment)
# self.server = self.environment.server
self.marionette = None
self.create_marionette()
self.io_loop.run_sync(self.use_cert_app)
def tearDown(self):
super(TestCase, self).tearDown()
self.io_loop.run_sync(self.close_cert_app)
def create_marionette(self):
if not self.marionette or not self.marionette.session:
self.marionette = Marionette()
self.marionette.start_session()
@tornado.gen.coroutine
def use_cert_app(self):
# app management is done in the system app
self.marionette.switch_to_frame()
self.marionette.import_script("tests/app_management.js")
script = "GaiaApps.launchWithName('CertTest App');"
try:
self.cert_test_app = self.marionette.execute_async_script(script, script_timeout=5000)
self.marionette.switch_to_frame(self.cert_test_app["frame"])
self.assertTrue('certtest' in self.marionette.get_url())
except MarionetteException as e:
ok = yield self.instruct("Could not launch CertTest app automatically." \
"Please launch by hand then hit OK to continue.")
self.assertTrue(ok, "Could not launch CertTest app")
except Exception as e:
message = "Unexpected exception: %s" % e
yield self.instruct(message)
self.fail(message)
@tornado.gen.coroutine
def close_cert_app(self):
self.marionette.import_script("tests/app_management.js")
# app management is done in the system app
self.marionette.switch_to_frame()
script = "GaiaApps.kill('%s');" % self.cert_test_app["origin"]
try:
self.marionette.execute_async_script(script, script_timeout=5000)
self.assertTrue('certtest' not in self.marionette.get_url())
except MarionetteException as e:
ok = yield self.instruct("Could not close CertTest app automatically." \
"Please close by hand then hit OK to continue.")
self.assertTrue(ok, "Could not close CertTest app")
except Exception as e:
message = "Unexpected exception: %s" % e
yield self.instruct(message)
self.fail(message)
def get_new_ioloop(self):
return self.io_loop
def prompt(self, message):
"""Prompt the user for a reply. Returns a future which must be
yielded.
This will trigger an overlay in the host browser window
which can be used to tell the user to perform an action or to
input some manual data for us to work on.
Sample usage::
answer = yield prompt("What's the meaning of life?")
assert answer == 42
This function is a simple wrapper for ``tornado.gen.Task``,
and is equivalent to the usage of that.
:param message: The question to ask or message to give the
user.
:returns: A generator which must be yielded. Once yielded,
the return value will be the value of the prompt,
or False if the user hit 'Cancel'
"""
return tornado.gen.Task(self.handler.get_user_input, message)
def instruct(self, message):
"""Presents the user with an instruction. Returns a future which
must be yielded.
This will trigger an overlay in the host browser window
#.........这里部分代码省略.........