def __init__(self, projectName, reportName, mongoDbHost, mongoDbPort, klovServerAddress): # paths = GetPath() # self.classpath = "D:\\Learning\\Python\\SeleniumPythonBaseFramework\\" \ # "JavaFiles\\ExtentReport-jar-with-dependencies.jar" # self.classpath = paths.extentreport_jar_path() #self.classpath = "F:/EclipseWorkSpace/ext.jar" #self.classpath = "F:/EclipseWorkSpace/TestProject/target/TestProject-0.0.1-SNAPSHOT-jar-with-dependencies.jar" #self.classpath = "F:/AllPythonProjects/PDS_Framwork/Reports/TestProject-0.0.1-SNAPSHOT-jar-with-dependencies.jar" getpath = GetPath() self.classpath = getpath.extentreport_jar_path() print("self.classpath ", self.classpath) jpype.startJVM(jpype.getDefaultJVMPath(), '-ea', "-Djava.class.path=" + self.classpath) print("Step 1 *******") jpype.java.lang.System.out.println("hello world") extent_report = JPackage('com').reports print("Step 2 *******", extent_report, type(extent_report)) #print(jpype.isThreadAttachedToJVM()) #jpype.attachThreadToJVM() #print(jpype.isThreadAttachedToJVM()) self.reports = extent_report.ExtentReportFunctions( projectName, reportName, mongoDbHost, mongoDbPort, klovServerAddress) print("Step 3 *******") self.reports.initExtentReport() print("Step 4 *******")
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
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
def get_config_file(self): """ Get config.ini """ try: paths = GetPath() config_file_path = paths.config_path() config = configparser.RawConfigParser() config.read(config_file_path) return config except Exception as e: self.log.error("Error while reading config.ini file" + str(e)) return None
def get_testcaseid(testcase: str) -> list: global work_book, sheet getpath = GetPath() get_sheet(getpath.testrail_mapping_path("testrail_mapping.xls"), "Sheet1") rows = sheet.nrows cols = sheet.ncols excel_data_list = [] for row in range(1, rows): if (sheet.cell_value(row, 0) == testcase): for col in range(1, cols): if ("" != sheet.cell_value(row, col)): excel_data_list.append(int(sheet.cell_value(row, col))) return excel_data_list
class MoveToArchiveFolder: paths = GetPath() 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 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 one_time_setup(): """ This fixture will execute only once before start execution of all test cases """ paths = GetPath() move_to_archive = MoveToArchiveFolder() move_to_archive.move_to_archive(paths.archive_report_path(), paths.execution_report_path()) move_to_archive.move_to_archive(paths.archive_screenshot_path(), paths.screenshot_folder_path()) paths.screenshot_folder_path() paths.execution_report_path() paths.log_file_path() yield # _LOG.info("Generating execution report") # report = AreReport() # report.call_allure_report_bat() # report.close_allure() report.flush_report()