本文整理汇总了Python中mozprofile.profile.Profile类的典型用法代码示例。如果您正苦于以下问题:Python Profile类的具体用法?Python Profile怎么用?Python Profile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Profile类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_reset_should_remove_added_prefs
def test_reset_should_remove_added_prefs(self):
"""Check that when we call reset the items we expect are updated"""
profile = Profile()
prefs_file = os.path.join(profile.profile, 'user.js')
# we shouldn't have any initial preferences
initial_prefs = Preferences.read_prefs(prefs_file)
self.assertFalse(initial_prefs)
initial_prefs = file(prefs_file).read().strip()
self.assertFalse(initial_prefs)
# add some preferences
prefs1 = [("mr.t.quotes", "i aint getting on no plane!")]
profile.set_preferences(prefs1)
self.assertEqual(prefs1, Preferences.read_prefs(prefs_file))
lines = file(prefs_file).read().strip().splitlines()
self.assertTrue(bool([line for line in lines
if line.startswith('#MozRunner Prefs Start')]))
self.assertTrue(bool([line for line in lines
if line.startswith('#MozRunner Prefs End')]))
profile.reset()
self.assertNotEqual(prefs1,
Preferences.read_prefs(os.path.join(profile.profile, 'user.js')),
"I pity the fool who left my pref")
开发者ID:SlateScience,项目名称:MozillaJS,代码行数:26,代码来源:test_preferences.py
示例2: test_nonce
def test_nonce(self):
# make a profile with one preference
path = tempfile.mktemp()
profile = Profile(path,
preferences={'foo': 'bar'},
restore=False)
user_js = os.path.join(profile.profile, 'user.js')
self.assertTrue(os.path.exists(user_js))
# ensure the preference is correct
prefs = Preferences.read_prefs(user_js)
self.assertEqual(dict(prefs), {'foo': 'bar'})
del profile
# augment the profile with a second preference
profile = Profile(path,
preferences={'fleem': 'baz'},
restore=True)
prefs = Preferences.read_prefs(user_js)
self.assertEqual(dict(prefs), {'foo': 'bar', 'fleem': 'baz'})
# cleanup the profile;
# this should remove the new preferences but not the old
profile.cleanup()
prefs = Preferences.read_prefs(user_js)
self.assertEqual(dict(prefs), {'foo': 'bar'})
开发者ID:AshishNamdev,项目名称:mozilla-central,代码行数:28,代码来源:test_nonce.py
示例3: test_cleanup_on_garbage_collected
def test_cleanup_on_garbage_collected(self):
clone = Profile.clone(self.profile.profile)
profile_dir = clone.profile
self.assertTrue(os.path.exists(profile_dir))
del clone
# clone should be deleted
self.assertFalse(os.path.exists(profile_dir))
开发者ID:lgarner,项目名称:mozilla-central,代码行数:7,代码来源:test_clone_cleanup.py
示例4: _init_profile
def _init_profile(self):
preferences = dict(self.browser_config['preferences'])
if self.test_config.get('preferences'):
test_prefs = dict(
[(i, utils.parse_pref(j))
for i, j in self.test_config['preferences'].items()]
)
preferences.update(test_prefs)
# interpolate webserver value in prefs
webserver = self.browser_config['webserver']
if '://' not in webserver:
webserver = 'http://' + webserver
for name, value in preferences.items():
if type(value) is str:
value = utils.interpolate(value, webserver=webserver)
preferences[name] = value
extensions = self.browser_config['extensions'][:]
if self.test_config.get('extensions'):
extensions.append(self.test_config['extensions'])
profile = Profile.clone(
os.path.normpath(self.test_config['profile_path']),
self.profile_dir,
restore=False)
profile.set_preferences(preferences)
profile.addon_manager.install_addons(extensions)
开发者ID:kleopatra999,项目名称:system-addons,代码行数:28,代码来源:ffsetup.py
示例5: test_restore_false
def test_restore_false(self):
# make a clone of this profile with restore=False
clone = Profile.clone(self.profile.profile, restore=False)
clone.cleanup()
# clone should still be around on the filesystem
self.assertTrue(os.path.exists(clone.profile))
开发者ID:lgarner,项目名称:mozilla-central,代码行数:8,代码来源:test_clone_cleanup.py
示例6: test_restore_true
def test_restore_true(self):
# make a clone of this profile with restore=True
clone = Profile.clone(self.profile.profile, restore=True)
clone.cleanup()
# clone should be deleted
self.assertFalse(os.path.exists(clone.profile))
开发者ID:lgarner,项目名称:mozilla-central,代码行数:8,代码来源:test_clone_cleanup.py
示例7: start_firefox
def start_firefox(self):
env = os.environ.copy()
env['MOZ_CRASHREPORTER_NO_REPORT'] = '1'
profile = Profile()
profile.set_preferences({"marionette.defaultPrefs.enabled": True,
"marionette.defaultPrefs.port": self.marionette_port,
"dom.disable_open_during_load": False,
"dom.max_script_run_time": 0})
self.firefox_runner = FirefoxRunner(profile,
self.firefox_binary,
cmdargs=["--marionette"],
env=env,
kp_kwargs = {"processOutputLine":[self.on_output]},
process_class=self.process_cls)
self.logger.debug("Starting Firefox")
self.firefox_runner.start()
self.logger.debug("Firefox Started")
开发者ID:jgraham,项目名称:wptrunner-old,代码行数:19,代码来源:runtests.py
示例8: test_preexisting_preferences
def test_preexisting_preferences(self):
"""ensure you don't clobber preexisting preferences"""
# make a pretend profile
tempdir = tempfile.mkdtemp()
try:
# make a user.js
contents = """
user_pref("webgl.enabled_for_all_sites", true);
user_pref("webgl.force-enabled", true);
"""
user_js = os.path.join(tempdir, 'user.js')
f = file(user_js, 'w')
f.write(contents)
f.close()
# make sure you can read it
prefs = Preferences.read_prefs(user_js)
original_prefs = [('webgl.enabled_for_all_sites', True), ('webgl.force-enabled', True)]
self.assertTrue(prefs == original_prefs)
# now read this as a profile
profile = Profile(tempdir, preferences={"browser.download.dir": "/home/jhammel"})
# make sure the new pref is now there
new_prefs = original_prefs[:] + [("browser.download.dir", "/home/jhammel")]
prefs = Preferences.read_prefs(user_js)
self.assertTrue(prefs == new_prefs)
# clean up the added preferences
profile.cleanup()
del profile
# make sure you have the original preferences
prefs = Preferences.read_prefs(user_js)
self.assertTrue(prefs == original_prefs)
except:
shutil.rmtree(tempdir)
raise
开发者ID:lofter2011,项目名称:Icefox,代码行数:40,代码来源:test_preferences.py
示例9: test_magic_markers
def test_magic_markers(self):
"""ensure our magic markers are working"""
profile = Profile()
prefs_file = os.path.join(profile.profile, 'user.js')
# we shouldn't have any initial preferences
initial_prefs = Preferences.read_prefs(prefs_file)
self.assertFalse(initial_prefs)
initial_prefs = file(prefs_file).read().strip()
self.assertFalse(initial_prefs)
# add some preferences
prefs1 = [("browser.startup.homepage", "http://planet.mozilla.org/"),
("zoom.minPercent", 30)]
profile.set_preferences(prefs1)
self.assertEqual(prefs1, Preferences.read_prefs(prefs_file))
lines = file(prefs_file).read().strip().splitlines()
self.assertTrue(bool([line for line in lines
if line.startswith('#MozRunner Prefs Start')]))
self.assertTrue(bool([line for line in lines
if line.startswith('#MozRunner Prefs End')]))
# add some more preferences
prefs2 = [("zoom.maxPercent", 300),
("webgl.verbose", 'false')]
profile.set_preferences(prefs2)
self.assertEqual(prefs1 + prefs2, Preferences.read_prefs(prefs_file))
lines = file(prefs_file).read().strip().splitlines()
self.assertTrue(len([line for line in lines
if line.startswith('#MozRunner Prefs Start')]) == 2)
self.assertTrue(len([line for line in lines
if line.startswith('#MozRunner Prefs End')]) == 2)
# now clean it up
profile.clean_preferences()
final_prefs = Preferences.read_prefs(prefs_file)
self.assertFalse(final_prefs)
lines = file(prefs_file).read().strip().splitlines()
self.assertTrue('#MozRunner Prefs Start' not in lines)
self.assertTrue('#MozRunner Prefs End' not in lines)
开发者ID:SlateScience,项目名称:MozillaJS,代码行数:41,代码来源:test_preferences.py
示例10: test_restore_true
def test_restore_true(self):
counter = [0]
def _feedback(dir, content):
# Called by shutil.copytree on each visited directory.
# Used here to display info.
#
# Returns the items that should be ignored by
# shutil.copytree when copying the tree, so always returns
# an empty list.
counter[0] += 1
return []
# make a clone of this profile with restore=True
clone = Profile.clone(self.profile.profile, restore=True,
ignore=_feedback)
self.addCleanup(mozfile.remove, clone.profile)
clone.cleanup()
# clone should be deleted
self.assertFalse(os.path.exists(clone.profile))
self.assertTrue(counter[0] > 0)
开发者ID:luke-chang,项目名称:gecko-1,代码行数:23,代码来源:test_clone_cleanup.py
示例11: do_POST
def do_POST(self):
try:
path, body, session, element = self.process_request()
logger.debug("%s - %s - %s - %s" % (path, body, session, element))
if path == "/back":
logger.info("Navigating back - %s" % session)
assert session
assert self.server.marionette.go_back()
self.send_JSON(session=session)
elif path == "/clear":
logger.info("Clearing %s - %s" % (element, session))
assert session
marionette_element = HTMLElement(self.server.marionette, element)
marionette_element.clear()
self.send_JSON(session=session)
elif path == "/click":
logger.info("Clicking %s - %s" % (element, session))
assert session
marionette_element = HTMLElement(self.server.marionette, element)
marionette_element.click()
self.send_JSON(session=session)
elif path == "/element":
logger.info("Find Element using - %s, value - %s - %s" % (body["using"], body["value"], session))
# find element variants
assert session
self.send_JSON(
session=session,
value={"ELEMENT": self.server.marionette.find_element(body["using"], body["value"], id=element).id},
)
elif path == "/elements":
logger.info("Find Elements using - %s, value - %s - %s" % (body["using"], body["value"], session))
# find elements variants
assert session
self.send_JSON(
session=session,
value=[
{"ELEMENT": x.id} for x in self.server.marionette.find_elements(body["using"], body["value"])
],
)
elif path == "/execute":
logger.info("Executing Script - %s" % session)
assert session
if body["args"]:
result = self.server.marionette.execute_script(
body["script"], script_args=body["args"], new_sandbox=False
)
else:
result = self.server.marionette.execute_script(body["script"], new_sandbox=False)
self.send_JSON(session=session, value=result)
elif path == "/execute_async":
logger.info("Executing Async Script - %s" % session)
assert session
result = None
if body["args"]:
result = self.server.marionette.execute_async_script(
body["script"], script_args=body["args"], new_sandbox=False
)
else:
result = self.server.marionette.execute_async_script(body["script"], new_sandbox=False)
self.send_JSON(session=session, value=result)
elif path == "/forward":
logger.info("Forwarding - %s" % session)
assert session
assert self.server.marionette.go_forward()
self.send_JSON(session=session)
elif path == "/frame":
logger.info("Switch to Frame %s - %s" % (body["id"], session))
assert session
frame = body["id"]
if isinstance(frame, dict) and "ELEMENT" in frame:
frame = HTMLElement(self.server.marionette, frame["ELEMENT"])
assert self.server.marionette.switch_to_frame(frame)
self.send_JSON(session=session)
elif path == "/refresh":
logger.info("Refreshing the page - %s" % session)
assert session
assert self.server.marionette.refresh()
self.send_JSON(session=session)
elif path == "/session":
logger.info("Creating new session")
logger.debug("loading webdriver prefs")
with open("webdriver.json") as webpref:
read_prefs = webpref.read()
prefs = json.loads(read_prefs)
port = free_port()
logger.debug("Creating Profile")
profile = Profile()
profile.set_preferences(prefs["frozen"])
profile.set_preferences(prefs["mutable"])
profile.set_preferences({"marionette.defaultPrefs.enabled": True, "marionette.defaultPrefs.port": port})
logger.debug("Profile created at %s" % profile.profile)
logger.debug("Creating runner")
firefox_binary = (
body["desiredCapabilities"]["firefoxBinary"]
if body["desiredCapabilities"]["firefoxBinary"]
#.........这里部分代码省略.........
开发者ID:AutomatedTester,项目名称:Selenium-Proxy,代码行数:101,代码来源:selenium_proxy.py
示例12: _init_profile
def _init_profile(self):
preferences = dict(self.browser_config['preferences'])
if self.test_config.get('preferences'):
test_prefs = dict(
[(i, utils.parse_pref(j))
for i, j in self.test_config['preferences'].items()]
)
preferences.update(test_prefs)
# interpolate webserver value in prefs
webserver = self.browser_config['webserver']
if '://' not in webserver:
webserver = 'http://' + webserver
for name, value in preferences.items():
if type(value) is str:
value = utils.interpolate(value, webserver=webserver)
preferences[name] = value
extensions = self.browser_config['extensions'][:]
if self.test_config.get('extensions'):
extensions.append(self.test_config['extensions'])
# downloading a profile instead of using the empty one
if self.test_config['profile'] is not None:
path = heavy.download_profile(self.test_config['profile'])
self.test_config['profile_path'] = path
profile_path = os.path.normpath(self.test_config['profile_path'])
LOG.info("Cloning profile located at %s" % profile_path)
def _feedback(directory, content):
# Called by shutil.copytree on each visited directory.
# Used here to display info.
#
# Returns the items that should be ignored by
# shutil.copytree when copying the tree, so always returns
# an empty list.
sub = directory.split(profile_path)[-1].lstrip("/")
if sub:
LOG.info("=> %s" % sub)
return []
profile = Profile.clone(profile_path,
self.profile_dir,
ignore=_feedback,
restore=False)
profile.set_preferences(preferences)
# installing addons
LOG.info("Installing Add-ons")
profile.addon_manager.install_addons(extensions)
# installing webextensions
webextensions = self.test_config.get('webextensions', None)
if isinstance(webextensions, basestring):
webextensions = [webextensions]
if webextensions is not None:
LOG.info("Installing Webextensions")
for webext in webextensions:
filename = utils.interpolate(webext)
if mozinfo.os == 'win':
filename = filename.replace('/', '\\')
if not filename.endswith('.xpi'):
continue
if not os.path.exists(filename):
continue
profile.addon_manager.install_from_path(filename)
开发者ID:luke-chang,项目名称:gecko-1,代码行数:69,代码来源:ffsetup.py
示例13: do_POST
def do_POST(self):
try:
path, body, session, element = self.process_request()
logger.debug("%s - %s - %s - %s" % (path, body, session, element))
if path == '/back':
logger.info("Navigating back - %s" % session)
assert(session)
assert(self.server.marionette.go_back())
self.send_JSON(session=session)
elif path == '/clear':
logger.info("Clearing %s - %s" % (element, session))
assert(session)
marionette_element = HTMLElement(self.server.marionette, element)
marionette_element.clear()
self.send_JSON(session=session)
elif path == '/click':
logger.info("Clicking %s - %s" % (element, session))
assert(session)
marionette_element = HTMLElement(self.server.marionette, element)
marionette_element.click()
self.send_JSON(session=session)
elif path == '/element':
logger.info("Find Element using - %s, value - %s - %s" \
% (body['using'], body['value'], session))
# find element variants
assert(session)
self.send_JSON(session=session,
value={'ELEMENT': self.server.marionette.find_element(body['using'], body['value'], id=element).id})
elif path == '/elements':
logger.info("Find Elements using - %s, value - %s - %s" \
% (body['using'], body['value'], session))
# find elements variants
assert(session)
self.send_JSON(session=session,
value=[{'ELEMENT': x.id} for x in self.server.marionette.find_elements(body['using'], body['value'])])
elif path == '/execute':
logger.info("Executing Script - %s" % session)
assert(session)
if body['args']:
result = self.server.marionette.execute_script(body['script'], script_args=body['args'],
new_sandbox=False)
else:
result = self.server.marionette.execute_script(body['script'],new_sandbox=False)
self.send_JSON(session=session, value=result)
elif path == '/execute_async':
logger.info("Executing Async Script - %s" % session)
assert(session)
result = None
if body['args']:
result = self.server.marionette.execute_async_script(body['script'], script_args=body['args'], new_sandbox=False)
else:
result = self.server.marionette.execute_async_script(body['script'], new_sandbox=False)
self.send_JSON(session=session, value=result)
elif path == '/forward':
logger.info("Forwarding - %s" % session)
assert(session)
assert(self.server.marionette.go_forward())
self.send_JSON(session=session)
elif path == '/frame':
logger.info("Switch to Frame %s - %s" % (body['id'], session))
assert(session)
frame = body['id']
if isinstance(frame, dict) and 'ELEMENT' in frame:
frame = HTMLElement(self.server.marionette, frame['ELEMENT'])
assert(self.server.marionette.switch_to_frame(frame))
self.send_JSON(session=session)
elif path == '/refresh':
logger.info("Refreshing the page - %s" % session)
assert(session)
assert(self.server.marionette.refresh())
self.send_JSON(session=session)
elif path == '/session':
logger.info("Creating new session")
logger.debug("loading webdriver prefs")
with open('webdriver.json') as webpref:
read_prefs = webpref.read()
prefs = json.loads(read_prefs)
port = free_port()
logger.debug("Creating Profile")
profile = Profile()
profile.set_preferences(prefs['frozen'])
profile.set_preferences(prefs['mutable'])
profile.set_preferences({"marionette.defaultPrefs.enabled": True,
"marionette.defaultPrefs.port": port})
logger.debug("Profile created at %s" % profile.profile)
logger.debug("Creating runner")
firefox_binary = body["desiredCapabilities"]['firefoxBinary'] if body["desiredCapabilities"]['firefoxBinary'] else firefox_binary_path()
self.server.runner = FirefoxRunner(profile, firefox_binary)
self.server.runner.start()
logger.debug("Browser has been started")
import time
time.sleep(10)
logger.info("Creating Marionette instance on %s:%s" % ("localhost", port))
self.server.marionette = Marionette("localhost", port)
session = self.server.marionette.start_session()
#.........这里部分代码省略.........
开发者ID:jonallengriffin,项目名称:Selenium-Proxy,代码行数:101,代码来源:selenium_proxy.py
注:本文中的mozprofile.profile.Profile类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论