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 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