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 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 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'))
EC.presence_of_element_located(( By.ID, "widget_com_ibm_asq_common_web_ui_internal_widgets_layout_ASQValidateTextBox_0" ))) elem = driver.find_element_by_css_selector( 'div.execute-icon-image.button-img') elem.click() elem = driver.find_element_by_css_selector( 'td.dijitReset.dijitMenuItemIconCell') elem.click() elem = wait.until( EC.element_to_be_clickable(( By.XPATH, "//div[@class='actions-container']/span[3]/span[@class='button-div'][1]/button" ))) elem.click() except: Failed = True log.critical('Browser Automation Failed!') else: log.critical('Browser Automation Succeed!') finally: driver.close() return not Failed # assert(Failed, 'Browser Automation Failed!') if __name__ == "__main__": ea_auto.ea_start() run_normal_test()
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)
elem.send_keys("test") elem = driver.find_element_by_name("j_password") # Find the query box elem.send_keys("test" + Keys.ENTER) wait = WebDriverWait(driver, 30) elem = wait.until(EC.presence_of_element_located((By.ID,"jazz_ui_toolbar_Button_1"))) # driver.get("https://10.144.10.217:9443/qm/web/console/QM%20Test%20Project#action=com.ibm.rqm.planning.home.actionDispatcher&subAction=viewTestCase&id=43") # Load page driver.get("https://10.144.10.217:9443/qm/web/console/autotest%20project#action=com.ibm.rqm.planning.home.actionDispatcher&subAction=viewTestCase&id=81") # Load page elem = wait.until(EC.presence_of_element_located((By.ID,"widget_com_ibm_asq_common_web_ui_internal_widgets_layout_ASQValidateTextBox_0"))) elem = driver.find_element_by_css_selector('div.execute-icon-image.button-img') elem.click() elem = driver.find_element_by_css_selector('td.dijitReset.dijitMenuItemIconCell') elem.click() elem = wait.until(EC.element_to_be_clickable((By.XPATH,"//div[@class='actions-container']/span[3]/span[@class='button-div'][1]/button"))) elem.click() except: Failed = True logger.critical('Browser Automation Failed!') else: logger.critical('Browser Automation Succeed!') Failed = False break finally: driver.close() ts_test_case_1() # handle the click operation needed for C:\Users\Public\Documents\National Instruments\TestStand 2012\Examples\Demo\C\computer.seq return not Failed # assert(Failed, 'Browser Automation Failed!') if __name__ == "__main__": ea_auto.ea_start() run_normal_test()