Ejemplo n.º 1
0
    def __init__(self,
                 executable_path="WebKitWebDriver",
                 port=0,
                 options=None,
                 desired_capabilities=DesiredCapabilities.WEBKITGTK,
                 service_log_path=None,
                 keep_alive=False):
        """
        Creates a new instance of the WebKitGTK driver.

        Starts the service and then creates new instance of WebKitGTK Driver.

        :Args:
         - executable_path : path to the executable. If the default is used it assumes the executable is in the $PATH.
         - port : port you would like the service to run, if left as 0, a free port will be found.
         - options : an instance of WebKitGTKOptions
         - desired_capabilities : Dictionary object with desired capabilities
         - service_log_path : Path to write service stdout and stderr output.
         - keep_alive : Whether to configure RemoteConnection to use HTTP keep-alive.
        """
        if options is not None:
            capabilities = options.to_capabilities()
            capabilities.update(desired_capabilities)
            desired_capabilities = capabilities

        self.service = Service(executable_path,
                               port=port,
                               log_path=service_log_path)
        self.service.start()

        RemoteWebDriver.__init__(self,
                                 command_executor=self.service.service_url,
                                 desired_capabilities=desired_capabilities,
                                 keep_alive=keep_alive)
        self._is_remote = False
Ejemplo n.º 2
0
 def quit(self):
     """
     Closes the browser and shuts down the
     """
     try:
         RemoteWebDriver.quit(self)
     except http_client.BadStatusLine:
         pass
Ejemplo n.º 3
0
    def __init__(self,
                 executable_path="chromedriver",
                 port=0,
                 options=None,
                 service_args=None,
                 desired_capabilities=None,
                 service_log_path=None,
                 chrome_options=None,
                 keep_alive=True):
        """
        Creates a new instance of the chrome driver.

        Starts the service and then creates new instance of chrome driver.

        :Args:
         - executable_path - path to the executable. If the default is used it assumes the executable is in the $PATH
         - port - port you would like the service to run, if left as 0, a free port will be found.
         - options - this takes an instance of ChromeOptions
         - service_args - List of args to pass to the driver service
         - desired_capabilities - Dictionary object with non-browser specific
           capabilities only, such as "proxy" or "loggingPref".
         - service_log_path - Where to log information from the driver.
         - chrome_options - Deprecated argument for options
         - keep_alive - Whether to configure ChromeRemoteConnection to use HTTP keep-alive.
        """
        if chrome_options:
            warnings.warn('use options instead of chrome_options',
                          DeprecationWarning,
                          stacklevel=2)
            options = chrome_options

        if options is None:
            # desired_capabilities stays as passed in
            if desired_capabilities is None:
                desired_capabilities = self.create_options().to_capabilities()
        else:
            if desired_capabilities is None:
                desired_capabilities = options.to_capabilities()
            else:
                desired_capabilities.update(options.to_capabilities())

        self.service = Service(executable_path,
                               port=port,
                               service_args=service_args,
                               log_path=service_log_path)
        self.service.start()

        try:
            RemoteWebDriver.__init__(
                self,
                command_executor=ChromeRemoteConnection(
                    remote_server_addr=self.service.service_url,
                    keep_alive=keep_alive),
                desired_capabilities=desired_capabilities)
        except Exception:
            self.quit()
            raise
        self._is_remote = False
Ejemplo n.º 4
0
 def quit(self):
     """
     Closes the browser and shuts down the WebKitGTKDriver executable
     that is started when starting the WebKitGTKDriver
     """
     try:
         RemoteWebDriver.quit(self)
     except http_client.BadStatusLine:
         pass
     finally:
         self.service.stop()
Ejemplo n.º 5
0
 def quit(self):
     """
     Closes the browser and shuts down the ChromeDriver executable
     that is started when starting the ChromeDriver
     """
     try:
         RemoteWebDriver.quit(self)
     except Exception:
         # We don't care about the message because something probably has gone wrong
         pass
     finally:
         self.service.stop()
Ejemplo n.º 6
0
    def __init__(self, host="localhost", port=4444, desired_capabilities=DesiredCapabilities.ANDROID):
        """
        Creates a new instance of Selendroid using the WebView app

        :Args:
         - host - location of where selendroid is running
         - port - port that selendroid is running on
         - desired_capabilities: Dictionary object with capabilities
        """
        RemoteWebDriver.__init__(
            self,
            command_executor="http://%s:%d/wd/hub" % (host, port),
            desired_capabilities=desired_capabilities)
Ejemplo n.º 7
0
    def __init__(self,
                 executable_path='MicrosoftWebDriver.exe',
                 capabilities=None,
                 port=0,
                 verbose=False,
                 service_log_path=None,
                 log_path=None,
                 keep_alive=False):
        """
        Creates a new instance of the chrome driver.

        Starts the service and then creates new instance of chrome driver.

        :Args:
         - executable_path - path to the executable. If the default is used it assumes the executable is in the $PATH
         - capabilities - Dictionary object with non-browser specific
           capabilities only, such as "proxy" or "loggingPref".
         - port - port you would like the service to run, if left as 0, a free port will be found.
         - verbose - whether to set verbose logging in the service
         - service_log_path - Where to log information from the driver.
         - log_path: Deprecated argument for service_log_path
         - keep_alive - Whether to configure ChromeRemoteConnection to use HTTP keep-alive.
         """
        if log_path:
            warnings.warn('use service_log_path instead of log_path',
                          DeprecationWarning,
                          stacklevel=2)
            service_log_path = log_path

        self.port = port
        if self.port == 0:
            self.port = utils.free_port()

        self.edge_service = Service(executable_path,
                                    port=self.port,
                                    verbose=verbose,
                                    log_path=service_log_path)
        self.edge_service.start()

        if capabilities is None:
            capabilities = DesiredCapabilities.EDGE

        RemoteWebDriver.__init__(self,
                                 command_executor=RemoteConnection(
                                     'http://localhost:%d' % self.port,
                                     resolve_ip=False,
                                     keep_alive=keep_alive),
                                 desired_capabilities=capabilities)
        self._is_remote = False
Ejemplo n.º 8
0
    def quit(self):
        """Quits the driver and close every associated window."""
        try:
            RemoteWebDriver.quit(self)
        except Exception:
            # We don't care about the message because something probably has gone wrong
            pass

        if self.w3c:
            self.service.stop()
        else:
            self.binary.kill()

        if self.profile is not None:
            try:
                shutil.rmtree(self.profile.path)
                if self.profile.tempfolder is not None:
                    shutil.rmtree(self.profile.tempfolder)
            except Exception as e:
                print(str(e))
Ejemplo n.º 9
0
    def __init__(self,
                 port=0,
                 executable_path="/usr/bin/safaridriver",
                 reuse_service=False,
                 desired_capabilities=DesiredCapabilities.SAFARI,
                 quiet=False,
                 keep_alive=True,
                 service_args=None):
        """

        Creates a new Safari driver instance and launches or finds a running safaridriver service.

        :Args:
         - port - The port on which the safaridriver service should listen for new connections. If zero, a free port will be found.
         - executable_path - Path to a custom safaridriver executable to be used. If absent, /usr/bin/safaridriver is used.
         - reuse_service - If True, do not spawn a safaridriver instance; instead, connect to an already-running service that was launched externally.
         - desired_capabilities: Dictionary object with desired capabilities (Can be used to provide various Safari switches).
         - quiet - If True, the driver's stdout and stderr is suppressed.
         - keep_alive - Whether to configure SafariRemoteConnection to use
             HTTP keep-alive. Defaults to False.
         - service_args : List of args to pass to the safaridriver service
        """

        self._reuse_service = reuse_service
        self.service = Service(executable_path,
                               port=port,
                               quiet=quiet,
                               service_args=service_args)
        if not reuse_service:
            self.service.start()

        executor = SafariRemoteConnection(
            remote_server_addr=self.service.service_url, keep_alive=keep_alive)

        RemoteWebDriver.__init__(self,
                                 command_executor=executor,
                                 desired_capabilities=desired_capabilities)

        self._is_remote = False
Ejemplo n.º 10
0
    def __init__(self,
                 executable_path="phantomjs",
                 port=0,
                 desired_capabilities=DesiredCapabilities.PHANTOMJS,
                 service_args=None,
                 service_log_path=None):
        """
        Creates a new instance of the PhantomJS / Ghostdriver.

        Starts the service and then creates new instance of the driver.

        :Args:
         - executable_path - path to the executable. If the default is used it assumes the executable is in the $PATH
         - port - port you would like the service to run, if left as 0, a free port will be found.
         - desired_capabilities: Dictionary object with non-browser specific
           capabilities only, such as "proxy" or "loggingPref".
         - service_args : A List of command line arguments to pass to PhantomJS
         - service_log_path: Path for phantomjs service to log to.
        """
        warnings.warn(
            'Selenium support for PhantomJS has been deprecated, please use headless '
            'versions of Chrome or Firefox instead')
        self.service = Service(executable_path,
                               port=port,
                               service_args=service_args,
                               log_path=service_log_path)
        self.service.start()

        try:
            RemoteWebDriver.__init__(self,
                                     command_executor=self.service.service_url,
                                     desired_capabilities=desired_capabilities)
        except Exception:
            self.quit()
            raise

        self._is_remote = False
Ejemplo n.º 11
0
    def __init__(self,
                 firefox_profile=None,
                 firefox_binary=None,
                 timeout=30,
                 capabilities=None,
                 proxy=None,
                 executable_path="geckodriver",
                 options=None,
                 service_log_path="geckodriver.log",
                 firefox_options=None,
                 service_args=None,
                 desired_capabilities=None,
                 log_path=None,
                 keep_alive=True):
        """Starts a new local session of Firefox.

        Based on the combination and specificity of the various keyword
        arguments, a capabilities dictionary will be constructed that
        is passed to the remote end.

        The keyword arguments given to this constructor are helpers to
        more easily allow Firefox WebDriver sessions to be customised
        with different options.  They are mapped on to a capabilities
        dictionary that is passed on to the remote end.

        As some of the options, such as `firefox_profile` and
        `options.profile` are mutually exclusive, precedence is
        given from how specific the setting is.  `capabilities` is the
        least specific keyword argument, followed by `options`,
        followed by `firefox_binary` and `firefox_profile`.

        In practice this means that if `firefox_profile` and
        `options.profile` are both set, the selected profile
        instance will always come from the most specific variable.
        In this case that would be `firefox_profile`.  This will result in
        `options.profile` to be ignored because it is considered
        a less specific setting than the top-level `firefox_profile`
        keyword argument.  Similarily, if you had specified a
        `capabilities["moz:firefoxOptions"]["profile"]` Base64 string,
        this would rank below `options.profile`.

        :param firefox_profile: Instance of ``FirefoxProfile`` object
            or a string.  If undefined, a fresh profile will be created
            in a temporary location on the system.
        :param firefox_binary: Instance of ``FirefoxBinary`` or full
            path to the Firefox binary.  If undefined, the system default
            Firefox installation will  be used.
        :param timeout: Time to wait for Firefox to launch when using
            the extension connection.
        :param capabilities: Dictionary of desired capabilities.
        :param proxy: The proxy settings to us when communicating with
            Firefox via the extension connection.
        :param executable_path: Full path to override which geckodriver
            binary to use for Firefox 47.0.1 and greater, which
            defaults to picking up the binary from the system path.
        :param options: Instance of ``options.Options``.
        :param service_log_path: Where to log information from the driver.
        :param firefox_options: Deprecated argument for options
        :param service_args: List of args to pass to the driver service
        :param desired_capabilities: alias of capabilities. In future
            versions of this library, this will replace 'capabilities'.
            This will make the signature consistent with RemoteWebDriver.
        :param log_path: Deprecated argument for service_log_path
        :param keep_alive: Whether to configure remote_connection.RemoteConnection to use
             HTTP keep-alive.
        """
        if log_path:
            warnings.warn('use service_log_path instead of log_path',
                          DeprecationWarning,
                          stacklevel=2)
            service_log_path = log_path
        if firefox_options:
            warnings.warn('use options instead of firefox_options',
                          DeprecationWarning,
                          stacklevel=2)
            options = firefox_options
        self.binary = None
        self.profile = None
        self.service = None

        # If desired capabilities is set, alias it to capabilities.
        # If both are set ignore desired capabilities.
        if capabilities is None and desired_capabilities:
            capabilities = desired_capabilities

        if capabilities is None:
            capabilities = DesiredCapabilities.FIREFOX.copy()
        if options is None:
            options = Options()

        capabilities = dict(capabilities)

        if capabilities.get("binary"):
            self.binary = capabilities["binary"]

        # options overrides capabilities
        if options is not None:
            if options.binary is not None:
                self.binary = options.binary
            if options.profile is not None:
                self.profile = options.profile

        # firefox_binary and firefox_profile
        # override options
        if firefox_binary is not None:
            if isinstance(firefox_binary, basestring):
                firefox_binary = FirefoxBinary(firefox_binary)
            self.binary = firefox_binary
            options.binary = firefox_binary
        if firefox_profile is not None:
            if isinstance(firefox_profile, basestring):
                firefox_profile = FirefoxProfile(firefox_profile)
            self.profile = firefox_profile
            options.profile = firefox_profile

        # W3C remote
        # TODO(ato): Perform conformance negotiation

        if capabilities.get("marionette"):
            capabilities.pop("marionette")
            self.service = Service(executable_path,
                                   service_args=service_args,
                                   log_path=service_log_path)
            self.service.start()

            capabilities.update(options.to_capabilities())

            executor = FirefoxRemoteConnection(
                remote_server_addr=self.service.service_url)
            RemoteWebDriver.__init__(self,
                                     command_executor=executor,
                                     desired_capabilities=capabilities,
                                     keep_alive=True)

        # Selenium remote
        else:
            if self.binary is None:
                self.binary = FirefoxBinary()
            if self.profile is None:
                self.profile = FirefoxProfile()

            # disable native events if globally disabled
            self.profile.native_events_enabled = (
                self.NATIVE_EVENTS_ALLOWED
                and self.profile.native_events_enabled)

            if proxy is not None:
                proxy.add_to_capabilities(capabilities)

            executor = ExtensionConnection("127.0.0.1", self.profile,
                                           self.binary, timeout)
            RemoteWebDriver.__init__(self,
                                     command_executor=executor,
                                     desired_capabilities=capabilities,
                                     keep_alive=keep_alive)

        self._is_remote = False
Ejemplo n.º 12
0
    def __init__(self,
                 executable_path='IEDriverServer.exe',
                 capabilities=None,
                 port=DEFAULT_PORT,
                 timeout=DEFAULT_TIMEOUT,
                 host=DEFAULT_HOST,
                 log_level=DEFAULT_LOG_LEVEL,
                 service_log_path=DEFAULT_SERVICE_LOG_PATH,
                 options=None,
                 ie_options=None,
                 desired_capabilities=None,
                 log_file=None,
                 keep_alive=False):
        """
        Creates a new instance of the chrome driver.

        Starts the service and then creates new instance of chrome driver.

        :Args:
         - executable_path - path to the executable. If the default is used it assumes the executable is in the $PATH
         - capabilities: capabilities Dictionary object
         - port - port you would like the service to run, if left as 0, a free port will be found.
         - timeout - no longer used, kept for backward compatibility
         - host - IP address for the service
         - log_level - log level you would like the service to run.
         - service_log_path - target of logging of service, may be "stdout", "stderr" or file path.
         - options - IE Options instance, providing additional IE options
         - ie_options - Deprecated argument for options
         - desired_capabilities - alias of capabilities; this will make the signature consistent with RemoteWebDriver.
         - log_file - Deprecated argument for service_log_path
         - keep_alive - Whether to configure RemoteConnection to use HTTP keep-alive.
        """
        if log_file:
            warnings.warn('use service_log_path instead of log_file',
                          DeprecationWarning,
                          stacklevel=2)
            service_log_path = log_file
        if ie_options:
            warnings.warn('use options instead of ie_options',
                          DeprecationWarning,
                          stacklevel=2)
            options = ie_options
        self.port = port
        if self.port == 0:
            self.port = utils.free_port()
        self.host = host

        # If both capabilities and desired capabilities are set, ignore desired capabilities.
        if capabilities is None and desired_capabilities:
            capabilities = desired_capabilities

        if options is None:
            if capabilities is None:
                capabilities = self.create_options().to_capabilities()
        else:
            if capabilities is None:
                capabilities = options.to_capabilities()
            else:
                # desired_capabilities stays as passed in
                capabilities.update(options.to_capabilities())

        self.iedriver = Service(executable_path,
                                port=self.port,
                                host=self.host,
                                log_level=log_level,
                                log_file=service_log_path)

        self.iedriver.start()

        RemoteWebDriver.__init__(self,
                                 command_executor='http://localhost:%d' %
                                 self.port,
                                 desired_capabilities=capabilities,
                                 keep_alive=keep_alive)
        self._is_remote = False
Ejemplo n.º 13
0
 def quit(self):
     RemoteWebDriver.quit(self)
     self.iedriver.stop()
Ejemplo n.º 14
0
 def _wrap_value(self, value):
     if isinstance(value, EventFiringWebElement):
         return WebDriver._wrap_value(self._driver, value.wrapped_element)
     return WebDriver._wrap_value(self._driver, value)
Ejemplo n.º 15
0
 def quit(self):
     RemoteWebDriver.quit(self)
     self.edge_service.stop()
Ejemplo n.º 16
0
    def __init__(self,
                 device_password,
                 bb_tools_dir=None,
                 hostip='169.254.0.1',
                 port=1338,
                 desired_capabilities={}):
        remote_addr = 'http://{}:{}'.format(hostip, port)

        filename = 'blackberry-deploy'
        if platform.system() == "Windows":
            filename += '.bat'

        if bb_tools_dir is not None:
            if os.path.isdir(bb_tools_dir):
                bb_deploy_location = os.path.join(bb_tools_dir, filename)
                if not os.path.isfile(bb_deploy_location):
                    raise WebDriverException(
                        'Invalid blackberry-deploy location: {}'.format(
                            bb_deploy_location))
            else:
                raise WebDriverException(
                    'Invalid blackberry tools location, must be a directory: {}'
                    .format(bb_tools_dir))
        else:
            bb_deploy_location = filename
        """
        Now launch the BlackBerry browser before allowing anything else to run.
        """
        try:
            launch_args = [
                bb_deploy_location, '-launchApp',
                str(hostip), '-package-name', 'sys.browser', '-package-id',
                'gYABgJYFHAzbeFMPCCpYWBtHAm0', '-password',
                str(device_password)
            ]

            with open(os.devnull, 'w') as fp:
                p = subprocess.Popen(launch_args, stdout=fp)

            returncode = p.wait()

            if returncode == 0:
                # wait for the BlackBerry10 browser to load.
                is_running_args = [
                    bb_deploy_location, '-isAppRunning',
                    str(hostip), '-package-name', 'sys.browser', '-package-id',
                    'gYABgJYFHAzbeFMPCCpYWBtHAm0', '-password',
                    str(device_password)
                ]

                WebDriverWait(None, LOAD_TIMEOUT)\
                    .until(lambda x: subprocess.check_output(is_running_args)
                           .find('result::true'),
                           message='waiting for BlackBerry10 browser to load')

                RemoteWebDriver.__init__(
                    self,
                    command_executor=remote_addr,
                    desired_capabilities=desired_capabilities)
            else:
                raise WebDriverException(
                    'blackberry-deploy failed to launch browser')
        except Exception as e:
            raise WebDriverException(
                'Something went wrong launching blackberry-deploy',
                stacktrace=getattr(e, 'stacktrace', None))