def resume_all_settings(*args, **kwargs): power_manager = kwargs.get("power_manager") os.system("mclient --quiet set root/Power/default/AC/sleep 30") time.sleep(1) os.system("mclient commit") SwitchThinProMode("admin") time.sleep(1) set_ac_min_to_one(power_manager, revert=True) SwitchThinProMode("user")
def switch_user(self, user_mode): ''' :param: user_mode: e.g. 'admin' or 'user' ''' if user_mode == 'admin': SwitchThinProMode('admin') elif user_mode == 'user': SwitchThinProMode('user') else: self.log.info('invalid user_mode {}'.format(user_mode))
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 resume_all_settings(*args, **kwargs): SwitchThinProMode("admin") os.system("mclient --quiet set root/screensaver/timeoutScreensaver 10") os.system("mclient --quiet set root/screensaver/lockScreenUser 0") os.system("mclient --quiet set root/Power/default/AC/sleep 30") time.sleep(1) os.system("mclient commit") power_manager = kwargs.get("power_manager") power_manager.open_power_manager_from_control_panel() set_sleep_time(power_manager, revert=True) set_screen_saver_time(power_manager, revert=True) power_manager.apply() SwitchThinProMode("user") close_control_pannel() return
def login_remote(*args, **kwargs): case_name = kwargs.get("case_name") result_file = kwargs.get("report_file") log.info('2.2. Start a remote session with your SH account.') SwitchThinProMode(switch_to='user') conn = kwargs.get('conn') if start_remote('logon', conn=conn): steps = { 'step_name': 'login a remote session (RDP)', 'result': 'Pass', 'expect': '', 'actual': '', 'note': '' } common_function.update_cases_result(result_file, case_name, steps) else: log.info('remote session login fail') steps = { 'step_name': 'login a remote session (RDP)', 'result': 'Fail', 'expect': 'login success', 'actual': 'vdi login fail', 'note': '' } common_function.update_cases_result(result_file, case_name, steps) reset_all_settings(num=0) return False
def start(case_name, **kwargs): try: log.info('Begin to start case {}'.format(case_name)) result_file = os.path.join(get_current_dir(), r'Test_Report', '{}.yaml'.format(check_ip_yaml())) new_cases_result(result_file, case_name) SwitchThinProMode(switch_to='admin') default_method = get_connection_method() wired = Wired() if dynamic_ip_check(case_name, result_file, wired) is False: reset_connection_method(default_method) return if dynamic_ip_ping(case_name, result_file) is False: reset_connection_method(default_method) return ip = get_ip() mask = wired.get_mask('eth0') gateway = wired.gateway() if static_ip_check(case_name, result_file, wired, ip, mask, gateway) is False: reset_connection_method(default_method) return if static_ip_ping(case_name, result_file) is False: reset_connection_method(default_method) return except: log.error(traceback.format_exc()) error_pic = os.path.join(get_current_dir(), r'Test_Report', 'img', '{}.png'.format(case_name)) capture_screen(error_pic) os.system("wmctrl -c 'Control Panel'")
def check_status(): """ 0 >> no setting 1 >> domain_1 2 >> domain_2 :return: """ SwitchThinProMode(switch_to='admin') time.sleep(20) open_window("active directory") ad = get_position('ad.png') if not ad: Logger().info("find ad fail") return authenticate = get_position('authenticate.png') if authenticate: close_window() return 0 authenticate_checked = get_position('authenticate_checked.png') if authenticate_checked: join_authenticate = get_position('join_authenticate.png') if join_authenticate: close_window() return 1 join_authenticate_checked = get_position('join_authenticate_checked.png') if join_authenticate_checked: close_window() return 2 close_window()
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 lock_screen(): log.info('lock the screen') SwitchThinProMode(switch_to='user') time.sleep(2) pyautogui.hotkey('ctrl', 'alt', 'l') time.sleep(2) size = common_function.screen_resolution() tool.click(int(size[0] / 2), int(size[1] / 2), 1) return True
def start(case_name, **kwargs): ip = check_ip_yaml() yml_path = get_current_dir("Test_Report/{}.yaml").format(ip) screensavertool = screensaver.ScreenSaver() params = { "case_name": case_name, "yml_path": yml_path, "screensavertool": screensavertool } step1(**params) SwitchThinProMode("user")
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") yml_path = kwargs.get("yml_path") new_cases_result(yml_path, case_name) SwitchThinProMode("user") event_list = [] event_dict = { "event_method": open_screensaver, "error_msg": {'actual': 'open screensaver fail'}, "case_name": case_name, "yml_path": yml_path } event_list.append(copy.deepcopy(event_dict)) event_dict = { "event_method": check_enable_screen_saver_status, "error_msg": {'actual': 'disabled', 'except': 'enabled'}, "case_name": case_name, "yml_path": yml_path } event_list.append(copy.deepcopy(event_dict)) event_dict.update({"event_method": check_default_time, 'except': '10', 'actual': ''}) event_list.append(copy.deepcopy(event_dict)) event_dict.update({"event_method": check_image_mapping, 'except': 'default', 'actual': ''}) event_list.append(copy.deepcopy(event_dict)) event_dict.update({"event_method": check_standard_image, 'except': 'disabled', 'actual': 'enabled'}) event_list.append(copy.deepcopy(event_dict)) event_dict.update({"event_method": check_require_password_in_admin, 'except': 'enabled', 'actual': 'disabled'}) event_list.append(copy.deepcopy(event_dict)) event_dict.update({"event_method": check_require_password_for_domain, 'except': 'enabled', 'actual': 'disabled'}) event_list.append(copy.deepcopy(event_dict)) event_dict.update({"event_method": check_require_passwoed_for_general_user, 'except': 'disabled', 'actual': 'enabled'}) event_list.append(copy.deepcopy(event_dict)) for i in event_list: res = event(**i) if not res: return False close_powermanager() return True
def set_user_password(): current_path = get_current_dir("Test_Data") temp_path = current_path + "/temp.png" user = current_path + "/td_power_manager/user_icon" enabled = user + "/enabled" change_path = user + "/change" SwitchThinProMode("admin") time.sleep(1) log.info("Open security desktop") os.popen( "hptc-control-panel --config-panel /etc/hptc-control-panel/applications/hptc-security.desktop" ) time.sleep(4) print(user) res = wait_element(user) if res: location, shape = res loc_x, loc_y = location offset_x, offset_y = 0, -20 loc = { "left": loc_x + offset_x, "top": loc_y + offset_y, "width": 500, "height": 40 } capture_screen_by_loc(temp_path, loc) enabled_list = get_folder_items(enabled, file_only=True) change_path_list = get_folder_items(change_path, file_only=True) flag = True for i in enabled_list: if compare_pic_similarity(enabled + "/{}".format(i), temp_path): break else: flag = False for i in change_path_list: change_res = compare_pic_similarity(change_path + "/{}".format(i), temp_path) if change_res: break else: change_res = False if flag and change_res: print(change_res, "change") change_loc, change_shape = change_res offset = (change_loc[0] + int(change_shape[1] / 2), change_loc[1] + int(change_shape[0] / 2)) print(offset) return (loc_x + offset_x, loc_y + offset_y), offset return False
def step5(*args, **kwargs): case_name = kwargs.get("case_name") yml_path = kwargs.get("yml_path") SwitchThinProMode("user") event_dict = { "event_method": wait_and_check_screen_saver, "event_params": ((1, ), {}), "call_back": move_mouse, "callback_parmas": ((), {}), "error_msg": { 'actual': 'screen saver launch fail, lock screen fail' }, "case_name": case_name, "yml_path": yml_path } return event(**event_dict)
def step1(*args, **kwargs): SwitchThinProMode("admin") case_name = kwargs.get("case_name") yml_path = kwargs.get("yml_path") new_cases_result(yml_path, case_name) power_manager = kwargs.get("power_manager") event_dict = { "event_method": set_ac_min_to_one, "event_params": ((power_manager, ), {}), "error_msg": { 'actual': 'set power manager fail' }, "case_name": case_name, "yml_path": yml_path } return event(**event_dict)
def step4(*args, **kwargs): case_name = kwargs.get("case_name") report_file = kwargs.get("report_file") SwitchThinProMode(switch_to='user') tl = TelnetLinux() tl.logon() lock_screen() time.sleep(2) pyautogui.press('enter') time.sleep(1) a = click_icon('locked_dialog') if not a: log.debug( "first check not found locked dialog", common_function.get_current_dir( 'Test_Report', 'img', '{}_locked_dialog.png'.format(case_name.replace(' ', '_')))) pyautogui.press('enter') time.sleep(1) a = click_icon('locked_dialog') pyautogui.press('esc') time.sleep(1) b = click_icon('locked_dialog') unlock_screen('root', '1') tl.logoff() log.info('press esc before {}, press esc after {}'.format(a, b)) if a and not b: steps = { 'step_name': "verify press esc key will dismiss the dialog", 'result': 'Pass', 'expect': 'success', 'actual': 'success', 'note': '' } common_function.update_cases_result(report_file, case_name, steps) else: steps = { 'step_name': "verify press esc key will dismiss the dialog", 'result': 'Fail', 'expect': 'success', 'actual': 'fail', 'note': '' } common_function.update_cases_result(report_file, case_name, steps) reset_settings() return False
def start(case_name, **kwargs): try: log.info('Begin to start case {}'.format(case_name)) result_file = os.path.join(get_current_dir(), r'Test_Report', '{}.yaml'.format(check_ip_yaml())) new_cases_result(result_file, case_name) SwitchThinProMode(switch_to='admin') if not check_fiber_exist(): log.error("not found fiber card on thin client") pre_check_report = { 'step_name': 'check_fiber_exist', 'result': 'Fail', 'expect': 'has fiber card on thin client', 'actual': 'not found fiber card on thin client', 'note': '' } cf.update_cases_result(result_file, case_name, pre_check_report) log.error("test case {} fail".format(case_name)) return False default_method = get_connection_method() wired = Wired() if dynamic_ip_check(case_name, result_file, wired) is False: reset_connection_method(default_method) return if dynamic_ip_ping(case_name, result_file) is False: reset_connection_method(default_method) return mask = wired.get_mask('eth1') gateway = wired.gateway() ip = modify_ip(gateway) if static_ip_check(case_name, result_file, wired, ip, mask, gateway) is False: reset_connection_method(default_method) return if static_ip_ping(case_name, result_file) is False: reset_connection_method(default_method) return except: log.debug( traceback.format_exc(), get_current_dir('Test_Report', 'img', '{}.png'.format(case_name))) os.system("wmctrl -c 'Control Panel'")
def step1(*args, **kwargs): case_name = kwargs.get("case_name") yml_path = kwargs.get("yml_path") sctool = kwargs.get("screensavertool") new_cases_result(yml_path, case_name) SwitchThinProMode("admin") event_dict = { "event_method": preparewakeup, "event_params": ((), {}), "call_back": resume_lock_screen, "callback_parmas": ((sctool, ), {}), "do_call_back_while_fail": True, "error_msg": { 'actual': 'wol wake up fail' }, "case_name": case_name, "yml_path": yml_path } return event(**event_dict)
def verify_remote_only(*args, **kwargs): case_name = kwargs.get("case_name") result_file = kwargs.get("report_file") user = kwargs.get('user') conn = kwargs.get('conn') start_remote('', conn=conn) time.sleep(5) log.info("verify only remote session's account is listed") require_pass_domain_users() SwitchThinProMode(switch_to='user') start_remote('logon', conn=conn) lock_screen() if check_account('no_vdi'): steps = { 'step_name': "only one remote session's account is listed", 'result': 'Pass', 'expect': 'success', 'actual': 'success', 'note': '' } common_function.update_cases_result(result_file, case_name, steps) unlock_screen(r'sh\{}'.format(user), 'Shanghai2010') else: error_pic = os.path.join(common_function.get_current_dir(), r'Test_Report', 'img', '{}+verify_remote_only.png'.format(case_name)) picture_operator.capture_screen(error_pic) steps = { 'step_name': "only one remote session's account is listed", 'result': 'Fail', 'expect': 'success', 'actual': 'fail', 'note': '{}'.format(error_pic) } common_function.update_cases_result(result_file, case_name, steps) unlock_screen(r'sh.dto\!#$%^', 'Shanghai2010') start_remote('', conn=conn)
def start(case_name, **kwargs): try: result_file = os.path.join(get_current_dir(), r'Test_Report', '{}.yaml'.format(check_ip_yaml())) log.info('Begin to start test {}'.format(case_name)) new_cases_result(result_file, case_name) SwitchThinProMode(switch_to='admin') wireless = Wireless() wireless.wired_wireless_switch('off') time.sleep(5) wireless.open_network() wireless.switch_to_wireless_tab() if add_wl(wireless, "R1-TC_5G_n", case_name, result_file) is False: wireless.close_control_panel() return edit_value_dict = { "ssid": "R1-TC_2.4G_n_WPA2P", "authentication": "WPA/WPA2-PSK", "password": "******" } if edit_wl(wireless, "R1-TC_5G_n", edit_value_dict, case_name, result_file) is False: wireless.close_control_panel() return if delete_wl(wireless, "R1-TC_2.4G_n_WPA2P", case_name, result_file): wireless.close_control_panel() return reset_setting(wireless, 'R1-TC_5G_n') reset_setting(wireless, 'R1-TC_2.4G_n_WPA2P') wireless.close_control_panel() except: log.error(traceback.format_exc()) error_pic = os.path.join(get_current_dir(), r'Test_Report', 'img', '{}.png'.format(case_name)) capture_screen(error_pic) os.system("wmctrl -c 'Control Panel'")
def add_domain(status_code, user_name, password, domain_name): if status_code == 0: Logger().info("setting nothing") return elif status_code != 1 and status_code != 2: Logger().info("invalid status code") return SwitchThinProMode(switch_to='admin') open_window("active directory") ad = get_position('ad.png') if not ad: Logger().info("find ad fail") return domain = get_position('domain_name.png') if not domain: Logger().info("find domain fail") return domain_txt_pos = (domain[1][0] + 200, domain[1][1]) pyautogui.click(domain_txt_pos) for i in range(20): pyautogui.hotkey('backspace') time.sleep(0.5) pyautogui.typewrite(domain_name) authenticate = get_position('authenticate.png') if not authenticate: Logger().info("find authenticate fail") return pyautogui.click(authenticate[1]) apply = get_position('apply.png') if not apply: Logger().info("find apply fail") return if status_code == 1: pyautogui.click(apply[1]) while True: enter = get_position('enter_authenticate.png') if enter: Logger().info("entering domain") else: break time.sleep(1) apply_checked = get_position('apply_checked.png') if not apply_checked: Logger().info("find apply_checked fail") close_window() return else: Logger().info("apply_checked pass") close_window() return True elif status_code == 2: join_authenticate = get_position('join_authenticate.png') if not join_authenticate: Logger().info("find join_authenticate fail") return pyautogui.click(join_authenticate[1]) pyautogui.click(apply[1]) dialog = get_position('dialog.png') if not dialog: Logger().info("find dialog fail") return user = get_position('user.png') if not user: Logger().info("find user fail") return pwd = get_position('pwd.png') if not user: Logger().info("find pwd fail") return pyautogui.click(user[1]) pyautogui.typewrite(user_name) pyautogui.click(pwd[1]) pyautogui.typewrite(password) ok = get_position('ok.png') if not user: Logger().info("find ok fail") return pyautogui.click(ok[1]) while True: enter = get_position('enter.png') if enter: Logger().info("entering domain") else: break time.sleep(1) apply_checked = get_position('apply_checked.png') if not apply_checked: Logger().info("find apply_checked fail") close_window() return else: Logger().info("apply_checked pass") close_window() return True
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): 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
def leave_domain(status_code, user_name, password): if status_code == 0: return True SwitchThinProMode(switch_to='admin') open_window("active directory") ad = get_position('ad.png') if not ad: Logger().info("find ad fail") return authenticate_checked = get_position('authenticate_checked.png') if not authenticate_checked: Logger().info("find authenticate fail") return pyautogui.click(authenticate_checked[1]) apply = get_position('apply.png') if not apply: Logger().info("find apply fail") return pyautogui.click(apply[1]) if status_code == 1: reboot_dialog = get_position('reboot_dialog.png') if reboot_dialog: pyautogui.hotkey("enter") time.sleep(1) pyautogui.hotkey("enter") Logger().info("reboot to exit dialog") remove_flag() return apply_checked = get_position('apply_checked.png') if not apply_checked: Logger().info("find apply_checked fail") close_window() return else: Logger().info("apply_checked pass") close_window() return True elif status_code == 2: reboot_dialog = get_position('reboot_dialog.png') if reboot_dialog: pyautogui.hotkey("enter") Logger().info("reboot to exit dialog") dialog = get_position('dialog.png') if not dialog: Logger().info("find dialog fail") return user = get_position('user.png') if not user: Logger().info("find user fail") return pwd = get_position('pwd.png') if not user: Logger().info("find pwd fail") return pyautogui.click(user[1]) pyautogui.typewrite(user_name) pyautogui.click(pwd[1]) pyautogui.typewrite(password) ok = get_position('ok.png') if not user: Logger().info("find ok fail") close_window() return pyautogui.click(ok[1]) while True: leave = get_position('leave.png') if leave: Logger().info("leaving domain") else: break time.sleep(1) pyautogui.hotkey("enter") return True else: dialog = get_position('dialog.png') if not dialog: Logger().info("find dialog fail") return user = get_position('user.png') if not user: Logger().info("find user fail") return pwd = get_position('pwd.png') if not user: Logger().info("find pwd fail") return pyautogui.click(user[1]) pyautogui.typewrite(user_name) pyautogui.click(pwd[1]) pyautogui.typewrite(password) ok = get_position('ok.png') if not user: Logger().info("find ok fail") close_window() return pyautogui.click(ok[1]) while True: leave = get_position('leave.png') if leave: Logger().info("leaving domain") else: break time.sleep(1) pyautogui.hotkey("enter") apply_checked = get_position('apply_checked.png') if not apply_checked: Logger().info("find apply_checked fail") close_window() return else: Logger().info("apply_checked pass") remove_flag() close_window() return True
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): 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