Esempio n. 1
0
def customLogger(log_level):
    """
    Create logger which status like Info, Error, Critical etc.
    """
    logger = None
    try:
        # getting the logs folder path + creating file name
        # with current datetime stamp
        paths = GetPath()
        log_path = paths.log_file_path()
        file_name = GenericFunctions.get_filename_date()
        if 'windows' in GenericFunctions.get_os().casefold():
            file_path = log_path + "\\" + "Automation_" + file_name
        else:
            file_path = log_path + "/" + "Automation_" + file_name

        # Gets the name of the class / method from where
        # this method is called
        logger_name = inspect.stack()[1][3]
        logger = logging.getLogger(logger_name)

        # By default, log all messages
        logger.setLevel(logging.DEBUG)

        file_handler = logging.FileHandler(file_path + ".log", mode='a')
        file_handler.setLevel(log_level)

        formatter = logging.Formatter('%(asctime)s - %(name)s'
                                      ' - %(levelname)s: %(message)s')
        file_handler.setFormatter(formatter)
        logger.addHandler(file_handler)
    except Exception as e:
        print(e)

    return logger
Esempio n. 2
0
    def capture_screenshot(driver: webdriver, title: str):
        """
        This method captures screenshot and copied it at given location.
        """
        try:
            log = customLogger(logging.INFO)
            log.info("Capturing the screen shot of failed test case '" +
                     title + "'.")
            # Get path of screen shot folder
            paths = GetPath()
            os = GenericFunctions.get_os()
            screenshot_folder = paths.screenshot_folder_path()

            # create screenshot name using title and timestamp
            # current_date = "_".join(re.split(" |\:|\.", str(GenericFunctions.get_current_date_time())))
            current_date = GenericFunctions.get_filename_datetimestamp()
            if os.casefold() == 'windows':
                screenshot_name = "\\" + title + "_" + current_date + ".png"
            else:
                screenshot_name = "/" + title + "_" + current_date + ".png"
            screenshot_path = screenshot_folder + screenshot_name
            log.info("Screenshot path: " + screenshot_path)

            if driver is not None:
                driver.save_screenshot(screenshot_path)
            else:
                log.error("Driver is None ")
        except Exception as e:
            log.error("Capture Screenshot exception: " + str(e))
        return screenshot_path
Esempio n. 3
0
 def log_file_path(self, doc="this returns the path till logs folder"):
     """
     this returns the path till logs folder
     """
     try:
         log_path = os.path.join("logs")
         GenericFunctions.isdir_present(log_path)
         return log_path
     except Exception as e:
         print("Error in log_file_path" + str(e))
Esempio n. 4
0
 def archive_screenshot_path(self,
                             doc="this returns the path of archive folder"):
     """
     This returns the path of execution report
     """
     try:
         archive_path = os.path.join("resources", "archive")
         GenericFunctions.isdir_present(archive_path)
         return archive_path
     except Exception as e:
         print("Error in execution report path" + str(e))
Esempio n. 5
0
 def execution_report_path(
         self, doc="this returns the path of execution report folder"):
     """
     This returns the path of execution report
     """
     try:
         report_path = os.path.join("target", "execution_report")
         GenericFunctions.isdir_present(report_path)
         return report_path
     except Exception as e:
         print("Error in execution report path" + str(e))
Esempio n. 6
0
    def screenshot_folder_path(
            self, doc="this returns the path till screenshot folder"):
        """
        this returns the path till screenshot folder
        """
        try:

            screenshot_path = os.path.join("resources", "screenshots")
            GenericFunctions.isdir_present(screenshot_path)
            return screenshot_path
        except Exception as e:
            print("Error in screenshot_folder_path" + str(e))
Esempio n. 7
0
 def call_allure_report_bat(self):
     global _pro
     path = GetPath()
     report_path = path.execution_report_path()
     report_executable_path = path.allure_report_executable_path()
     if 'window' in GenericFunctions.get_os().casefold():
         report_executable_path = path.allure_report_executable_path(
         ) + '\\report.bat'
         _pro = subprocess.Popen([report_executable_path, report_path])
     else:
         report_executable_path = path.allure_report_executable_path(
         ) + '/report.bash'
         st = os.stat(report_executable_path)
         os.chmod(report_executable_path, st.st_mode | stat.S_IEXEC)
         subprocess.Popen([report_executable_path, report_path])
    def move_to_archive(self, archive_dir_path, source_dir):
        """
        Moving old files to archive folder. This is specially for execution reports
        """
        dir_name = GenericFunctions.get_filename_datetimestamp()

        print("dir_name  ", dir_name)

        if 'windows' in GenericFunctions.get_os().casefold():
            GenericFunctions.isdir_present(archive_dir_path + "\\", dir_name)
            GenericFunctions.move_directories(
                source_dir, archive_dir_path + "\\" + dir_name)
        else:
            # code for linux or mac
            pass
    def get_property_value(self, section: str, key: str) -> str:
        """
        Returns property value for give key.
        If key is password first it decrypt the encrypted password and return it
        """
        try:
            config = self.get_config_file()
            value = config.get(section, key)
            if 'password' in key.casefold():
                decrypt_key = (config.get(section, key + "_key"))
                password = GenericFunctions.decrypt_value(decrypt_key, value)
                if password is not None:
                    return password
                else:
                    raise Exception(
                        "Password Key is None. Please check password key is valid or not."
                    )

            else:
                return value
        except Exception as e:
            self.log.error("Error while reading config.ini file" + str(e))
            return None