Esempio n. 1
0
    def __init__(self, webdriver, *args, **kwargs):
        """Constructor.  It's better to not call this directly, instead use PageFactory 
        to instantiate PageObjects.
        
        Ars: 
            webdriver (Webdriver): Selenium Webdriver instance.

        """
        try:
            config_reader = kwargs['config_reader']
        except KeyError:
            config_reader = WTF_CONFIG_READER

        
        self._validate_page(webdriver)
        
        # Assign webdriver to PageObject. 
        # Each page object has an instance of "webdriver" referencing the webdriver 
        # driving this page.
        self.webdriver = webdriver

        # Take reference screenshots if this option is enabled.
        if config_reader.get("selenium.take_reference_screenshot", False) == True:
            class_name = type(self).__name__
            if class_name in PageObject.__names_of_classes_we_already_took_screen_caps_of__:
                pass
            else:
                try:
                    WebScreenShotUtil.take_reference_screenshot(webdriver, class_name)
                    PageObject.__names_of_classes_we_already_took_screen_caps_of__[class_name] = True
                except Exception as e:
                    _wtflog.error(e)  # Some WebDrivers such as head-less drivers does not take screenshots.
        else:
            pass
Esempio n. 2
0
    def __init__(self, _env_var_=None):
        """
        constructor
        """
        self._dataMaps = []

        # load default yaml file if this is not a unit test.
        try:
            if _env_var_ != None: 
                # We pass in a custom env var for unit testing.
                configs = re.split(",|;", _env_var_)
                for config in reversed(configs):
                    self.__load_config_file(config)
            elif not ConfigReader.ENV_VARS in os.environ:
                _wtflog.warning(u("Config file not specified.  Using config/defaults.yaml"))
                self.__load_config_file(ConfigReader.DEFAULT_CONFIG_FILE)
            else:
                # Read and load in all configs specified in reverse order
                configs = re.split(",|;", str(os.environ[ConfigReader.ENV_VARS]))
                for config in reversed(configs):
                    self.__load_config_file(config)

                
        except Exception as e:
            # Fall back to default.yaml file when no config settings are specified.
            _wtflog.error(u("An error occurred while loading config file: %s"), e)
            raise e
Esempio n. 3
0
    def __init__(self, _env_var_=None):
        """
        constructor
        """
        self._dataMaps = []

        # load default yaml file if this is not a unit test.
        try:
            if _env_var_ != None:
                # We pass in a custom env var for unit testing.
                configs = re.split(",|;", _env_var_)
                for config in reversed(configs):
                    self.__load_config_file(config)
            elif not ConfigReader.ENV_VARS in os.environ:
                _wtflog.warning(
                    u("Config file not specified.  Using config/defaults.yaml")
                )
                self.__load_config_file(ConfigReader.DEFAULT_CONFIG_FILE)
            else:
                # Read and load in all configs specified in reverse order
                configs = re.split(",|;",
                                   str(os.environ[ConfigReader.ENV_VARS]))
                for config in reversed(configs):
                    self.__load_config_file(config)

        except Exception as e:
            # Fall back to default.yaml file when no config settings are
            # specified.
            _wtflog.error(u("An error occurred while loading config file: %s"),
                          e)
            raise e
Esempio n. 4
0
    def __init__(self, _env_var_=None):
        """
        constructor
        """
        self._dataMaps = []

        # load default yaml file if this is not a unit test.
        try:
            if _env_var_ is not None:
                # We pass in a custom env var for unit testing.
                configs = re.split(",|;", _env_var_)
                for config in reversed(configs):
                    self.__load_config_file(config)
            elif not ConfigReader.ENV_VARS in os.environ:
                _wtflog.warning(u("Config file not specified. Using:{0}")\
                                .format(os.path.join(ConfigReader.CONFIG_LOCATION,
                                                     ConfigReader.DEFAULT_CONFIG_FILE + ConfigReader.CONFIG_EXT)))
                self.__load_config_file(ConfigReader.DEFAULT_CONFIG_FILE)
            else:
                # Read and load in all configs specified in reverse order
                configs = re.split(",|;",
                                   str(os.environ[ConfigReader.ENV_VARS]))
                for config in reversed(configs):
                    self.__load_config_file(config)

        except Exception as e:
            # Error loading config file.
            _wtflog.error(u("An error occurred while loading config file: %s"),
                          e)
            raise e
Esempio n. 5
0
    def __init__(self, _env_var_=None):
        """
        constructor
        """
        self._dataMaps = []

        # load default yaml file if this is not a unit test.
        try:
            if _env_var_ is not None:
                # We pass in a custom env var for unit testing.
                configs = re.split(",|;", _env_var_)
                for config in reversed(configs):
                    self.__load_config_file(config)
            elif not ConfigReader.ENV_VARS in os.environ:
                _wtflog.warning(u("Config file not specified. Using:{0}")\
                                .format(os.path.join(ConfigReader.CONFIG_LOCATION,
                                                     ConfigReader.DEFAULT_CONFIG_FILE + ConfigReader.CONFIG_EXT)))
                self.__load_config_file(ConfigReader.DEFAULT_CONFIG_FILE)
            else:
                # Read and load in all configs specified in reverse order
                configs = re.split(
                    ",|;", str(os.environ[ConfigReader.ENV_VARS]))
                for config in reversed(configs):
                    self.__load_config_file(config)

        except Exception as e:
            # Error loading config file.
            _wtflog.error(
                u("An error occurred while loading config file: %s"), e)
            raise e
Esempio n. 6
0
 def __load_config_file(self, file_name):
     try:
         config_file_location = os.path.join(ProjectUtils.get_project_root(),
                                             ConfigReader.CONFIG_LOCATION,
                                             file_name + ConfigReader.CONFIG_EXT)
         _wtflog.debug(u("locating config file: %s"), config_file_location)
         config_yaml = open(config_file_location, 'r')
         dataMap = yaml.load(config_yaml)
         self._dataMaps.insert(0, dataMap)
         config_yaml.close()
     except Exception as e:
         _wtflog.error(u("Error loading config file: %s"), file_name)
         raise ConfigFileReadError(u("Error reading config file ") + file_name, e)
Esempio n. 7
0
 def __load_config_file(self, file_name):
     try:
         config_file_location = os.path.join(
             ProjectUtils.get_project_root(), ConfigReader.CONFIG_LOCATION,
             file_name + ConfigReader.CONFIG_EXT)
         _wtflog.debug(u("locating config file: %s"), config_file_location)
         config_yaml = open(config_file_location, 'r')
         dataMap = yaml.load(config_yaml)
         self._dataMaps.insert(0, dataMap)
         config_yaml.close()
     except Exception as e:
         _wtflog.error(u("Error loading config file: %s"), file_name)
         raise ConfigFileReadError(
             u("Error reading config file ") + file_name, e)
Esempio n. 8
0
    def __init__(self, webdriver, *args, **kwargs):
        """Constructor.  It's better to not call this directly, instead use PageFactory 
        to instantiate PageObjects.

        Args: 
            webdriver (Webdriver): Selenium Webdriver instance.

        """
        try:
            config_reader = kwargs['config_reader']
        except KeyError:
            config_reader = WTF_CONFIG_READER

        try:
            self._validate_page(webdriver)
        except TypeError as e:
            _wtflog.error(
                "PageObjects need to implement '_validate_page(self, webdriver)' method: %s",
                e)
            raise e
        except Exception as e:
            _wtflog.debug("Unable to instantiate page: %s", e)
            raise e

        # Assign webdriver to PageObject.
        # Each page object has an instance of "webdriver" referencing the webdriver
        # driving this page.
        self.webdriver = webdriver

        # Take reference screenshots if this option is enabled.
        if config_reader.get("selenium.take_reference_screenshot",
                             False) == True:
            class_name = type(self).__name__
            if class_name in PageObject.__names_of_classes_we_already_took_screen_caps_of__:
                pass
            else:
                try:
                    WebScreenShotUtil.take_reference_screenshot(
                        webdriver, class_name)
                    PageObject.__names_of_classes_we_already_took_screen_caps_of__[
                        class_name] = True
                except Exception as e:
                    # Some WebDrivers such as head-less drivers does not take
                    # screenshots.
                    _wtflog.error(e)
        else:
            pass