def test_config_ini_file(self): ea_log_path, ea_log_file, logger = initialize_test_folders(test_name) config_file.initialize(log_folder=ea_log_path) removeall(ea_log_path) tps_step = '1-5' ts_auto.ts_start(delay=5) ea_start(delay=15) passed = browser_auto.run_normal_test() time_sleep(20) ea_close() ts_closed = ts_auto.ts_close() try: self.assertTrue(passed, 'Browser Automation Failed!') self.assertTrue(ts_closed, 'TestStand close Failed!') self.assertTrue(os.path.exists(ea_log_file), 'EA log: {} not found!'.format(ea_log_file)) self.assertTrue( lookup_keyword_in_ea_log(active_kwd_list, ea_log_file), 'Not all the keywords were found in EA log!') self.assertTrue( lookup_keyword_in_ea_log(task_executed_kwd_list, ea_log_file), 'Not all the keywords were found in EA log!') except AssertionError as e: logger.critical(tps_state_str.format(tps_name, tps_step, 'FAILED')) logger.critical(str(e)) except Exception as e: logger.critical( tps_state_str.format(tps_name, tps_step, 'UNKOWN ERROR')) logger.critical(str(e)) else: logger.critical(tps_state_str.format(tps_name, tps_step, 'PASSED'))
def restart_time_test(self, opt, inp_str, veri_keywords=active_kwd_list, expect_result=True): ea_log_path, ea_log_file, logger = initialize_test_folders(test_name) config_file.initialize(log_folder = ea_log_path) removeall(ea_log_path) logger = logging.getLogger("COSMO.config.login") tps_step = opt + ' = ' + inp_str logger.critical(tps_state_str.format(tps_name, tps_step, 'BEGIN')) if opt != None: config_file.change_option('Server', opt, '"{}"'.format(inp_str)) ea_start(delay=15) time_gui_closed = time.time() logger.info('gui closed now.') ea_close() time_process_ended = time.time() logger.info('process is ended now.') time_result = time_process_ended - time_gui_closed try: self.assertTrue(os.path.exists(ea_log_file), 'EA log: {} not found!'.format(ea_log_file)) self.assertTrue(expect_result == lookup_keyword_in_ea_log(active_kwd_list, ea_log_file), 'Expected result is {}, not satisfied!'.format(expect_result)) except AssertionError as e: logger.critical(tps_state_str.format(tps_name, tps_step, 'FAILED')) logger.critical(str(e)) except Exception as e: logger.critical(tps_state_str.format(tps_name, tps_step, 'UNKOWN ERROR')) logger.critical(str(e)) else: logger.critical(tps_state_str.format(tps_name, tps_step, 'PASSED')) finally: logger.critical('Seconds to restart EA is {}'.format(time_result))
def test_config_ini_file(self): ea_log_path, ea_log_file, logger = initialize_test_folders(test_name) config_file.initialize(log_folder = ea_log_path) removeall(ea_log_path) tps_step = '1-5' ts_auto.ts_start(delay=5) ea_start(delay=15) passed = browser_auto.run_normal_test() time_sleep(20) ea_close() ts_closed = ts_auto.ts_close() try: self.assertTrue(passed, 'Browser Automation Failed!') self.assertTrue(ts_closed, 'TestStand close Failed!') self.assertTrue(os.path.exists(ea_log_file), 'EA log: {} not found!'.format(ea_log_file)) self.assertTrue(lookup_keyword_in_ea_log(active_kwd_list, ea_log_file), 'Not all the keywords were found in EA log!') self.assertTrue(lookup_keyword_in_ea_log(task_executed_kwd_list, ea_log_file), 'Not all the keywords were found in EA log!') except AssertionError as e: logger.critical(tps_state_str.format(tps_name, tps_step, 'FAILED')) logger.critical(str(e)) except Exception as e: logger.critical(tps_state_str.format(tps_name, tps_step, 'UNKOWN ERROR')) logger.critical(str(e)) else: logger.critical(tps_state_str.format(tps_name, tps_step, 'PASSED'))
def config_test(self, opt, inp_str, veri_keywords=active_kwd_list, expect_result=True): ea_log_path, ea_log_file, logger = initialize_test_folders(test_name) config_file.initialize(log_folder=ea_log_path) removeall(ea_log_path) logger = logging.getLogger("COSMO.config.login") tps_step = opt + ' = ' + inp_str logger.critical(tps_state_str.format(tps_name, tps_step, 'BEGIN')) if opt != None: config_file.change_option('Server', opt, '"{}"'.format(inp_str)) ea_start(delay=15) ea_close() try: self.assertTrue(os.path.exists(ea_log_file), 'EA log: {} not found!'.format(ea_log_file)) self.assertTrue( expect_result == lookup_keyword_in_ea_log( active_kwd_list, ea_log_file), 'Expected result is {}, not satisfied!'.format(expect_result)) except AssertionError as e: logger.critical(tps_state_str.format(tps_name, tps_step, 'FAILED')) logger.critical(str(e)) except Exception as e: logger.critical( tps_state_str.format(tps_name, tps_step, 'UNKOWN ERROR')) logger.critical(str(e)) else: logger.critical(tps_state_str.format(tps_name, tps_step, 'PASSED'))
def stress_test(repeat_times = 10): ea_log_path, ea_log_file, logger = initialize_test_folders(test_name) logger.critical("Initialize Stress Test.") #ea_initialize_test(log_folder=ea_log_path) config_file.initialize(log_folder=ea_log_path) '''shutil.copy('ea/Configuration.ini', config_file) ea_start(delay=15) ea_click(item='file_name') ea_config('folder', ea_log_path) ea_close()''' logger.critical("Initialize Stress Test Finished.") cnt = 0 passed_number = 0 while cnt < repeat_times: cnt += 1 logger.critical("Stress Test No.{} BEGIN.".format(cnt)) removeall(ea_log_path) ea_start(delay=0) passed = browser_auto.run_normal_test() ea_close() try: assert passed, 'Browser Automation FAILED!' assert os.path.exists(ea_log_file), 'EA log: {} not found!'.format(ea_log_file) assert lookup_keyword_in_ea_log(active_kwd_list + task_executed_kwd_list, ea_log_file), 'Not all the keywords were found in EA log!' except AssertionError as e: logger.critical("Stress Test No.{} FAILED.".format(cnt)) logger.critical(str(e)) except Exception as e: logger.critical("Stress Test No.{} UNKOWN ERROR.".format(cnt)) logger.critical(str(e)) else: logger.critical("Stress Test No.{} PASSED.".format(cnt)) passed_number += 1 logger.critical('Pass rate till now is {}'.format(passed_number/cnt)) if cnt%100 == 0: time_sleep(2) #delete temp file too hurry might prevent firefox from closing removeall(r'C:\Users\msun\AppData\Local\temp') #the files here could be too large, if running for hours
def test_config_ini_file(self): ea_log_path, ea_log_file, logger = initialize_test_folders(test_name) config_file.initialize(log_folder = ea_log_path) removeall(ea_log_path) tps_step = '1-5' ea_start(delay=5) if not ts_auto.ts_close():# todo: ts_close is not stable enough logger.critical('Close TestStand FAILED!') ea_close() try: self.assertTrue(os.path.exists(ea_log_file), 'EA log: {} not found!'.format(ea_log_file)) self.assertTrue(lookup_keyword_in_ea_log(shutdown_kwd_list, ea_log_file), 'Not all the keywords were found in EA log!') except AssertionError as e: logger.critical(tps_state_str.format(tps_name, tps_step, 'FAILED')) logger.critical(str(e)) except Exception as e: logger.critical(tps_state_str.format(tps_name, tps_step, 'UNKOWN ERROR')) logger.critical(str(e)) else: logger.critical(tps_state_str.format(tps_name, tps_step, 'PASSED'))
def test_config_ini_file(self): ea_log_path, ea_log_file, logger = initialize_test_folders(test_name) tps_step = '1-2' removeall(config_file) ea_start(handle_ts=False) try: with open(config_file, 'r') as f: self.assertTrue(len(f.read()) == 0, 'config file is not empty') except Exception as e: logger.critical(tps_state_str.format(tps_name, tps_step, 'FAILED')) logger.critical(str(e)) else: logger.critical(tps_state_str.format(tps_name, tps_step, 'PASSED')) tps_step = '3' # test_items = ['server', 'username', 'password', 'project_area', 'adapter_name'] # todo: cann't test password; encrypt make the file a mess, python could not read that file test_items = ['server', 'username', 'project_area', 'adapter_name'] for i in test_items: t_i = 'test_' + i print(t_i) ea_config(i, t_i) ea_close() try: with open(config_file, 'r') as f: config_content = f.read() for i in test_items: t_i = 'test_' + i if i != 'password': self.assertTrue( t_i in config_content, 'content: {} could not be found'.format(t_i)) else: self.assertTrue(t_i not in config_content, 'password is read directly') except Exception as e: logger.critical(tps_state_str.format(tps_name, tps_step, 'FAILED')) logger.critical(str(e)) else: logger.critical(tps_state_str.format(tps_name, tps_step, 'PASSED'))
def test_config_ini_file(self): ea_log_path, ea_log_file, logger = initialize_test_folders(test_name) config_file.initialize(log_folder=ea_log_path) removeall(ea_log_path) tps_step = '1-5' ea_start(delay=5) if not ts_auto.ts_close(): # todo: ts_close is not stable enough logger.critical('Close TestStand FAILED!') ea_close() try: self.assertTrue(os.path.exists(ea_log_file), 'EA log: {} not found!'.format(ea_log_file)) self.assertTrue( lookup_keyword_in_ea_log(shutdown_kwd_list, ea_log_file), 'Not all the keywords were found in EA log!') except AssertionError as e: logger.critical(tps_state_str.format(tps_name, tps_step, 'FAILED')) logger.critical(str(e)) except Exception as e: logger.critical( tps_state_str.format(tps_name, tps_step, 'UNKOWN ERROR')) logger.critical(str(e)) else: logger.critical(tps_state_str.format(tps_name, tps_step, 'PASSED'))
def tearDown(self): try: ea_close() except: pass pass
def tearDown(self): try: ea_close() except: pass pass
def test_config_log(self): ea_log_path, ea_log_file, logger = initialize_test_folders(test_name) logger = logging.getLogger("COSMO.config.log") tps_name = 'Configurations of log file' # initialize tps_step = 'Initialize log path' logger.critical(tps_state_str.format(tps_name, tps_step, 'BEGIN')) config_file.initialize(log_folder= ea_log_path) # step 1-2 removeall(ea_log_path) tps_step = '1 - 2' logger.critical(tps_state_str.format(tps_name, tps_step, 'BEGIN')) ea_start(delay=15) ea_close() try: self.assertTrue(os.path.exists(ea_log_file), 'EA log: {} not found!'.format(ea_log_file)) self.assertTrue(lookup_keyword_in_ea_log(active_kwd_list, ea_log_file), 'Not all the keywords were found in EA log!') except AssertionError as e: logger.critical(tps_state_str.format(tps_name, tps_step, 'FAILED')) logger.critical(str(e)) except Exception as e: logger.critical(tps_state_str.format(tps_name, tps_step, 'UNKOWN ERROR')) logger.critical(str(e)) else: logger.critical(tps_state_str.format(tps_name, tps_step, 'PASSED')) # step 3 removeall(ea_log_path) tps_step = '3' logger.critical(tps_state_str.format(tps_name, tps_step, 'BEGIN')) ea_start(delay=15) passed = browser_auto.run_normal_test() time_sleep(20) ea_close() try: self.assertTrue(passed, 'Browser Automation Failed!') self.assertTrue(os.path.exists(ea_log_file), 'EA log: {} not found!'.format(ea_log_file)) self.assertTrue(lookup_keyword_in_ea_log(active_kwd_list, ea_log_file), 'Not all the keywords were found in EA log!') self.assertTrue(lookup_keyword_in_ea_log(task_executed_kwd_list, ea_log_file), 'Not all the keywords were found in EA log!') except AssertionError as e: logger.critical(tps_state_str.format(tps_name, tps_step, 'FAILED')) logger.critical(str(e)) except Exception as e: logger.critical(tps_state_str.format(tps_name, tps_step, 'UNKOWN ERROR')) logger.critical(str(e)) else: logger.critical(tps_state_str.format(tps_name, tps_step, 'PASSED')) # step 4 tps_step = '4' logger.critical('TPS: {}, step: {}, test begin.'.format(tps_name, tps_step)) ea_log_path_exists = ea_log_path + 'exists\\' ea_log_file_step4 = os.path.join(ea_log_path_exists, 'system log.html') config_file.change_option('Client', 'systemlogfolder', '"{}"'.format(ea_log_path_exists)) removeall(ea_log_path) os.mkdir(ea_log_path_exists) ea_start(delay=15) ea_close() try: self.assertTrue(os.path.exists(ea_log_file_step4), 'EA log: {} not found!'.format(ea_log_file_step4)) self.assertTrue(lookup_keyword_in_ea_log(active_kwd_list, ea_log_file_step4), 'Not all the keywords were found in EA log!') except AssertionError as e: logger.critical(tps_state_str.format(tps_name, tps_step, 'FAILED')) logger.critical(str(e)) except Exception as e: logger.critical(tps_state_str.format(tps_name, tps_step, 'UNKOWN ERROR')) logger.critical(str(e)) else: logger.critical(tps_state_str.format(tps_name, tps_step, 'PASSED')) # step 5 tps_step = '5' logger.critical('TPS: {}, step: {}, test begin.'.format(tps_name, tps_step)) ea_log_path_not_exists = ea_log_path + 'not_exists\\' ea_log_file_step5 = os.path.join(ea_log_path_not_exists, 'system log.html') config_file.change_option('Client', 'systemlogfolder', '"{}"'.format(ea_log_path_not_exists)) removeall(ea_log_path) ea_start(delay=15) ea_close() try: self.assertTrue(os.path.exists(ea_log_file_step5), 'EA log: {} not found!'.format(ea_log_file_step5)) self.assertTrue(lookup_keyword_in_ea_log(active_kwd_list, ea_log_file_step5), 'Not all the keywords were found in EA log!') except AssertionError as e: logger.critical(tps_state_str.format(tps_name, tps_step, 'FAILED')) logger.critical(str(e)) except Exception as e: logger.critical(tps_state_str.format(tps_name, tps_step, 'UNKOWN ERROR')) logger.critical(str(e)) else: logger.critical(tps_state_str.format(tps_name, tps_step, 'PASSED')) # step 6 tps_step = '6' logger.critical('TPS: {}, step: {}, test begin.'.format(tps_name, tps_step)) config_file.change_option('Client', 'systemlogfolder', '"{}"'.format(ea_log_path)) config_file.change_option('Client', 'systemlognamestyle', '"TimeStampedFilename"') removeall(ea_log_path) ea_start(delay=15) ea_close() try: validate_str = datetime.datetime.now().strftime('system log %Y-%m-%d ') + '*.html' validate_str = ea_log_path + validate_str logger.debug('Validate string is {}'.format(validate_str)) files_found = glob.glob(validate_str) self.assertTrue(len(files_found) == 1, '{} of log(s) with {} format were found'.format(len(files_found), validate_str)) ea_log_file_step6 = files_found[0] self.assertTrue(os.path.exists(ea_log_file_step6), 'EA log: {} not found!'.format(ea_log_file_step6)) self.assertTrue(lookup_keyword_in_ea_log(active_kwd_list, ea_log_file_step6), 'Not all the keywords were found in EA log!') except AssertionError as e: logger.critical(tps_state_str.format(tps_name, tps_step, 'FAILED')) logger.critical(str(e)) except Exception as e: logger.critical(tps_state_str.format(tps_name, tps_step, 'UNKOWN ERROR')) logger.critical(str(e)) else: logger.critical(tps_state_str.format(tps_name, tps_step, 'PASSED'))
def ea_start_close_test(): for i in range(100): logger.critical('test begin.') ea_start(delay=15) logger.critical('test end.') ea_close(delay=10)