Ejemplo n.º 1
0
    def __create_remote_webdriver_from_config(self, testname=None):
        '''
        Reads the config value for browser type.
        '''
        desired_capabilities = self._generate_desired_capabilities(testname)

        remote_url = self._config_reader.get(
            WebDriverFactory.REMOTE_URL_CONFIG)

        # Instantiate remote webdriver.
        driver = webdriver.Remote(desired_capabilities=desired_capabilities,
                                  command_executor=remote_url)

        # Log IP Address of node if configured, so it can be used to
        # troubleshoot issues if they occur.
        log_driver_props = \
            self._config_reader.get(
                WebDriverFactory.LOG_REMOTEDRIVER_PROPS, default_value=False
            ) in [True, "true", "TRUE", "True"]
        if "wd/hub" in remote_url and log_driver_props:
            try:
                grid_addr = remote_url[:remote_url.index("wd/hub")]
                info_request_response = urllib2.urlopen(
                    grid_addr + "grid/api/testsession?session=" +
                    driver.session_id, "", 5000)
                node_info = info_request_response.read()
                _wtflog.info(
                    u("RemoteWebdriver using node: ") + u(node_info).strip())
            except:
                # Unable to get IP Address of remote webdriver.
                # This happens with many 3rd party grid providers as they don't want you accessing info on nodes on
                # their internal network.
                pass

        return driver
Ejemplo n.º 2
0
    def __init__(self, server_address, username, password):
        """
        Constructor
        
        Args:
            server_address (str): Email Server address.
            username (str): Username
            password (str): Password

        """
        _wtflog.info("connecting to %s, using %s:%s", server_address, username, password)
        self._mail = imaplib.IMAP4_SSL(server_address)
        self._mail.login(username, password)
        _wtflog.info("connected.")
Ejemplo n.º 3
0
    def __init__(self, server_address, username, password):
        """
        Constructor

        Args:
            server_address (str): Email Server address.
            username (str): Username
            password (str): Password

        """
        _wtflog.info("connecting to %s, using %s:%s", server_address, username,
                     password)
        self._mail = imaplib.IMAP4_SSL(server_address)
        self._mail.login(username, password)
        _wtflog.info("connected.")
Ejemplo n.º 4
0
 def clean_up_webdrivers(self):
     '''
     Clean up webdrivers created during execution.
     '''
     # Quit webdrivers.
     _wtflog.info("WebdriverManager : Cleaning up webdrivers")
     try:
         if self.__use_shutdown_hook:
             for key in self.__registered_drivers.keys():
                 for driver in self.__registered_drivers[key]:
                     try:
                         _wtflog.debug("Closing webdriver for thread: %s", key)
                         driver.quit()
                     except:
                         pass
     except:
         pass
Ejemplo n.º 5
0
 def clean_up_webdrivers(self):
     '''
     Clean up webdrivers created during execution.
     '''
     # Quit webdrivers.
     _wtflog.info("WebdriverManager: Cleaning up webdrivers")
     try:
         if self.__use_shutdown_hook:
             for key in self.__registered_drivers.keys():
                 for driver in self.__registered_drivers[key]:
                     try:
                         _wtflog.debug(
                             "Shutdown hook closing Webdriver for thread: %s", key)
                         driver.quit()
                     except:
                         pass
     except:
         pass
Ejemplo n.º 6
0
    def __create_remote_webdriver_from_config(self, testname=None):
        '''
        Reads the config value for browser type.
        '''
        desired_capabilities = self._generate_desired_capabilities(testname)
        
        remote_url = self._config_reader.get(
            WebDriverFactory.REMOTE_URL_CONFIG)

        # Instantiate remote webdriver.
        driver = webdriver.Remote(
            desired_capabilities=desired_capabilities,
            command_executor=remote_url
        )

        # Log IP Address of node if configured, so it can be used to
        # troubleshoot issues if they occur.
        log_driver_props = \
            self._config_reader.get(
                WebDriverFactory.LOG_REMOTEDRIVER_PROPS, default_value=False
            ) in [True, "true", "TRUE", "True"]
        if "wd/hub" in remote_url and log_driver_props:
            try:
                grid_addr = remote_url[:remote_url.index("wd/hub")]
                info_request_response = urllib2.urlopen(
                    grid_addr + "grid/api/testsession?session=" + driver.session_id, "", 5000)
                node_info = info_request_response.read()
                _wtflog.info(
                    u("RemoteWebdriver using node: ") + u(node_info).strip())
            except:
                # Unable to get IP Address of remote webdriver.
                # This happens with many 3rd party grid providers as they don't want you accessing info on nodes on
                # their internal network.
                pass

        return driver
Ejemplo n.º 7
0
    def __create_remote_webdriver_from_config(self, testname=None):
        '''
        Reads the config value for browser type.
        '''
        browser_type = self._config_reader.get(
            WebDriverFactory.BROWSER_TYPE_CONFIG)
        remote_url = self._config_reader.get(
            WebDriverFactory.REMOTE_URL_CONFIG)

        browser_constant_dict = {WebDriverFactory.HTMLUNIT: DesiredCapabilities.HTMLUNIT,
                                 WebDriverFactory.HTMLUNITWITHJS: DesiredCapabilities.HTMLUNITWITHJS,
                                 WebDriverFactory.ANDROID: DesiredCapabilities.ANDROID,
                                 WebDriverFactory.CHROME: DesiredCapabilities.CHROME,
                                 WebDriverFactory.FIREFOX: DesiredCapabilities.FIREFOX,
                                 WebDriverFactory.INTERNETEXPLORER: DesiredCapabilities.INTERNETEXPLORER,
                                 WebDriverFactory.IPAD: DesiredCapabilities.IPAD,
                                 WebDriverFactory.IPHONE: DesiredCapabilities.IPHONE,
                                 WebDriverFactory.OPERA: DesiredCapabilities.OPERA,
                                 WebDriverFactory.SAFARI: DesiredCapabilities.SAFARI,
                                 WebDriverFactory.PHANTOMJS: DesiredCapabilities.PHANTOMJS}

        try:
            # Get a copy of the desired capabilities object. (to avoid
            # overwriting the global.)
            desired_capabilities = browser_constant_dict[browser_type].copy()
        except KeyError:
            raise TypeError(
                u("Unsupported Browser Type {0}").format(browser_type))

        # Get additional desired properties from config file and add them in.
        other_desired_capabilities = self._config_reader.get(
            WebDriverFactory.DESIRED_CAPABILITIES_CONFIG)

        for prop in other_desired_capabilities:
            value = other_desired_capabilities[prop]

            if type(other_desired_capabilities[prop]) is dict:
                # do some recursive call to flatten this setting.
                self.__flatten_capabilities(
                    desired_capabilities, prop, other_desired_capabilities[prop])
            else:  # Handle has a single string value.
                if isinstance(value, basestring):
                    desired_capabilities[prop] = value

                # Version is specified as a string, but we'll allow user to use
                # an int for convenience.
                elif prop == "version":
                    desired_capabilities[prop] = str(value)

                else:
                    desired_capabilities[prop] = value

        # Set the test name property if specified in the WTF_TESTNAME var.
        try:
            test_name = self._config_reader.get("TESTNAME")
            desired_capabilities['name'] = test_name
        except KeyError:
            pass  # No test name is specified, use the default.

        # Append optional testname postfix if supplied.
        if testname:
            if desired_capabilities['name']:
                desired_capabilities['name'] += "-" + testname
            else:
                # handle case where name is not specified.
                desired_capabilities['name'] = testname

        # Instantiate remote webdriver.
        driver = webdriver.Remote(
            desired_capabilities=desired_capabilities,
            command_executor=remote_url
        )

        # Log IP Address of node if configured, so it can be used to
        # troubleshoot issues if they occur.
        log_driver_props = \
            self._config_reader.get(
                WebDriverFactory.LOG_REMOTEDRIVER_PROPS, default_value=False
            ) in [True, "true", "TRUE", "True"]
        if "wd/hub" in remote_url and log_driver_props:
            try:
                grid_addr = remote_url[:remote_url.index("wd/hub")]
                info_request_response = urllib2.urlopen(
                    grid_addr + "grid/api/testsession?session=" + driver.session_id, "", 5000)
                node_info = info_request_response.read()
                _wtflog.info(
                    u("RemoteWebdriver using node: ") + u(node_info).strip())
            except:
                # Unable to get IP Address of remote webdriver.
                # This happens with many 3rd party grid providers as they don't want you accessing info on nodes on
                # their internal network.
                pass

        return driver
Ejemplo n.º 8
0
    def __create_remote_webdriver_from_config(self, testname=None):
        '''
        Reads the config value for browser type.
        '''
        browser_type = self._config_reader.get(
            WebDriverFactory.BROWSER_TYPE_CONFIG)
        remote_url = self._config_reader.get(
            WebDriverFactory.REMOTE_URL_CONFIG)

        browser_constant_dict = {
            WebDriverFactory.HTMLUNIT: DesiredCapabilities.HTMLUNIT,
            WebDriverFactory.HTMLUNITWITHJS:
            DesiredCapabilities.HTMLUNITWITHJS,
            WebDriverFactory.ANDROID: DesiredCapabilities.ANDROID,
            WebDriverFactory.CHROME: DesiredCapabilities.CHROME,
            WebDriverFactory.FIREFOX: DesiredCapabilities.FIREFOX,
            WebDriverFactory.INTERNETEXPLORER:
            DesiredCapabilities.INTERNETEXPLORER,
            WebDriverFactory.IPAD: DesiredCapabilities.IPAD,
            WebDriverFactory.IPHONE: DesiredCapabilities.IPHONE,
            WebDriverFactory.OPERA: DesiredCapabilities.OPERA,
            WebDriverFactory.SAFARI: DesiredCapabilities.SAFARI,
            WebDriverFactory.PHANTOMJS: DesiredCapabilities.PHANTOMJS
        }

        try:
            # Get a copy of the desired capabilities object. (to avoid
            # overwriting the global.)
            desired_capabilities = browser_constant_dict[browser_type].copy()
        except KeyError:
            raise TypeError(
                u("Unsupported Browser Type {0}").format(browser_type))

        # Get additional desired properties from config file and add them in.
        other_desired_capabilities = self._config_reader.get(
            WebDriverFactory.DESIRED_CAPABILITIES_CONFIG)

        for prop in other_desired_capabilities:
            value = other_desired_capabilities[prop]

            if type(other_desired_capabilities[prop]) is dict:
                # do some recursive call to flatten this setting.
                self.__flatten_capabilities(desired_capabilities, prop,
                                            other_desired_capabilities[prop])
            else:  # Handle has a single string value.
                if isinstance(value, basestring):
                    desired_capabilities[prop] = value

                # Version is specified as a string, but we'll allow user to use
                # an int for convenience.
                elif prop == "version":
                    desired_capabilities[prop] = str(value)

                else:
                    desired_capabilities[prop] = value

        # Set the test name property if specified in the WTF_TESTNAME var.
        try:
            test_name = self._config_reader.get("TESTNAME")
            desired_capabilities['name'] = test_name
        except KeyError:
            pass  # No test name is specified, use the default.

        # Append optional testname postfix if supplied.
        if testname:
            if desired_capabilities['name']:
                desired_capabilities['name'] += "-" + testname
            else:
                # handle case where name is not specified.
                desired_capabilities['name'] = testname

        # Instantiate remote webdriver.
        driver = webdriver.Remote(desired_capabilities=desired_capabilities,
                                  command_executor=remote_url)

        # Log IP Address of node if configured, so it can be used to
        # troubleshoot issues if they occur.
        log_driver_props = \
            self._config_reader.get(
                WebDriverFactory.LOG_REMOTEDRIVER_PROPS, default_value=False
            ) in [True, "true", "TRUE", "True"]
        if "wd/hub" in remote_url and log_driver_props:
            try:
                grid_addr = remote_url[:remote_url.index("wd/hub")]
                info_request_response = urllib2.urlopen(
                    grid_addr + "grid/api/testsession?session=" +
                    driver.session_id, "", 5000)
                node_info = info_request_response.read()
                _wtflog.info(
                    u("RemoteWebdriver using node: ") + u(node_info).strip())
            except:
                # Unable to get IP Address of remote webdriver.
                # This happens with many 3rd party grid providers as they don't want you accessing info on nodes on
                # their internal network.
                pass

        return driver