def verify_cpu_mhz(mode, case_name, power_manager): try: if mode == 'ondemand': low_mhz = linux_get_cpu_mhz(mode) select_mode('performance', power_manager) time.sleep(15) high_mhz = linux_get_cpu_mhz('performance') log.info("ondemand mode:{}, performance mode:{}".format( low_mhz, high_mhz)) return [high_mhz, low_mhz] else: high_mhz = linux_get_cpu_mhz(mode) select_mode('ondemand', power_manager) time.sleep(15) low_mhz = linux_get_cpu_mhz('ondemand') log.info("performance mode:{}, ondemand mode:{}".format( high_mhz, low_mhz)) return [high_mhz, low_mhz] except: log.error(traceback.format_exc()) error_pic = os.path.join(common_function.get_current_dir(), r'Test_Report', 'img', '{}.png'.format(case_name)) capture_screen(error_pic) os.system("wmctrl -c 'Control Panel'") return '0'
def start(case_name, **kwargs): try: log.info('Begin to start test {}'.format(case_name)) user_manager = vdi_connection.MultiUserManger() user = user_manager.get_a_available_key() rdp_server = user_manager.get_a_available_key('rdp win10') conn = vdi_connection.RDPLinux(user=user, rdp_server=rdp_server) log.info('user: {}, rdp_server: {}'.format(user, rdp_server)) report_file = os.path.join( common_function.get_current_dir(), r'Test_Report', '{}.yaml'.format(common_function.check_ip_yaml())) common_function.new_cases_result(report_file, case_name) common_function.case_steps_run_control(steps_list, __name__, case_name=case_name, log=log, report_file=report_file, user=user, rdp_server=rdp_server, conn=conn, user_manager=user_manager) except: log.error(traceback.format_exc()) error_pic = os.path.join(common_function.get_current_dir(), r'Test_Report', 'img', '{}.png'.format(case_name)) picture_operator.capture_screen(error_pic) reset_all_settings(num=0) return False
def step2(case_name): try: return check_icon('default') except: log.error(traceback.format_exc()) error_pic = os.path.join(common_function.get_current_dir(), r'Test_Report', 'img', '{}.png'.format(case_name)) capture_screen(error_pic) return
def wait_and_check_screen_saver(t=55): log.info("start wait time") for i in range(9): time.sleep(t) if linux_check_locked(): log.error("current loop times {}".format(i)) break else: time.sleep(t + 35) flag = linux_check_locked() log.info("check screen lock result:{}".format(flag)) return flag return False
def step1(case_name): try: power_m = PowerManagerFactory("ScreenSaver") power_m.ScreenSaver.open_power_manager_from_control_panel() power_m.ScreenSaver.switch() before = check_changed('activation') set_system_image(power_m) time.sleep(5) after = check_changed('activation1') power_m.ScreenSaver.close_all_power_manager() if before and after: return True except: log.error(traceback.format_exc()) error_pic = os.path.join(common_function.get_current_dir(), r'Test_Report', 'img', '{}.png'.format(case_name)) capture_screen(error_pic) return []
def start(case_name, *args, **kwargs): try: log.info('Begin to start test {}'.format(case_name)) result_file = os.path.join( common_function.get_current_dir(), r'Test_Report', '{}.yaml'.format(common_function.check_ip_yaml())) common_function.new_cases_result(result_file, case_name) common_function.case_steps_run_control(steps_list, __name__, case_name=case_name, log=log, report_file=result_file) reset_settings() log.info('test case {} is end'.format(case_name)) except: log.error(traceback.format_exc()) error_pic = os.path.join(common_function.get_current_dir(), r'Test_Report', 'img', '{}.png'.format(case_name.replace(' ', '_'))) capture_screen(error_pic) pass
def start(case_name, **kwargs): try: result_file = os.path.join( common_function.get_current_dir(), r'Test_Report', '{}.yaml'.format(common_function.check_ip_yaml())) log.info('Begin to start test {}'.format(case_name)) new_cases_result(result_file, case_name) SwitchThinProMode(switch_to='admin') if check_sleep_status(): steps = { 'step_name': 'check "Minutes before system sleep"', 'result': 'Pass', 'expect': 'enable', 'actual': 'it is enable', 'note': '' } update_cases_result(result_file, case_name, steps) else: steps = { 'step_name': 'check "Minutes before system sleep"', 'result': 'Fail', 'expect': 'enable', 'actual': 'not enable', 'note': '' } update_cases_result(result_file, case_name, steps) log.info('{} end'.format(case_name)) return False last_time_gap = int(sleep_method1()) if last_time_gap > 5: steps = { 'step_name': 'check tc go to sleep after 1 minute', 'result': 'Pass', 'expect': 'sleep', 'actual': 'TC go to sleep', 'note': '' } update_cases_result(result_file, case_name, steps) else: steps = { 'step_name': 'check tc go to sleep after 1 minute', 'result': 'Fail', 'expect': 'sleep', 'actual': 'TC not go to sleep', 'note': 'sleep time: {}'.format(last_time_gap) } update_cases_result(result_file, case_name, steps) os.system("wmctrl -c 'Control Panel'") log.info('{} end'.format(case_name)) return False last_time_gap = int(sleep_method2(sleep_desktop)) if last_time_gap > 5: steps = { 'step_name': 'check tc go to sleep by desktop', 'result': 'Pass', 'expect': 'sleep', 'actual': 'TC go to sleep', 'note': '' } update_cases_result(result_file, case_name, steps) else: error_pic = os.path.join( common_function.get_current_dir(), r'Test_Report', 'img', '{}+sleep_by_desktop.png'.format(case_name.replace(' ', '_'))) capture_screen(error_pic) steps = { 'step_name': 'check tc go to sleep by desktop', 'result': 'Fail', 'expect': 'sleep', 'actual': 'TC not go to sleep', 'note': '{}'.format(error_pic) } update_cases_result(result_file, case_name, steps) log.info('{} end'.format(case_name)) return False last_time_gap = int(sleep_method2(sleep_start_menu)) if last_time_gap > 5: steps = { 'step_name': 'check tc go to sleep by start menu', 'result': 'Pass', 'expect': 'sleep', 'actual': 'TC go to sleep', 'note': 'sleep time: {}'.format(last_time_gap) } update_cases_result(result_file, case_name, steps) else: error_pic = os.path.join( common_function.get_current_dir(), r'Test_Report', 'img', '{}+sleep_by_start_menu.png'.format(case_name.replace( ' ', '_'))) capture_screen(error_pic) steps = { 'step_name': 'check tc go to sleep by start menu', 'result': 'Fail', 'expect': 'sleep', 'actual': 'TC not go to sleep', 'note': '{}'.format(error_pic) } update_cases_result(result_file, case_name, steps) log.info('{} end'.format(case_name)) return False log.info('{} end'.format(case_name)) except: log.error(traceback.format_exc()) error_pic = os.path.join(common_function.get_current_dir(), r'Test_Report', 'img', '{}.png'.format(case_name.replace(' ', '_'))) capture_screen(error_pic) os.system("wmctrl -c 'Control Panel'") pass
def start(case_name, **kwargs): try: result_file = os.path.join(common_function.get_current_dir(), r'Test_Report', '{}.yaml'.format(common_function.check_ip_yaml())) log.info('Begin to start test {}'.format(case_name)) new_cases_result(result_file, case_name) SwitchThinProMode(switch_to='admin') power_manager = PowerManagerFactory("AC") if not power_manager.AC.open_power_manager_from_control_panel(): steps = { 'step_name': 'verify the cpu run with ondemand on AC', 'result': 'Fail', 'expect': '', 'actual': '', 'note': 'power manager open fail'} update_cases_result(result_file, case_name, steps) return False power_manager.AC.switch() default_mode = get_cup_mode() cpu_mhz_list = [] loop_result = [] for i in range(3): cpu_mode = get_cup_mode() value = verify_cpu_mhz(cpu_mode, case_name, power_manager) cpu_mhz_list.append(abs(float(value[0])-float(value[1]))) loop_result.append(value) time.sleep(2) reset_settings(default_mode, power_manager) power_manager.AC.close_all_power_manager() log.info('cpu mhz list: {}'.format(cpu_mhz_list)) value = max(cpu_mhz_list) if default_mode == 'ondemand': steps = { 'step_name': 'verify the cpu run with ondemand on AC', 'result': 'Pass', 'expect': 'ondemand', 'actual': 'ondemand', 'note': ''} update_cases_result(result_file, case_name, steps) else: steps = { 'step_name': 'verify the cpu run with ondemand on AC', 'result': 'Fail', 'expect': 'ondemand', 'actual': '{}'.format(default_mode), 'note': ''} update_cases_result(result_file, case_name, steps) if float(value) > 500: steps = { 'step_name': 'check the cpu mhz', 'result': 'Pass', 'expect': '>500', 'actual': '{}'.format(value), 'note': ''} update_cases_result(result_file, case_name, steps) else: steps = { 'step_name': 'check the cpu mhz', 'result': 'Fail', 'expect': '>500', 'actual': '{}'.format(value), 'note': 'loop 3 times result:{}'.format(loop_result)} update_cases_result(result_file, case_name, steps) log.info('{} end'.format(case_name)) except: log.error(traceback.format_exc()) error_pic = os.path.join(common_function.get_current_dir(), r'Test_Report', 'img', '{}.png'.format(case_name)) capture_screen(error_pic) power_manager = PowerManagerFactory("AC") power_manager.AC.close_all_power_manager() pass
def start(case_name, **kwargs): value_ls = get_defaule() try: log.info('Begin to start test {}'.format(case_name)) result_file = os.path.join( common_function.get_current_dir(), r'Test_Report', '{}.yaml'.format(common_function.check_ip_yaml())) new_cases_result(result_file, case_name) SwitchThinProMode(switch_to='admin') source_pic1 = os.path.join( common_function.get_current_dir(), 'Test_Data/td_power_manager/verify_screensaver_diff_image', 'source_pic/pic.jpg') source_img1, source_size1 = open_pic(source_pic1) source_data1 = get_pic_color(source_img1, get_xy(source_size1)) log.info('pic.jpg data {}'.format(source_data1)) source_pic2 = os.path.join( common_function.get_current_dir(), 'Test_Data/td_power_manager/verify_screensaver_diff_image', 'source_pic/pic1.png') source_img2, source_size2 = open_pic(source_pic2) source_data2 = get_pic_color(source_img2, get_xy(source_size2)) log.info('pic1.png data {}'.format(source_data2)) power_m = PowerManagerFactory("ScreenSaver") if not power_m.open_power_manager_from_control_panel(): log.info('try open power manager again') power_m.open_power_manager_from_control_panel() power_m.ScreenSaver.switch() data1, data2 = step1(power_m, source_size1, source_size2) log.info(f"data1 type: {type(data1)}") log.info(f"source data1 type: {type(source_data1)}") log.info([data1, data2]) log.info([source_data1, source_data2]) if [data1, data2] == [source_data1, source_data2] or [ data2, data1 ] == [source_data1, source_data2]: steps = { 'step_name': 'verify new slideshow', 'result': 'Pass', 'expect': 'slideshow', 'actual': 'slideshow', 'note': '' } update_cases_result(result_file, case_name, steps) else: log.debug( "picture not match", common_function.get_current_dir( 'Test_Report', 'img', '{}_slideshow.png'.format(case_name.replace(' ', '_')))) steps = { 'step_name': 'verify new slideshow', 'result': 'Fail', 'expect': 'slideshow', 'actual': 'no slideshow', 'note': '' } update_cases_result(result_file, case_name, steps) reset_settings(value_ls) return False data3, data4 = step2(power_m) log.info(f"data3 type: {type(data3)}") log.info(f"source data1 type: {type(source_data1)}") log.info([data3, data4]) log.info([source_data1, source_data2]) if [data3, data4] == [source_data1, source_data2] or [ data4, data3 ] == [source_data1, source_data2]: steps = { 'step_name': 'verify new slideshowstretch', 'result': 'Pass', 'expect': 'slideshowstrech', 'actual': 'slideshowstrech', 'note': '' } update_cases_result(result_file, case_name, steps) else: log.debug( "picture not match", common_function.get_current_dir( 'Test_Report', 'img', '{}_slideshowstretch.png'.format( case_name.replace(' ', '_')))) steps = { 'step_name': 'verify new slideshow', 'result': 'Fail', 'expect': 'slideshow', 'actual': 'no slideshowstrech', 'note': '' } update_cases_result(result_file, case_name, steps) reset_settings(value_ls) return False if step3(power_m, 4): steps = { 'step_name': 'verify new center show', 'result': 'Pass', 'expect': 'center', 'actual': 'center', 'note': '' } update_cases_result(result_file, case_name, steps) else: log.debug( "picture not match", common_function.get_current_dir( 'Test_Report', 'img', '{}_center.png'.format(case_name.replace(' ', '_')))) steps = { 'step_name': 'verify new center show', 'result': 'Fail', 'expect': 'center', 'actual': 'no center', 'note': '' } update_cases_result(result_file, case_name, steps) locked_wake_up() time.sleep(5) reset_settings(value_ls) return False locked_wake_up() time.sleep(5) data = step4(power_m, source_size1) if data == source_data1: steps = { 'step_name': 'verify new expand show', 'result': 'Pass', 'expect': 'expand', 'actual': 'expand', 'note': '' } update_cases_result(result_file, case_name, steps) else: log.debug( "picture not match", common_function.get_current_dir( 'Test_Report', 'img', '{}_expand.png'.format(case_name.replace(' ', '_')))) steps = { 'step_name': 'verify new expand show', 'result': 'Fail', 'expect': 'expand', 'actual': 'no expand', 'note': '' } update_cases_result(result_file, case_name, steps) reset_settings(value_ls) return False data5 = step5(power_m) if data5 == source_data2: steps = { 'step_name': 'verify new stretch show', 'result': 'Pass', 'expect': 'stretch', 'actual': 'stretch', 'note': '' } update_cases_result(result_file, case_name, steps) else: log.debug( "picture not match", common_function.get_current_dir( 'Test_Report', 'img', '{}_stretch.png'.format(case_name.replace(' ', '_')))) steps = { 'step_name': 'verify new stretch show', 'result': 'Fail', 'expect': 'stretch', 'actual': 'no stretch', 'note': '' } update_cases_result(result_file, case_name, steps) reset_settings(value_ls) return False if step6(power_m, 7): steps = { 'step_name': 'verify new tile show', 'result': 'Pass', 'expect': 'tile', 'actual': 'tile', 'note': '' } update_cases_result(result_file, case_name, steps) else: log.debug( "picture not match", common_function.get_current_dir( 'Test_Report', 'img', '{}_tile.png'.format(case_name.replace(' ', '_')))) steps = { 'step_name': 'verify new tile show', 'result': 'Fail', 'expect': 'tile', 'actual': 'no tile', 'note': '' } update_cases_result(result_file, case_name, steps) locked_wake_up() time.sleep(5) reset_settings(value_ls) return False locked_wake_up() time.sleep(5) power_m.close_all_power_manager() reset_settings(value_ls) log.info('{} is end'.format(case_name)) except: reset_settings(value_ls) log.error(traceback.format_exc()) error_pic = os.path.join(common_function.get_current_dir(), r'Test_Report', 'img', '{}.png'.format(case_name.replace(' ', '_'))) capture_screen(error_pic) os.popen("hptc-control-panel --term") pass
def start(case_name, **kwargs): try: result_file = os.path.join( common_function.get_current_dir(), r'Test_Report', '{}.yaml'.format(common_function.check_ip_yaml())) log.info('Begin to start test {}'.format(case_name)) new_cases_result(result_file, case_name) SwitchThinProMode(switch_to='admin') if 'mt' not in get_platform().lower(): log.warning('There is no need to run this case on DTC') step1 = { 'step_name': 'check current platform', 'result': 'Fail', 'expect': '', 'actual': '', 'note': 'current platform is not mtc, skip the case' } common_function.update_cases_result(result_file, case_name, step1) return power_manager = PowerManagerFactory("Battery") power_manager.Battery.open_power_manager_from_control_panel() power_manager.Battery.switch() default_mode = get_cup_mode() cpu_mhz_list = [] loop_result = [] for i in range(3): cpu_mode = get_cup_mode() value = verify_cpu_mhz(cpu_mode, case_name, power_manager) cpu_mhz_list.append(abs(float(value[0]) - float(value[1]))) loop_result.append(value) time.sleep(2) reset_settings(default_mode, power_manager) power_manager.Battery.close_all_power_manager() log.info('cpu mhz list: {}'.format(cpu_mhz_list)) value = max(cpu_mhz_list) if default_mode == 'ondemand': steps = { 'step_name': 'verify the cpu run with ondemand on Battery', 'result': 'Pass', 'expect': 'ondemand', 'actual': 'ondemand', 'note': '' } update_cases_result(result_file, case_name, steps) else: steps = { 'step_name': 'verify the cpu run with ondemand on Battery', 'result': 'Fail', 'expect': 'ondemand', 'actual': '{}'.format(default_mode), 'note': '' } update_cases_result(result_file, case_name, steps) if float(value) > 500: steps = { 'step_name': 'check the cpu mhz', 'result': 'Pass', 'expect': '>500', 'actual': '{}'.format(value), 'note': '' } update_cases_result(result_file, case_name, steps) else: steps = { 'step_name': 'check the cpu mhz', 'result': 'Fail', 'expect': '>500', 'actual': '{}'.format(value), 'note': 'loop 3 times result:{}'.format(loop_result) } update_cases_result(result_file, case_name, steps) log.info('{} end'.format(case_name)) except: log.error(traceback.format_exc()) error_pic = os.path.join(common_function.get_current_dir(), r'Test_Report', 'img', '{}.png'.format(case_name)) capture_screen(error_pic) os.system("wmctrl -c 'Control Panel'") pass
def start(case_name, **kwargs): try: result_file = os.path.join( common_function.get_current_dir(), r'Test_Report', '{}.yaml'.format(common_function.check_ip_yaml())) log.info('Begin to start test {}'.format(case_name)) common_function.new_cases_result(result_file, case_name) SwitchThinProMode(switch_to='admin') sleep_time = check_ac_default_value() if sleep_time == '30': steps = { 'step_name': 'check the default value on AC', 'result': 'Pass', 'expect': '30', 'actual': '30', 'note': '' } common_function.update_cases_result(result_file, case_name, steps) else: steps = { 'step_name': 'check the default value on AC', 'result': 'Fail', 'expect': '30', 'actual': 'The default value is wrong', 'note': '' } common_function.update_cases_result(result_file, case_name, steps) log.info('case {} is end'.format(case_name)) return False with PrepareWakeUp(time=1810) as w: w.wait(1810) to_os = ScreenSaver() to_os.resume_lock_screen_by_mouse() last_time_gap = int(w.get_max_time_gap()) if last_time_gap > 5: steps = { 'step_name': 'check the os go to verify_s3_work afer 30 minutes', 'result': 'Pass', 'expect': 'sleep', 'actual': 'it is go to sleep', 'note': '' } common_function.update_cases_result(result_file, case_name, steps) else: steps = { 'step_name': 'check the os go to verify_s3_work afer 30 minutes', 'result': 'Fail', 'expect': 'sleep', 'actual': 'it is not go to sleep', 'note': 'time gap: {}, must more than 5'.format(last_time_gap) } common_function.update_cases_result(result_file, case_name, steps) return False if last_time_gap > 5: steps = { 'step_name': 'check the os wake up', 'result': 'Pass', 'expect': 'wake up', 'actual': 'System can wake up immediately', 'note': '' } common_function.update_cases_result(result_file, case_name, steps) else: steps = { 'step_name': 'check the os wake up', 'result': 'Fail', 'expect': 'wake up', 'actual': 'System not wake up immediately', 'note': '' } common_function.update_cases_result(result_file, case_name, steps) log.info('case {} is end'.format(case_name)) except: log.error(traceback.format_exc()) error_pic = os.path.join(common_function.get_current_dir(), r'Test_Report', 'img', '{}.png'.format(case_name.replace(' ', '_'))) capture_screen(error_pic) pass
# -m http # run testcases which marked as http args_allure = ['-s', '-q', '--alluredir', xml_report_path_allure, 'Testcase/test_wsapi.py::TestWSAPITest::test_get_real_chain_block_info_with_sub'] args_pytest = ['-s', '-v', '--html=%s' % os.path.join(html_report_path, 'pytest-html%s' % common.current_time(consts.TIME_FORMAT_FILE), 'report.html'), 'Testcase/test_httpapi.py'] pytest.main(args_allure) # generate allure html reports cmd = 'allure generate %s -o %s' % (xml_report_path_allure, html_report_path_allure) try: command = command.Cmd() command.run(cmd) except Exception: log.error('testcase failed to run, check environment configuration please!') raise # # send email # try: # # email configuration # qq_mail = memail.Email() # qq_mail.smtp_server = config.smtpserver_email # qq_mail.smtp_server_port = config.smtpserverport_email # qq_mail.from_addr = config.from_email # qq_mail.username = config.username_email # qq_mail.to_addr = config.to_email # qq_mail.password = config.password_email # # do send # msg = qq_mail.set_msg() # qq_mail.login()
def start(case_name, **kwargs): log.info('Begin to start test {}'.format(case_name)) a = get_default_value() try: result_file = os.path.join( common_function.get_current_dir(), r'Test_Report', '{}.yaml'.format(common_function.check_ip_yaml())) common_function.new_cases_result(result_file, case_name) if not SwitchThinProMode(switch_to='admin'): SwitchThinProMode(switch_to='admin') if step1(case_name): steps = { 'step_name': "verify settings can be changed", 'result': 'Pass', 'expect': 'can', 'actual': 'can', 'note': '' } common_function.update_cases_result(result_file, case_name, steps) else: steps = { 'step_name': "verify settings can be changed", 'result': 'Fail', 'expect': 'can', 'actual': 'can not', 'note': '' } common_function.update_cases_result(result_file, case_name, steps) reset_all_settings(a) return False time.sleep(121) if step2(case_name): steps = { 'step_name': "verify after 2 minutes the screensaver can work well", 'result': 'Pass', 'expect': 'success', 'actual': 'success', 'note': '' } common_function.update_cases_result(result_file, case_name, steps) else: steps = { 'step_name': "verify after 2 minutes the screensaver can work well", 'result': 'Fail', 'expect': 'success', 'actual': 'fail', 'note': '' } common_function.update_cases_result(result_file, case_name, steps) reset_all_settings(a) return False reset_all_settings(a) log.info('{} is end'.format(case_name)) except: log.error(traceback.format_exc()) error_pic = os.path.join(common_function.get_current_dir(), r'Test_Report', 'img', '{}.png'.format(case_name)) capture_screen(error_pic) reset_all_settings(a) pass