def test(): power_manager = PowerManagerFactory("AC", "Battery", "ScreenSaver", "PowerMenu", "LOG")#PowerManagerFactory.generate_dtc() power_manager.open_power_manager() # """ # AC # """ # power_manager.AC.switch() # accheck=ACCheck() # print('minutes_display_checked',accheck.minutes_display_checked) # print("minutes_sleep_checked", accheck.minutes_sleep_checked) # print('power_button_status', accheck.power_button_status) # print('lib_action_status',accheck.lib_action_status) # print('cpu_mode_status', accheck.cpu_mode_status) """ BAT ,only for MTC """ power_manager.Battery.switch("Normal") batcheck=BatteryCheck() print('BAT mode check',batcheck.mode_status) print('BAT Normal minutes_display_checked', batcheck.minutes_display_checked) print("BAT Normal minutes_sleep_checked", batcheck.minutes_sleep_checked) print('BAT Normal power_button_status', batcheck.power_button_status) print('BAT Normal lib_action_status', batcheck.lib_action_status) print('BAT Normal cpu_mode_status', batcheck.cpu_mode_status) power_manager.Battery.switch("Low") print('BAT mode check', batcheck.mode_status) print('BAT low minutes_display_checked', batcheck.minutes_display_checked) print("BAT low minutes_sleep_checked", batcheck.minutes_sleep_checked) print('BAT low cpu_mode_status', batcheck.cpu_mode_status) power_manager.Battery.switch("Critical") print('BAT mode check', batcheck.mode_status) print("BAT critical action",batcheck.critical_action_status) # """ # PM # """ # power_manager.PowerMenu.switch() # powermenucheck=PowerMenuCheck() # print("PM show_PM_checked",powermenucheck.show_PM_checked) # print("PM show_logout_checked", powermenucheck.show_logout_checked) # print("PM show_poweroff_checked", powermenucheck.show_poweroff_checked) # print("PM show_reboot_checked", powermenucheck.show_reboot_checked) # print("PM show_sleep_checked", powermenucheck.show_sleep_checked) # """ # SC # """ # power_manager.ScreenSaver.switch() # sc=ScreenSaverCheck() # print("SC enable_TSL_checked", sc.enable_TSL_checked) # print("SC enable_SS_checked", sc.enable_SS_checked) # print("SC minutes_before_asa_checked", sc.minutes_before_asa_checked) # print("SC require_pwd_admin_checked ", sc.require_pwd_admin_checked) # print("SC require_pwd_domain_checked", sc.require_pwd_domain_checked) # print("SC require_pwd_user_checked", sc.require_pwd_user_checked) # print("SC standard_image_checked", sc.standard_image_checked) # print("SC custom_image_checked ", sc.custom_image_checked) # print("SC solid_color_checked", sc.solid_color_checked) # power_manager.apply()
def step3(*args, **kwargs): case_name = kwargs.get("case_name") yml_path = kwargs.get("yml_path") PowerManagerFactory.open_power_manager_from_control_panel() time.sleep(3) event_dict = { "event_method": check_estar_logo, "case_name": case_name, "yml_path": yml_path} return event(**event_dict)
def open_screensaver(): time.sleep(2) try: power_manager = PowerManagerFactory("ScreenSaver") power_manager.open_power_manager_from_control_panel() power_manager.ScreenSaver.switch() except IconNotExistError: close_powermanager() return False return True
def reset_settings(*args, **kwargs): case_name = kwargs.get('case_name') SwitchThinProMode(switch_to='admin') if not click_icon('start'): unlock_screen('root', '1') try: power_m = PowerManagerFactory("ScreenSaver") power_m.ScreenSaver.open_power_manager_from_control_panel() power_m.ScreenSaver.switch() power_m.ScreenSaver.set( pms=pms.ScreenSaver.Enable_Screensaver_and_Screen_Lock, radio="on") power_m.ScreenSaver.set( pms=pms.ScreenSaver.Require_password_for_general_users, radio="off") power_m.ScreenSaver.apply() time.sleep(5) power_m.ScreenSaver.close_all_power_manager() except: log.debug( traceback.format_exc(), common_function.get_current_dir( 'Test_Report', 'img', '{}.png'.format(case_name.replace(' ', '_')))) os.system( "mclient --quiet set root/screensaver/lockScreenUser {}".format(0)) os.system("mclient commit") os.system('hptc-control-panel --term') web = WebConn([]) web.close_web_connection() tl = TelnetLinux() tl.logoff() if os.path.exists(path): os.remove(path)
def reset_all_settings(lis): locked_wake_up() time.sleep(2) power_m = PowerManagerFactory("ScreenSaver") power_m.ScreenSaver.open_power_manager_from_control_panel() power_m.ScreenSaver.switch() power_m.ScreenSaver.set( pms=pms.ScreenSaver.Enable_Screensaver_and_Screen_Lock, radio="on") power_m.ScreenSaver.set( pms=pms.ScreenSaver.Minutes_before_automatic_Screensaver_activation, radio="on", text=lis[1]) power_m.ScreenSaver.apply() time.sleep(5) power_m.ScreenSaver.close_all_power_manager() if lis: log.info('reset all settings in the end') os.system( "mclient --quiet set root/screensaver/enableScreensaver {}".format( lis[0])) os.system( "mclient --quiet set root/screensaver/enableCustomLogo {}".format( lis[2])) os.system("mclient --quiet set root/screensaver/logoPath {}".format( lis[3])) os.system("mclient commit")
def sleep_method1(): try: log.info('sleep by wait time') power_manager = PowerManagerFactory("AC") power_manager.AC.open_power_manager_from_control_panel() power_manager.AC.switch() power_manager.AC.set(pms=pms.AC.Minutes_before_system_sleep, radio="on", text="{}".format('1')) with PrepareWakeUp(time=80) as w: power_manager.AC.apply() w.wait(60) to_os = ScreenSaver() to_os.resume_lock_screen_by_mouse() time_gap = w.get_max_time_gap() w.set_max_time_gap(0) power_manager.AC.set(pms=pms.AC.Minutes_before_system_sleep, radio="on", text="{}".format('30')) power_manager.AC.apply() time.sleep(5) power_manager.AC.close_all_power_manager() return time_gap except: log.warning(traceback.format_exc()) return '0'
def start(case_name, **kwargs): ip = check_ip_yaml() yml_path = get_current_dir("Test_Report/{}.yaml").format(ip) power_manager = PowerManagerFactory("AC", "ScreenSaver") screensavertool = screensaver.ScreenSaver() params = { "case_name": case_name, "yml_path": yml_path, "screensavertool": screensavertool, "power_manager": power_manager } flag = step1(**params) flag = step2(**params) if flag else False flag = step3(**params) if flag else False flag = step4(**params) if flag else False flag = step5(**params) if flag else False flag = step6(**params) if flag else False power_manager.close_all_power_manager() resume_all_settings(**params) return flag
def require_pass_domain_users(): log.info('Uncheck "Require password for domain users') SwitchThinProMode(switch_to='admin') power_m = PowerManagerFactory("ScreenSaver") power_m.ScreenSaver.open_power_manager_from_control_panel() power_m.ScreenSaver.switch() power_m.ScreenSaver.set( pms=pms.ScreenSaver.Enable_Screensaver_and_Screen_Lock, radio="on") power_m.ScreenSaver.set( pms=pms.ScreenSaver.Require_password_for_domain_users, radio="off") power_m.ScreenSaver.apply() time.sleep(3) power_m.ScreenSaver.close_all_power_manager()
def step1(*args, **kwargs): case_name = kwargs.get("case_name") report_file = kwargs.get("report_file") SwitchThinProMode(switch_to='admin') log.info('set user password: 1') set_user_password() log.info('enable require password for general users') power_m = PowerManagerFactory("ScreenSaver") power_m.ScreenSaver.open_power_manager_from_control_panel() power_m.ScreenSaver.switch() power_m.ScreenSaver.set( pms=pms.ScreenSaver.Enable_Screensaver_and_Screen_Lock, radio="on") power_m.ScreenSaver.set( pms=pms.ScreenSaver.Require_password_for_general_users, radio="on") click_icon('ok', count=1) power_m.ScreenSaver.apply() time.sleep(5) power_m.ScreenSaver.close_all_power_manager() SwitchThinProMode(switch_to='user') log.info('start a web connection') web = WebConn([]) web.open_firefox() if click_icon('firefox_title'): log.info('web connection success') lock_screen() pyautogui.press('enter') if click_icon('locked_dialog'): log.info('screen lock dialog shown') steps = { 'step_name': "verify screen lock dialog shown", 'result': 'Pass', 'expect': 'show', 'actual': 'show', 'note': '' } common_function.update_cases_result(report_file, case_name, steps) else: error_pic = os.path.join( common_function.get_current_dir(), r'Test_Report', 'img', '{}+step1.png'.format(case_name.replace(' ', '_'))) capture_screen(error_pic) steps = { 'step_name': "verify screen lock dialog shown", 'result': 'Fail', 'expect': 'show', 'actual': 'not show', 'note': '' } common_function.update_cases_result(report_file, case_name, steps) reset_settings() return False
def check_ac_default_value(): power_manager = PowerManagerFactory("AC") power_manager.AC.open_power_manager_from_control_panel() power_manager.AC.switch() path = os.path.join(common_function.get_current_dir(), 'Test_Data', 'td_power_manager', 'verify_ac_default_value', 'sleep_time') if wait_element(path): sleep = '30' else: sleep = '' log.info('get default value on AC sleep after:{}'.format(sleep)) power_manager.AC.close_all_power_manager() return sleep
def check_sleep_status(): power_manager = PowerManagerFactory("AC") if not power_manager.AC.open_power_manager_from_control_panel(): log.info('try to open power manager again') if not power_manager.AC.open_power_manager_from_control_panel(): return False power_manager.AC.switch() path = os.path.join(common_function.get_current_dir(), 'Test_Data', 'td_power_manager', 'verify_s3_work', 'sleep_disable') power_icon = picture_operator.wait_element(path, offset=(10, 10)) power_manager.AC.close_all_power_manager() if power_icon: log.warning('system sleep is disable') return False else: return True
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, **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 close_powermanager(): return PowerManagerFactory.close_all_power_manager()
def resume(*args, **kwargs): return PowerManagerFactory.close_all_power_manager()
def close_control_pannel(): time.sleep(2) return PowerManagerFactory.close_all_power_manager()
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): 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