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


Python utils.is_connectable函数代码示例

本文整理汇总了Python中selenium.webdriver.common.utils.is_connectable函数的典型用法代码示例。如果您正苦于以下问题:Python is_connectable函数的具体用法?Python is_connectable怎么用?Python is_connectable使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: get_driver

    def get_driver(self):
        """
        Only creates the driver if not present and returns it.

        :return: ``WebDriver`` instance.
        """

        # Dedicated mode
        if hasattr(settings, 'CRAWLABLE_PHANTOMJS_DEDICATED_MODE') and settings.CRAWLABLE_PHANTOMJS_DEDICATED_MODE:
            if not self._web_driver:
                self._web_driver = DedicatedWebDriver(
                    port=getattr(settings, 'CRAWLABLE_PHANTOMJS_DEDICATED_PORT', 8910)
                )
            elif not is_connectable(self._web_driver.service.port):
                raise RuntimeError('Cannot connect to dedicated PhantomJS instance on: %s' %
                                    self._web_driver.service.service_url)
        # Instance based mode (more for testing purposes). When debugging, you can even replace the PhantomJS webdriver
        # with firefox and remove the arguments to the web driver constructor below.
        else:
            if not self._web_driver:
                self._web_driver = WebDriver(service_args=self.service_args)
            elif not is_connectable(self._web_driver.service.port):
                self._web_driver.service.stop()
                self._web_driver = WebDriver(service_args=self.service_args)

        # Make sure it doesn't time out.
        self._web_driver.set_script_timeout(30)

        return self._web_driver
开发者ID:jfterpstra,项目名称:onepercentclub-site,代码行数:29,代码来源:middleware.py

示例2: start

    def start(self):
        """
        Starts the ChromeDriver Service.

        :Exceptions:
         - WebDriverException : Raised either when it can't start the service
           or when it can't connect to the service
        """
        env = self.env or os.environ
        try:
            self.process = subprocess.Popen([
              self.path,
              "--port=%d" % self.port] +
              self.service_args, env=env, stdout=PIPE, stderr=PIPE)
        except:
            raise WebDriverException(
                "'" + os.path.basename(self.path) + "' executable needs to be \
                available in the path. Please look at \
                http://docs.seleniumhq.org/download/#thirdPartyDrivers \
                and read up at \
                https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver")
        count = 0
        while not utils.is_connectable(self.port):
            count += 1
            time.sleep(1)
            if count == 30:
                raise WebDriverException("Can not connect to the '" +
                                         os.path.basename(self.path) + "'")
开发者ID:bilalnazer,项目名称:selenium,代码行数:28,代码来源:service.py

示例3: start

    def start(self):
        """
        Starts the GeckoDriver "wires" Service.

        :Exceptions:
         - WebDriverException : Raised either when it can't start the service
           or when it can't connect to the service
        """
        env = self.env or os.environ
        self.log_file = file("geckodriver.log", "w")
        try:
            #import pdb; pdb.set_trace()
            self.process = subprocess.Popen([
              self.path,
              "-b", self.firefox_binary, '--webdriver-port', "%d" % self.port],
              env=env, stdout=self.log_file, stderr=self.log_file)
        except Exception as e:
            raise WebDriverException(
                "'" + os.path.basename(self.path) + "' executable needs to be \
                available in the path.\n %s" % str(e))
        count = 0
        while not utils.is_connectable(self.port):
            count += 1
            time.sleep(1)
            if count == 30:
                raise WebDriverException("Can not connect to the '" +
                                         os.path.basename(self.path) + "'")
开发者ID:DhamodharanGH,项目名称:local,代码行数:27,代码来源:service.py

示例4: _wait_until_connectable

    def _wait_until_connectable(self):
        """Blocks until the extension is connectable in the firefox.

        The base class implements this by checking utils.is_connectable() every
        second (sleep_for == 1) and failing after 30 attempts (max_tries ==
        30). Expriments showed that once a firefox can't be connected to, it's
        better to start a new one instead so we don't wait 30 seconds to fail
        in the end (the caller should catch WebDriverException and starts a new
        firefox).
        """
        connectable = False
        max_tries = 6
        sleep_for = 1
        for count in range(1, max_tries):
            connectable = utils.is_connectable(self.profile.port)
            if connectable:
                break
            logger.debug('Cannot connect to process %d with port: %d, count %d'
                         % (self.process.pid, self.profile.port, count))
            if self.process.poll() is not None:
                # Browser has exited
                raise selenium_exceptions.WebDriverException("The browser appears to have exited "
                      "before we could connect. If you specified a log_file in "
                      "the FirefoxBinary constructor, check it for details.")
            time.sleep(sleep_for)
        if not connectable:
            self.kill()
            raise selenium_exceptions.WebDriverException(
                      "Can't load the profile. Profile "
                      "dir: %s. If you specified a log_file in the "
                      "FirefoxBinary constructor, check it for details." %
                      self.profile.profile_dir)
        return connectable
开发者ID:ikornaselur,项目名称:sst,代码行数:33,代码来源:browsers.py

示例5: stop

    def stop(self):
        """
        Tells the EdgeDriver to stop and cleans up the process
        """
        #If its dead dont worry
        if self.process is None:
            return

        #Tell the Server to die!
        try:
            from urllib import request as url_request
        except ImportError:
            import urllib2 as url_request

        url_request.urlopen("http://127.0.0.1:%d/shutdown" % self.port)
        count = 0
        while utils.is_connectable(self.port):
            if count == 30:
               break
            count += 1
            time.sleep(1)

        #Tell the Server to properly die in case
        try:
            if self.process:
                self.process.stdout.close()
                self.process.stderr.close()
                self.process.kill()
                self.process.wait()
        except WindowsError:
            # kill may not be available under windows environment
            pass
开发者ID:nvonop,项目名称:selenium,代码行数:32,代码来源:service.py

示例6: start

    def start(self):
        """
        Starts PhantomJS with GhostDriver.

        :Exceptions:
         - WebDriverException : Raised either when it can't start the service
           or when it can't connect to the service
        """
        try:
            '''
            self.process = subprocess.Popen(self.service_args, stdin=subprocess.PIPE,
                                            close_fds=True, stdout=self._log,
                                            stderr=self._log)
            '''
            self.process = subprocess.Popen(self.service_args,
                                            stdout=self._log, stderr=self._log)                             

        except Exception as e:
            raise WebDriverException("Unable to start phantomjs with ghostdriver.", e)
        count = 0
        while not utils.is_connectable(self.port):
            count += 1
            time.sleep(1)
            if count == 30:
                 raise WebDriverException("Can not connect to GhostDriver")
开发者ID:ktan2020,项目名称:legacy-automation,代码行数:25,代码来源:service.py

示例7: __init__

    def __init__(self, port=DEFAULT_PORT, timeout=DEFAULT_TIMEOUT):
        self.port = port
        if self.port == 0:
            self.port = utils.free_port()

        # Create IE Driver instance of the unmanaged code
        try:
            self.iedriver = CDLL(os.path.join(os.path.dirname(__file__),"win32", "IEDriver.dll"))
        except WindowsError:
            try:
                self.iedriver = CDLL(os.path.join(os.path.dirname(__file__),"x64", "IEDriver.dll"))
            except WindowsError:
                raise WebDriverException("Unable to load the IEDriver.dll component")
        self.ptr = self.iedriver.StartServer(self.port)

        seconds = 0
        while not utils.is_connectable(self.port):
            seconds += 1
            if seconds > DEFAULT_TIMEOUT:
                raise RuntimeError("Unable to connect to IE")
            time.sleep(1)

        RemoteWebDriver.__init__(
            self,
            command_executor='http://localhost:%d' % self.port,
            desired_capabilities=DesiredCapabilities.INTERNETEXPLORER)
开发者ID:hhakkala,项目名称:robotframework-selenium2library-boilerplate,代码行数:26,代码来源:webdriver.py

示例8: stop

    def stop(self):
        """ 
        Tells the ChromeDriver to stop and cleans up the process
        """
        #If its dead dont worry
        if self.process is None:
            return

        #Tell the Server to die!
        import urllib2
        try:
            urllib2.urlopen("http://127.0.0.01:%d/shutdown" % self.port)

            # make sure that shutdown worked by testing the port has gone away
            count = 0
            while utils.is_connectable(self.port):
                if count == 30:
                   break 
                count += 1
                time.sleep(1)
        finally:
        #Tell the Server to properly die in case
            if self.process:
                try:
                    os.kill(self.process.pid, signal.SIGTERM)
                    os.wait()
                except AttributeError:
                    # kill may not be available under windows environment
                    pass
开发者ID:DreamYa0,项目名称:PythonProject,代码行数:29,代码来源:service.py

示例9: start

    def start(self):
        """
        Starts the SafariDriver Service.

        :Exceptions:
         - WebDriverException : Raised either when it can't start the service
           or when it can't connect to the service
        """
        kwargs = dict()
        if self.quiet:
            devnull_out = open(devnull, 'w')
            kwargs.update(stdout=devnull_out,
                          stderr=devnull_out)
        try:
            self.process = subprocess.Popen(["java", "-jar", self.path, "-port", "%s" % self.port],
                                            **kwargs)
        except:
            raise WebDriverException(
                "SafariDriver executable needs to be available in the path.")
        time.sleep(10)
        count = 0
        while not utils.is_connectable(self.port):
            count += 1
            time.sleep(1)
            if count == 30:
                raise WebDriverException("Can not connect to the SafariDriver")
开发者ID:Athsheep,项目名称:Flask_Web_Development,代码行数:26,代码来源:service.py

示例10: start

 def start(self):
     """ Starts the ChromeDriver Service. 
         @Exceptions
             WebDriverException : Raised either when it can't start the service
                 or when it can't connect to the service"""
     try:
         self.process = subprocess.Popen([self.path, "--port=%d" % self.port], stdout=PIPE, stderr=PIPE)
     except:
         raise WebDriverException(self.MISSING_TEXT)
     count = 0
     while not utils.is_connectable(self.port):
         count += 1
         time.sleep(1)
         if count == 30:
             raise WebDriverException("Can not connect to the ChromeDriver")
开发者ID:hali4ka,项目名称:robotframework-selenium2library,代码行数:15,代码来源:service.py

示例11: _wait_until_connectable

 def _wait_until_connectable(self):
     """Blocks until the extension is connectable in the firefox."""
     count = 0
     while not utils.is_connectable(self.profile.port):
         if self.process.poll() is not None:
             # Browser has exited
             raise WebDriverException("The browser appears to have exited "
                   "before we could connect. If you specified a log_file in "
                   "the FirefoxBinary constructor, check it for details.")
         if count == 30:
             self.kill()
             raise WebDriverException("Can't load the profile. Profile "
                   "Dir: %s If you specified a log_file in the "
                   "FirefoxBinary constructor, check it for details.")
         count += 1
         time.sleep(1)
     return True
开发者ID:217,项目名称:selenium,代码行数:17,代码来源:firefox_binary.py

示例12: start

    def start(self):
        """
        Starts PhantomJS with GhostDriver.

        :exception WebDriverException: Raised either when it can't start the service
                                        or when it can't connect to the service.
        """
        try:
            self.process = subprocess.Popen(self.pre_command + self.service_args, stdin=subprocess.PIPE,
                                            close_fds=platform.system() != 'Windows',
                                            stdout=self._log, stderr=self._log)
        except Exception as e:
            raise WebDriverException("Unable to start phantomjs with ghostdriver: %s" % e)
        count = 0
        while not utils.is_connectable(self.port):
            count += 1
            time.sleep(1)
            if count == 30:
                raise WebDriverException("Can not connect to GhostDriver on port {}".format(self.port))
开发者ID:PumucklOnTheAir,项目名称:TestFramework,代码行数:19,代码来源:service_phantomjs_extended.py

示例13: start

 def start(self):
     """
     Starts the OperaDriver Service. 
     
     :Exceptions:
      - WebDriverException : Raised either when it can't start the service
        or when it can't connect to the service
     """
     try:
         self.process = subprocess.Popen(["java", "-jar", self.path, "-port", "%s" % self.port])
     except:
         raise WebDriverException(
             "OperaDriver executable needs to be available in the path.")
     time.sleep(10)
     count = 0
     while not utils.is_connectable(self.port):
         count += 1
         time.sleep(1)
         if count == 30:
              raise WebDriverException("Can not connect to the OperaDriver")
开发者ID:AlfZombie,项目名称:selenium,代码行数:20,代码来源:service.py

示例14: start

    def start(self):
        """
        Starts the ChromeDriver Service.

        :Exceptions:
         - WebDriverException : Raised either when it cannot find the
           executable, when it does not have permissions for the
           executable, or when it cannot connect to the service.
         - Possibly other Exceptions in rare circumstances (OSError, etc).
        """
        env = self.env or os.environ
        try:
            self.process = subprocess.Popen([
              self.path,
              "--port=%d" % self.port] +
              self.service_args, env=env, stdout=PIPE, stderr=PIPE)
        except OSError as err:
            docs_msg = "Please see " \
                   "https://sites.google.com/a/chromium.org/chromedriver/home"
            if err.errno == errno.ENOENT:
                raise WebDriverException(
                    "'%s' executable needs to be in PATH. %s" % (
                        os.path.basename(self.path), docs_msg)
                )
            elif err.errno == errno.EACCES:
                raise WebDriverException(
                    "'%s' executable may have wrong permissions. %s" % (
                        os.path.basename(self.path), docs_msg)
                )
            else:
                raise
        count = 0
        while not utils.is_connectable(self.port):
            count += 1
            time.sleep(1)
            if count == 30:
                raise WebDriverException("Can not connect to the '" +
                                         os.path.basename(self.path) + "'")
开发者ID:217,项目名称:selenium,代码行数:38,代码来源:service.py

示例15: start

    def start(self):
        """
        Starts the EdgeDriver Service.

        :Exceptions:
         - WebDriverException : Raised either when it can't start the service
           or when it can't connect to the service
        """
        try:
            cmd = [self.path, "--port=%d" % self.port]
            self.process = subprocess.Popen(cmd,
                    stdout=PIPE, stderr=PIPE)
        except TypeError:
            raise
        except:
            raise WebDriverException(
                "The EdgeDriver executable needs to be available in the path. "
                "Please download from http://go.microsoft.com/fwlink/?LinkId=619687 ")
        count = 0
        while not utils.is_connectable(self.port):
            count += 1
            time.sleep(1)
            if count == 30:
                 raise WebDriverException("Can not connect to the EdgeDriver")
开发者ID:DhamodharanGH,项目名称:local,代码行数:24,代码来源:service.py


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