Ejemplo n.º 1
0
    def __init__(self):
        """
        Constructor

        """
        root = ProjectUtils.get_project_root()
        if root[-1] == '/' or root[-1] == '\\':
            self._data_path = ProjectUtils.get_project_root() + DataManager._DATA_FOLDER_
        else:
            self._data_path = ProjectUtils.get_project_root() + "/" + DataManager._DATA_FOLDER_
            
        if not os.path.exists(self._data_path):
            raise RuntimeError("Missing data folder.  Please check to make sure you have a /data directory.")
Ejemplo n.º 2
0
    def __init__(self):
        '''
        Constructor
        '''
        self._asset_path = os.path.join(ProjectUtils.get_project_root() , AssetManager._ASSET_FOLDER_)

        if not os.path.exists(self._asset_path):
            raise RuntimeError("Missing assets folder.  Please check to make sure you have a /assets directory.")
Ejemplo n.º 3
0
    def __init__(self):
        """
        Constructor

        """
        root = ProjectUtils.get_project_root()
        if root[-1] == '/' or root[-1] == '\\':
            self._data_path = ProjectUtils.get_project_root(
            ) + DataManager._DATA_FOLDER_
        else:
            self._data_path = ProjectUtils.get_project_root(
            ) + "/" + DataManager._DATA_FOLDER_

        if not os.path.exists(self._data_path):
            raise RuntimeError(
                "Missing data folder.  Please check to make sure you have a /data directory."
            )
Ejemplo n.º 4
0
    def __init__(self):
        '''
        Constructor
        '''
        self._asset_path = os.path.join(ProjectUtils.get_project_root() , AssetManager._ASSET_FOLDER_)

        if not os.path.exists(self._asset_path):
            raise RuntimeError("Missing assets folder.  Please check to make sure you have a /assets directory.")
Ejemplo n.º 5
0
    def __init__(self):
        """
        Constructor

        """
        self._data_path = os.path.join(ProjectUtils.get_project_root(), DataManager._DATA_FOLDER_)

        if not os.path.exists(self._data_path):
            raise RuntimeError("Missing data folder.  Please check to make sure you have a /data directory.")
Ejemplo n.º 6
0
    def __init__(self):
        """
        Constructor

        """
        self._data_path = os.path.join(ProjectUtils.get_project_root(),
                                       DataManager._DATA_FOLDER_)

        if not os.path.exists(self._data_path):
            raise RuntimeError(
                "Missing data folder.  Please check to make sure you have a /data directory."
            )
Ejemplo n.º 7
0
    def take_reference_screenshot(webdriver, file_name):
        """
        Captures a screenshot as a reference screenshot.

        Args:
            webdriver (WebDriver) - Selenium webdriver.
            file_name (str) - File name to save screenshot as.
        """
        folder_location = os.path.join(ProjectUtils.get_project_root(),
                                       WebScreenShotUtil.REFERENCE_SCREEN_SHOT_LOCATION)

        WebScreenShotUtil.__capture_screenshot(
            webdriver, folder_location, file_name + ".png")
Ejemplo n.º 8
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)
Ejemplo n.º 9
0
    def take_screenshot(webdriver, file_name):
        """
        @param webdriver: WebDriver.
        @type webdriver: WebDriver
        @param file_name: Name to label this screenshot.
        @type file_name: str 
        """
        file_location = os.path.join(ProjectUtils.get_project_root() +
                                            WebScreenShotUtil.SCREEN_SHOT_LOCATION + 
                                            file_name + 
                                            ".png")

        WebScreenShotUtil.__capture_screenshot(webdriver, file_location)
Ejemplo n.º 10
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)
         print "locating config file:", 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:
         print "Error loading config file " + file_name
         raise ConfigFileReadError("Error reading config file " + file_name, e)
Ejemplo n.º 11
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)
Ejemplo n.º 12
0
    def take_screenshot(webdriver, file_name):
        """
        Captures a screenshot.
        
        Args:
            webdriver (WebDriver) - Selenium webdriver.
            file_name (str) - File name to save screenshot as.

        """
        file_location = os.path.join(ProjectUtils.get_project_root() +
                                     WebScreenShotUtil.SCREEN_SHOT_LOCATION +
                                     file_name + ".png")

        WebScreenShotUtil.__capture_screenshot(webdriver, file_location)
Ejemplo n.º 13
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)
         print "locating config file:", 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:
         print "Error loading config file " + file_name
         raise ConfigFileReadError("Error reading config file " + file_name,
                                   e)
Ejemplo n.º 14
0
 def test_capture_file_created_and_valid_png(self):
     self.driver = WTF_WEBDRIVER_MANAGER.new_driver("TestPageUtils.test_capture_file_created_and_valid_png")
     self.driver.get("http://www.yahoo.com")
     fname = "test"
     prj_root = ProjectUtils.get_project_root()
     fpath = os.path.join(prj_root, WebScreenShotUtil.SCREEN_SHOT_LOCATION, fname + ".png")
     try:
         WebScreenShotUtil.take_screenshot(self.driver, fname)
         self.assertTrue(os.path.isfile(fpath))
         self.assertEquals(imghdr.what(fpath), "png")
     finally:
         try:
             os.remove(fpath)
         except OSError:
             pass
Ejemplo n.º 15
0
    def take_screenshot(webdriver, file_name):
        """
        Captures a screenshot.
        
        Args:
            webdriver (WebDriver) - Selenium webdriver.
            file_name (str) - File name to save screenshot as.

        """
        file_location = os.path.join(ProjectUtils.get_project_root() +
                                            WebScreenShotUtil.SCREEN_SHOT_LOCATION + 
                                            file_name + 
                                            ".png")

        WebScreenShotUtil.__capture_screenshot(webdriver, file_location)
Ejemplo n.º 16
0
 def test_capture_file_created_and_valid_png(self):
     self.driver = WTF_WEBDRIVER_MANAGER.new_driver(
         "TestPageUtils.test_capture_file_created_and_valid_png")
     self.driver.get("http://www.yahoo.com")
     fname = "test"
     prj_root = ProjectUtils.get_project_root()
     fpath = os.path.join(
         prj_root, WebScreenShotUtil.SCREEN_SHOT_LOCATION, fname + ".png")
     try:
         WebScreenShotUtil.take_screenshot(self.driver, fname)
         self.assertTrue(os.path.isfile(fpath))
         self.assertEquals(imghdr.what(fpath), "png")
     finally:
         try:
             os.remove(fpath)
         except OSError:
             pass
Ejemplo n.º 17
0
    if(options.version_flag):
        print wtframework.__VERSION__
        exit()

    if len(args) < 2:
        print "Invalid command.", usage
        exit(1)
        
    if args[0] == "generate-page":
        if len(args) < 3:
            raise RuntimeError("usage: wtf_tools.py generate-page PageName http://page.url.com/somepage")

        pagename = args[1]
        url = args[2]
        print "Generating page object for url:", url
        file_content = page_object_tools.generate_page_object(pagename, url)
        path = os.path.join(ProjectUtils.get_project_root(), "tests", "pages", pagename.lower() + ".py")
        create_file(path, file_content)

    elif args[0] == "generate-test":
        test_name = args[1]
        print "Generating generic test."
        file_content = test_generation_tools.generate_empty_test(test_name)
        create_file(ProjectUtils.get_project_root() \
                    + "tests/tests/{test_name}.py".format(test_name=test_name), \
                    file_content)
        
    else:
        print "Invalid command.", usage, "\nFor help:\nwtf_tools.py --help\n"

Ejemplo n.º 18
0

if __name__ == '__main__':

    usage = "usage: %prog [-options args]"
    parser = OptionParser(usage=usage)
    parser.add_option("-c", "--config", dest="config",
                  help="Config to use (without the .yaml suffix)", metavar="FILE")
    parser.add_option("-r", "--results", dest="result_file",
                  help="path to create result file.", metavar="FILE")
    (options, args) = parser.parse_args()


    if options.config:
        # check if config exists.
        if os.path.exists(ProjectUtils.get_project_root() + \
                          ConfigReader.CONFIG_LOCATION + options.config +\
                          ConfigReader.CONFIG_EXT):
            print "Setting config WTF_ENV to:", options.config
            os.putenv(ConfigReader.ENV_VARS, options.config)
        else:
            print "Cannot find config: ", ProjectUtils.get_project_root() + \
                          ConfigReader.CONFIG_LOCATION + options.config +\
                          ConfigReader.CONFIG_EXT

    # Set PYTHONPATH if not set.
    try:
        if ProjectUtils.get_project_root() not in os.environ["PYTHONPATH"]:
            os.putenv("PYTHONPATH", os.environ["PYTHONPATH"] + os.pathsep + ProjectUtils.get_project_root())
    except:
        os.putenv("PYTHONPATH", ProjectUtils.get_project_root())
Ejemplo n.º 19
0
    if(options.version_flag):
        print(wtframework.__VERSION__)
        exit()

    if len(args) < 2:
        print("Invalid command.", usage)
        exit(1)
        
    if args[0] == "generate-page":
        if len(args) < 3:
            raise RuntimeError("usage: wtf_tools.py generate-page PageName http://page.url.com/somepage")

        pagename = args[1]
        url = args[2]
        print("Generating page object for url:", url)
        file_content = page_object_tools.generate_page_object(pagename, url)
        path = os.path.join(ProjectUtils.get_project_root(), "tests", "pages", pagename.lower() + ".py")
        create_file(path, file_content)

    elif args[0] == "generate-test":
        test_name = args[1]
        print("Generating generic test.")
        file_content = test_generation_tools.generate_empty_test(test_name)
        create_file(ProjectUtils.get_project_root() \
                    + "tests/tests/{test_name}.py".format(test_name=test_name), \
                    file_content)
        
    else:
        print("Invalid command.", usage, "\nFor help:\nwtf_tools.py --help\n")

Ejemplo n.º 20
0
 def take_reference_screenshot(webdriver, file_name):
     file_location = os.path.join(ProjectUtils.get_project_root() +
                                 WebScreenShotUtil.REFERENCE_SCREEN_SHOT_LOCATION + 
                                 file_name + 
                                 ".png")
     WebScreenShotUtil.__capture_screenshot(webdriver, file_location)
Ejemplo n.º 21
0
    parser = OptionParser(usage=usage)
    parser.add_option("-c",
                      "--config",
                      dest="config",
                      help="Config to use (without the .yaml suffix)",
                      metavar="FILE")
    parser.add_option("-r",
                      "--results",
                      dest="result_file",
                      help="path to create result file.",
                      metavar="FILE")
    (options, args) = parser.parse_args()

    if options.config:
        # check if config exists.
        if os.path.exists(ProjectUtils.get_project_root() + \
                          ConfigReader.CONFIG_LOCATION + options.config +\
                          ConfigReader.CONFIG_EXT):
            print "Setting config WTF_ENV to:", options.config
            os.putenv(ConfigReader.ENV_VARS, options.config)
        else:
            print "Cannot find config: ", ProjectUtils.get_project_root() + \
                          ConfigReader.CONFIG_LOCATION + options.config +\
                          ConfigReader.CONFIG_EXT

    # Set PYTHONPATH if not set.
    try:
        if ProjectUtils.get_project_root() not in os.environ["PYTHONPATH"]:
            os.putenv(
                "PYTHONPATH", os.environ["PYTHONPATH"] + os.pathsep +
                ProjectUtils.get_project_root())
Ejemplo n.º 22
0
    usage = "usage: %prog [-options args]"
    parser = OptionParser(usage=usage)
    parser.add_option("-c", "--config", dest="config",
                  help="Config to use (without the .yaml suffix)", metavar="FILE")
    parser.add_option("-r", "--results", dest="result_file",
                  help="path to create result file.", metavar="FILE")
    (options, args) = parser.parse_args()


    if options.config:
        configs = re.split(",|;", options.config)
        configs_valid = True
        for config in configs:
            # check if config exists.
            expected_path = os.path.join(ProjectUtils.get_project_root(),
                                         WTF_CONFIG_LOCATION,
                                         config + WTF_CONFIG_EXT)
            if os.path.exists(expected_path):
                pass  # config exists.
            else:
                configs_valid = False
                print("Cannot find config: ", expected_path)
        
        if configs_valid:
            os.putenv(WTF_ENV_VARS, options.config)
            print("Setting config WTF_ENV to:", options.config)
        else:
            exit(1)  # one or more errors was found in the configs.
        
Ejemplo n.º 23
0
    if(options.version_flag):
        print wtframework.__VERSION__
        exit()

    if len(args) < 2:
        print "Invalid command.", usage
        exit(1)
        
    if args[0] == "generate-page":
        if len(args) < 3:
            raise RuntimeError("usage: wtf_tools.py generate-page PageName http://page.url.com/somepage")

        pagename = args[1]
        url = args[2]
        print "Generating page object for url:", url
        file_content = page_object_tools.generate_page_object(pagename, url)
        create_file(ProjectUtils.get_project_root() \
                    +"tests/pages/{pagename}.py".format(pagename=pagename.lower()), file_content)

    elif args[0] == "generate-test":
        test_name = args[1]
        print "Generating generic test."
        file_content = test_generation_tools.generate_empty_test(test_name)
        create_file(ProjectUtils.get_project_root() \
                    +"tests/tests/{test_name}.py".format(test_name=test_name),\
                    file_content)
        
    else:
        print "Invalid command.", usage, "\nFor help:\nwtf_tools.py --help\n"