当前位置: 首页>>代码示例>>Python>>正文


Python Profile.set_preferences方法代码示例

本文整理汇总了Python中mozprofile.profile.Profile.set_preferences方法的典型用法代码示例。如果您正苦于以下问题:Python Profile.set_preferences方法的具体用法?Python Profile.set_preferences怎么用?Python Profile.set_preferences使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mozprofile.profile.Profile的用法示例。


在下文中一共展示了Profile.set_preferences方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_reset_should_remove_added_prefs

# 需要导入模块: from mozprofile.profile import Profile [as 别名]
# 或者: from mozprofile.profile.Profile import set_preferences [as 别名]
    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,代码行数:28,代码来源:test_preferences.py

示例2: start_firefox

# 需要导入模块: from mozprofile.profile import Profile [as 别名]
# 或者: from mozprofile.profile.Profile import set_preferences [as 别名]
    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,代码行数:21,代码来源:runtests.py

示例3: test_magic_markers

# 需要导入模块: from mozprofile.profile import Profile [as 别名]
# 或者: from mozprofile.profile.Profile import set_preferences [as 别名]
    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,代码行数:43,代码来源:test_preferences.py

示例4: do_POST

# 需要导入模块: from mozprofile.profile import Profile [as 别名]
# 或者: from mozprofile.profile.Profile import set_preferences [as 别名]
    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,代码行数:103,代码来源:selenium_proxy.py

示例5: do_POST

# 需要导入模块: from mozprofile.profile import Profile [as 别名]
# 或者: from mozprofile.profile.Profile import set_preferences [as 别名]
    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,代码行数:103,代码来源:selenium_proxy.py


注:本文中的mozprofile.profile.Profile.set_preferences方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。