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


Python SimpleWebServer.stop方法代码示例

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


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

示例1: setup_method

# 需要导入模块: from selenium.test.selenium.webdriver.common.webserver import SimpleWebServer [as 别名]
# 或者: from selenium.test.selenium.webdriver.common.webserver.SimpleWebServer import stop [as 别名]
class TestOptions:

    def setup_method(self, method):
        self.webserver = SimpleWebServer()
        self.webserver.start()

    def test_we_can_pass_options(self):
        capabilities = {'marionette': True}
        options = Options()
        self.driver = webdriver.Firefox(
            capabilities=capabilities,
            firefox_options=options)
        self.driver.get(self.webserver.where_is('formPage.html'))
        self.driver.find_element_by_id("cheese")

    def teardown_method(self, method):
        try:
            self.driver.quit()
        except:
            pass  # Don't care since we may have killed the browser above
        self.webserver.stop()
开发者ID:AkosLukacs,项目名称:selenium,代码行数:23,代码来源:mn_options_tests.py

示例2: setup_method

# 需要导入模块: from selenium.test.selenium.webdriver.common.webserver import SimpleWebServer [as 别名]
# 或者: from selenium.test.selenium.webdriver.common.webserver.SimpleWebServer import stop [as 别名]
class TestFirefoxProfile:
    
    def setup_method(self, method):
        self.driver = webdriver.Firefox() 
        self.webserver = SimpleWebServer()
        self.webserver.start()

    def test_that_we_can_accept_a_profile(self):
        self.profile1 = webdriver.FirefoxProfile()
        self.profile1.set_preference("startup.homepage_welcome_url", 
            "%s" % "http://localhost:%d/%s.html" % (self.webserver.port, "simpleTest"))
        self.profile1.update_preferences()

        self.profile2 = webdriver.FirefoxProfile(self.profile1.path)
        self.driver = webdriver.Firefox(firefox_profile=self.profile2)
        title = self.driver.title
        assert "Hello WebDriver" == title

    def test_that_we_delete_the_profile(self):
        path = self.driver.firefox_profile.path
        self.driver.quit()
        assert not os.path.exists(path)

    def teardown_method(self, method):
        try:
            self.driver.quit()
        except:
            pass #don't care since we may have killed the browser above
        self.webserver.stop()

    def _pageURL(self, name):
        return "http://localhost:%d/%s.html" % (self.webserver.port, name)

    def _loadSimplePage(self):
        self._loadPage("simpleTest")

    def _loadPage(self, name):
        self.driver.get(self._pageURL(name))
开发者ID:j0hnsmith,项目名称:Selenium2,代码行数:40,代码来源:test_ff_profile_tests.py

示例3: setup_method

# 需要导入模块: from selenium.test.selenium.webdriver.common.webserver import SimpleWebServer [as 别名]
# 或者: from selenium.test.selenium.webdriver.common.webserver.SimpleWebServer import stop [as 别名]

#.........这里部分代码省略.........

    def test_that_we_delete_the_profile(self):
        path = self.driver.firefox_profile.path
        self.driver.quit()
        assert not os.path.exists(path)

    def test_profiles_do_not_share_preferences(self):
        self.profile1 = webdriver.FirefoxProfile()
        self.profile1.accept_untrusted_certs = False
        self.profile2 = webdriver.FirefoxProfile()
        # Default is true. Should remain so.
        assert self.profile2.default_preferences["webdriver_accept_untrusted_certs"] == True

    def test_none_proxy_is_set(self):
        # The setup gave us a browser but we dont need it
        self.driver.quit()

        self.profile = webdriver.FirefoxProfile()
        proxy = None

        try:
            self.profile.set_proxy(proxy)
            assert False, "exception after passing empty proxy is expected"
        except ValueError as e:
            pass

        assert "network.proxy.type" not in self.profile.default_preferences

    def test_unspecified_proxy_is_set(self):
        # The setup gave us a browser but we dont need it
        self.driver.quit()

        self.profile = webdriver.FirefoxProfile()
        proxy = Proxy()

        self.profile.set_proxy(proxy)

        assert "network.proxy.type" not in self.profile.default_preferences

    def test_manual_proxy_is_set_in_profile(self):
        # The setup gave us a browser but we dont need it
        self.driver.quit()

        self.profile = webdriver.FirefoxProfile()
        proxy = Proxy()
        proxy.no_proxy = 'localhost, foo.localhost'
        proxy.http_proxy = 'some.url:1234'
        proxy.ftp_proxy = None
        proxy.sslProxy = 'some2.url'

        self.profile.set_proxy(proxy)

        assert self.profile.default_preferences["network.proxy.type"] == ProxyType.MANUAL['ff_value']
        assert self.profile.default_preferences["network.proxy.no_proxies_on"] == 'localhost, foo.localhost'
        assert self.profile.default_preferences["network.proxy.http"] == 'some.url'
        assert self.profile.default_preferences["network.proxy.http_port"] == 1234
        assert self.profile.default_preferences["network.proxy.ssl"] == 'some2.url'
        assert "network.proxy.ssl_port" not in self.profile.default_preferences
        assert "network.proxy.ftp" not in self.profile.default_preferences

    def test_pac_proxy_is_set_in_profile(self):
        # The setup gave us a browser but we dont need it
        self.driver.quit()

        self.profile = webdriver.FirefoxProfile()
        proxy = Proxy()
        proxy.proxy_autoconfig_url = 'http://some.url:12345/path'

        self.profile.set_proxy(proxy)

        assert self.profile.default_preferences["network.proxy.type"] == ProxyType.PAC['ff_value']
        assert self.profile.default_preferences["network.proxy.autoconfig_url"] == 'http://some.url:12345/path'

    def test_autodetect_proxy_is_set_in_profile(self):
        # The setup gave us a browser but we dont need it
        self.driver.quit()

        self.profile = webdriver.FirefoxProfile()
        proxy = Proxy()
        proxy.auto_detect = True

        self.profile.set_proxy(proxy)

        assert self.profile.default_preferences["network.proxy.type"] == ProxyType.AUTODETECT['ff_value']

    def teardown_method(self, method):
        try:
            self.driver.quit()
        except:
            pass #don't care since we may have killed the browser above
        self.webserver.stop()

    def _pageURL(self, name):
        return self.webserver.where_is(name + '.html')

    def _loadSimplePage(self):
        self._loadPage("simpleTest")

    def _loadPage(self, name):
        self.driver.get(self._pageURL(name))
开发者ID:217,项目名称:selenium,代码行数:104,代码来源:ff_profile_tests.py

示例4: setup_method

# 需要导入模块: from selenium.test.selenium.webdriver.common.webserver import SimpleWebServer [as 别名]
# 或者: from selenium.test.selenium.webdriver.common.webserver.SimpleWebServer import stop [as 别名]

#.........这里部分代码省略.........
        assert "Hello WebDriver" == title

    def test_that_prefs_are_written_in_the_correct_format(self):
        # The setup gave us a browser but we dont need it
        self.driver.quit()

        profile = webdriver.FirefoxProfile()
        profile.set_preference("sample.preference", "hi there")
        profile.update_preferences()

        assert '"hi there"' == profile.default_preferences["sample.preference"]

        encoded = profile.encoded
        decoded = base64.decodestring(encoded)
        fp = StringIO(decoded)
        zip = zipfile.ZipFile(fp, "r")
        for entry in zip.namelist():
            if entry.endswith("user.js"):
                user_js = zip.read(entry)
                for line in user_js.splitlines():
                    if line.startswith('user_pref("sample.preference",'):
                        assert True == line.endswith('"hi there");')
            # there should be only one user.js
            break
        fp.close()

    def test_that_unicode_prefs_are_written_in_the_correct_format(self):
        # The setup gave us a browser but we dont need it
        self.driver.quit()

        profile = webdriver.FirefoxProfile()
        profile.set_preference("sample.preference.2", u"hi there")
        profile.update_preferences()

        assert '"hi there"' == profile.default_preferences["sample.preference.2"]

        encoded = profile.encoded
        decoded = base64.decodestring(encoded)
        fp = StringIO(decoded)
        zip = zipfile.ZipFile(fp, "r")
        for entry in zip.namelist():
            if entry.endswith("user.js"):
                user_js = zip.read(entry)
                for line in user_js.splitlines():
                    if line.startswith('user_pref("sample.preference.2",'):
                        assert True == line.endswith('"hi there");')
            # there should be only one user.js
            break
        fp.close()


    def test_that_we_delete_the_profile(self):
        path = self.driver.firefox_profile.path
        self.driver.quit()
        assert not os.path.exists(path)

    def test_profiles_do_not_share_preferences(self):
        self.profile1 = webdriver.FirefoxProfile()
        self.profile1.accept_untrusted_certs = False
        self.profile2 = webdriver.FirefoxProfile()
        # Default is true. Should remain so.
        assert self.profile2.default_preferences["webdriver_accept_untrusted_certs"] == 'true'

    def test_sets_http_proxy(self):
        self.driver.quit()

        profile = webdriver.FirefoxProfile()
        proxy = Proxy()
        proxy.http_proxy = 'http://test.hostname:1234'
        profile.set_proxy(proxy)
        assert profile.default_preferences["network.proxy.type"] == str(ProxyType.MANUAL['ff_value'])
        assert profile.default_preferences["network.proxy.http"] == '"test.hostname"'
        assert profile.default_preferences["network.proxy.http_port"] == '1234'

    def test_sets_ssl_proxy(self):
        self.driver.quit()

        profile = webdriver.FirefoxProfile()
        proxy = Proxy()
        proxy.ssl_proxy = 'https://test.hostname:1234'
        profile.set_proxy(proxy)
        assert profile.default_preferences["network.proxy.type"] == str(ProxyType.MANUAL['ff_value'])
        assert profile.default_preferences["network.proxy.ssl"] == '"test.hostname"'
        assert profile.default_preferences["network.proxy.ssl_port"] == '1234'

    def teardown_method(self, method):
        try:
            self.driver.quit()
        except:
            pass #don't care since we may have killed the browser above
        self.webserver.stop()

    def _pageURL(self, name):
        return "http://localhost:%d/%s.html" % (self.webserver.port, name)

    def _loadSimplePage(self):
        self._loadPage("simpleTest")

    def _loadPage(self, name):
        self.driver.get(self._pageURL(name))
开发者ID:AlexandraChiorean,项目名称:Selenium2,代码行数:104,代码来源:ff_profile_tests.py

示例5: testCopyFromSource

# 需要导入模块: from selenium.test.selenium.webdriver.common.webserver import SimpleWebServer [as 别名]
# 或者: from selenium.test.selenium.webdriver.common.webserver.SimpleWebServer import stop [as 别名]
        driver.add_cookie(utils.convert_cookie_to_json(cookie))
        self.assertEquals(cookie, driver.get_cookies()[0])
        driver.quit()
        driver = webdriver.connect('firefox')
        self.assertEquals([], driver.get_cookies())
        driver.quit()

    def testCopyFromSource(self):
        dir_name = tempfile.mkdtemp()
        self._create_dummy_file(dir_name)
        profile = FirefoxProfile()
        profile.copy_profile_source(dir_name)
        profile_dir = profile.path
        dst_pref_file = open(os.path.join(profile_dir, self.DUMMY_FILE_NAME))
        content = dst_pref_file.read()
        self.assertEquals(self.DUMMY_FILE_CONTENT, content)

    def _create_dummy_file(self, dir_name):
        pref_file = open(os.path.join(dir_name, self.DUMMY_FILE_NAME), "w")
        pref_file.write(self.DUMMY_FILE_CONTENT)
        pref_file.close()

if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO)
    webserver = SimpleWebServer(8000)
    webserver.start()
    try:
        unittest.main()
    finally:
        webserver.stop()
开发者ID:Escobita,项目名称:selenium,代码行数:32,代码来源:profile_tests.py


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