def set_vpn(self, type, profile="profile_1", **kwargs): log.info("start set vpn") if type.lower() not in ["cisco", "pptp", "none"]: log.error("vpn type error") return False pyautogui.click(wait_element(self.vpn_pic("_connection_type"), offset=(400, 10))[0], interval=1) pyautogui.click(wait_element( self.vpn_pic("_type_{}".format(type.lower())))[0], interval=1) if type.lower() == "none": pass else: profile_data = YamlOperator( self.network_profile()).read()["vpn"][type.lower()][profile] print(profile_data) for key, value in profile_data.items(): pic_name = "_{}".format("_".join(key.split())) pyautogui.click(wait_element(self.vpn_pic(pic_name), offset=(200, 10))[0], interval=0.2) self.__clear() pyautogui.write(value, interval=0.1) auto_start = kwargs.get("auto_start", "null") if auto_start.lower() == "enable": self.enable_auto_start() elif auto_start.lower() == "disable": self.disable_auto_start() else: pass log.info("set vpn complete") return True
def restart_network(): log.info("restart network from network systray icon") nw = wait_element( cf.get_current_dir( "Test_Data/td_network/wired/_wired_connect_systray")) if not nw: log.error("not found network systray icon") return False pyautogui.click(nw[0]) stop = wait_element( cf.get_current_dir("Test_Data/td_network/wired/_systray_restart")) if not stop: log.error("not found network systray stop icon") return False pyautogui.click(stop[0]) wireless = network_setting.Wireless() for i in range(20): log.info("wait network disconnect...") time.sleep(2) if not wireless.check_wireless_connected(): log.info("network disconnected") break else: log.error("network disconnect fail") return False for i in range(40): log.info("wait network connect...") time.sleep(3) if wireless.check_wireless_connected(): log.info("network connected success") log.info("restart network from network systray icon success") return True log.error("network connected fail") log.error("restart network from network systray icon fail") return False
def step_2_2(): log.info("start check wireless after reboot") cf.SwitchThinProMode("admin") wireless = network_setting.Wireless() for i in range(24): log.info("wait connect wireless...") time.sleep(5) if wireless.check_wireless_connected(): log.info("wireless is connected") break else: log.error("connect wireless time out") return [False, "connect wireless time out"] if not wait_element(pic("_systray_connect")): log.error("not found the wireless systray icon") pyautogui.screenshot( cf.get_current_dir( "Test_Report/ssid_disable_and_enable_wireless_error.png")) return [False, "not found the wireless systray icon"] log.info("found the wireless systray icon") wireless.open_network() wireless.switch_to_wireless_tab() if not wait_element(pic("_black_add_gray_edit_del"), rate=0.99): log.error("not found the black add and edit delete") return [False, "not found the black add and edit delete"] log.info("found the black add and edit delete") wireless.close_control_panel() restore() # log.info("{:+^80}".format("test case pass")) return [True, "success"]
def __choose_cert_from_usb_disk(self, cert): pyautogui.click(wait_element(self.pic("_auth_ca_cert_USB_Disk"))[0]) pyautogui.click(wait_element(self.pic("_auth_USB_Disk"))[0], interval=1) # pyautogui.click(wait_element(self.pic("_auth_USB_Disk_certs"))[0], interval=1) pyautogui.click(wait_element( self.pic("_auth_USB_Disk_certs_{}".format(cert)))[0], interval=1) pyautogui.click(wait_element(self.pic("_auth_PEAP_ca_cert_open"))[0], interval=1)
def delete(self, ssid=""): icon = wait_element(self.pic("_move_mouse"), offset=(0, 10))[0] tool.click(icon[0], icon[1], num=2) if ssid: log.info("delete '{}' wireless ".format(ssid)) if wait_element(self.pic("_{}".format(ssid))): pyautogui.click(wait_element(self.pic("_{}".format(ssid)))[0], interval=2) pyautogui.press(keys='tab', presses=3) pyautogui.press(keys='space') pyautogui.press(keys='space') else: down_menu = wait_element(self.pic("_down_menu")) if down_menu: tool.click(down_menu[0][0], down_menu[0][1], num=10) if wait_element(self.pic("_{}".format(ssid))): pyautogui.click(wait_element( self.pic("_{}".format(ssid)))[0], interval=2) pyautogui.press(keys='tab', presses=3) pyautogui.press(keys='space') pyautogui.press(keys='space') else: log.info('{} wireless not exists'.format(ssid)) return False else: log.info('{} wireless not exists'.format(ssid)) return False else: log.info("delete the first wireless ".format(ssid)) ssid_title = wait_element(self.pic("_ssid_title".format(ssid)), offset=(20, 30))[0] tool.click(ssid_title[0], ssid_title[1]) pyautogui.click(wait_element(self.pic("_delete"))[0], interval=2) pyautogui.click(wait_element(self.pic("_yes"))[0], interval=2)
def disable_auto_start(self): disable = wait_element(self.vpn_pic("_auto_start_disable"), rate=0.99) if disable: log.info("auto start has disabled") return True else: pyautogui.click( wait_element(self.vpn_pic("_auto_start_enable"), rate=0.99, offset=(320, 10))[0]) log.info("disable auto start complate") return True
def edit(self, ssid, edit_value_dict): """ edit_value_dict like : {"ssid": "R1-TC_5G_n", "password": "******", ... , "static_ip": [ip, subnet_mask, gateway]} """ log.info("edit '{}' wireless profile".format(ssid)) icon = wait_element(self.pic("_move_mouse"), offset=(0, 10))[0] tool.click(icon[0], icon[1], num=2) if wait_element(self.pic("_{}".format(ssid))): pyautogui.click(wait_element(self.pic("_{}".format(ssid)))[0], interval=2) pyautogui.click(wait_element(self.pic("_edit"))[0], interval=2) else: down_menu = wait_element(self.pic("_down_menu"))[0] if down_menu: tool.click(down_menu[0], down_menu[1], num=10) if wait_element(self.pic("_{}".format(ssid))): pyautogui.click(wait_element(self.pic( "_{}".format(ssid)))[0], interval=2) pyautogui.click(wait_element(self.pic("_edit"))[0], interval=2) else: log.info('{} wireless not exists'.format(ssid)) return False else: log.info('{} wireless not exists'.format(ssid)) return False self.set_wireless_profile(edit_value_dict) if "static_ip" in edit_value_dict.keys(): self.set_ipv4_static(ip=edit_value_dict["static_ip"][0], subnet_mask=edit_value_dict["static_ip"][1], gateway=edit_value_dict["static_ip"][2]) self.apply_and_ok()
def logon_desktop_by_pic(self): desktops_path = get_current_dir("Test_Data/td_vdi/vdi_pic/citrix_workspace/desktops") desktop_path = get_current_dir("Test_Data/td_vdi/vdi_pic/citrix_workspace/{}".format(self.session.lower())) result = wait_element(desktops_path) if not result: return False loc, shape = result mouse.click(loc[0] + int(shape[1] / 2), loc[1] + int(shape[0] / 2)) result = wait_element(desktop_path) if not result: return False loc, shape = result # mouse.click(loc[0] + int(shape[1] / 2), loc[1] + int(shape[0] / 2)) pyautogui.click(loc[0] + int(shape[1] / 2), loc[1] + int(shape[0] / 2), interval=0.3, clicks=2) return True
def disable_wireless(self): disable = wait_element(self.pic("_disable_wireless"), rate=0.95) if disable: log.info("wireless has disabled") return True enable = wait_element(self.pic("_enable_wireless"), rate=0.99) if enable: pyautogui.click(enable[0][0] + 97, enable[0][1]) disable_1 = wait_element(self.pic("_disable_wireless"), rate=0.99) if disable_1: log.info("disable wireless success") return True else: log.error("disable wireless fail") return False
def __capture_part_screen(self, icon_path, position: tuple) -> tuple: save_path = get_current_dir("loc_demo.png") if not position: return picture_operator.wait_element(icon_path, offset=(0, 0)) if not len(position) == 4: raise KeyError( "Position must be a tuple as: (left, top, width, height)") left, top, width, height = position current_x, current_y = self.loc pos = { "left": current_x + left, "top": current_y + top, "width": width, "height": height } capture_screen_by_loc(file_path=save_path, loc_dic=pos) items = get_folder_items(icon_path, file_only=True, filter_name=".png") pic_path_list = list( map(lambda file_name: icon_path + f"/{file_name}", items)) for pic_item in pic_path_list: element_shape = compare_pic_similarity(img=pic_item, tmp=save_path) if element_shape: loc, size = element_shape loc_x, loc_y = loc current_left, current_top = current_x + left + loc_x, current_y + top + loc_y return (current_left, current_top), size return ()
def check_min_to_zero(): path = get_current_dir( "Test_Data/td_power_manager/verify_sleep_mode_disabled") res = wait_element(path) if res: return True return False
def __getattr__(self, item): log.info(f"-> Find Item: {item}") pic_path, offset, position = self.pic_settings.get(item, (None, ())) if not pic_path: raise KeyError(f"pic settings doesn't have Item: {item}") icon_path = get_current_dir(pic_path) if not os.path.exists(icon_path): raise PathNotFoundError( f"Pic Path: '{icon_path}' Not Exists, Current Path: {icon_path}" ) if not self.loc: element_shape = picture_operator.wait_element(icon_path, offset=(0, 0)) else: element_shape = self.__capture_part_screen(icon_path=icon_path, position=position) if not element_shape: raise PicNotFoundError( f"Item: '{item}' Icon not found, Current Path: {icon_path}") loc = self.__calculate_midpoint(loc=element_shape[0], size=element_shape[1], offset=offset) flow_obj = self.__class__(loc=loc, name=item, pic_path=pic_path) log.info(flow_obj) return flow_obj
def linux_check_locked(**kwargs): path = os.path.join(common_function.get_current_dir(), 'Test_Data', 'td_power_manager', 'locked_pic') path1 = kwargs.get('path', path) if picture_operator.wait_element(os.path.join(path1), cycle=1): return True else: return False
def check_password_frame_exist(flag=True): time.sleep(2) pic_path = common_function.get_current_dir("Test_Data/td_power_manager/loc_screen_pic") res = picture_operator.wait_element(pic_path) res_flag = True if res else False if res_flag == flag: return True return False
def click_icon(lis): log.info('check icon and click') path = os.path.join(common_function.get_current_dir(), 'Test_Data', 'td_power_manager', 'verify_s3_work') for i in lis: power_icon = picture_operator.wait_element(os.path.join(path, i), offset=(20, 10)) tool.click(power_icon[0][0], power_icon[0][1], 1)
def power_off_by_screen_lock(self): pyautogui.press("enter") time.sleep(1) tool_pic_rs = wait_element(self.pic("_tool")) if tool_pic_rs: pyautogui.click(tool_pic_rs[0]) power_rs = wait_element(self.pic("_power")) if not power_rs: self.log.error("not found power button") return False pyautogui.click(power_rs[0]) reboot_rs = wait_element(self.pic("_power_off")) if not reboot_rs: self.log.error("not found power_off button") return False pyautogui.click(reboot_rs[0]) self.log.info("start power off")
def check_powerpic(): path = get_root_path("Test_Data/td_precheck/Thinpro7.1/{}".format("estar_logo.png")) press_keys([keyboard.control_l_key, keyboard.alt_l_key, 's']) type_string('power') press_key(keyboard.down_key) press_key(keyboard.enter_key) estart_position = picture_operator.wait_element(path) return estart_position
def sw_user(p): path = os.path.join(common_function.get_current_dir(), 'Test_Data', 'td_power_manager', 'verify_domain_users', '{}'.format(p)) power_icon = picture_operator.wait_element(path, offset=(10, 10)) print(power_icon) if power_icon: tool.click(power_icon[0][0], power_icon[0][1], 3)
def check_object_exist(filename, cycle=3, offset=(10, 10), back=False): """ if you want to debug in main,back = True in get_root_path """ path = get_root_path( "Test_Data/td_precheck/Thinpro7.1/{}".format(filename), back=back) response = wait_element(path, cycle=cycle, offset=offset) print(response) return response
def click_icon(name, **kwargs): try: n = '' count = kwargs.get('count', n) path = os.path.join(common_function.get_current_dir(), 'Test_Data', 'td_power_manager', 'verify_screen_lock_dialog', '{}'.format(name)) if count: icon_location = picture_operator.wait_element(path, offset=(8, 10)) print(icon_location) if icon_location: tool.click(icon_location[0][0], icon_location[0][1], count) print('click icon') else: return picture_operator.wait_element(path) except: log.warning(traceback.format_exc()) pass
def get_cup_mode(): path = os.path.join(common_function.get_current_dir(), 'Test_Data', 'td_power_manager', 'verify_ac_default_value', 'ondemand') if wait_element(path): cpu_mode = 'ondemand' else: cpu_mode = 'performance' log.info('get cpu mode:{}'.format(cpu_mode)) return cpu_mode
def check_icon(name): log.info('check the picture {}'.format(name)) path = os.path.join(common_function.get_current_dir(), 'Test_Data', 'td_power_manager', 'verify_screensaver_works_in_system_image_mode', '{}'.format(name)) if os.path.exists(path): if wait_element(path): return True
def step_7_8(**kwargs): log = kwargs.get("log") case_name = kwargs.get("case_name") user_password = kwargs.get("user_password", "1") try: log.info("start set the user password") set_user_password(password=user_password) os.system("mclient --quiet set root/screensaver/lockScreenUser 1" ) # enable require password for general users os.system("mclient commit") log.info("enable require password for general users") pmcf.SwitchThinProMode("user") screensaver = ScreenSaver() log.info("lock screen") screensaver.lock_screen_by_hotkey() # lock screen time.sleep(2) pyautogui.click() time.sleep(2) if not wait_element(pic("_screen_lock_by_user")): log.error("not found the lock screen dialog") pyautogui.click() return [False, "not found the lock screen dialog"] log.info("found the lock screen dialog") pyautogui.typewrite(user_password) time.sleep(1) pyautogui.press("enter") time.sleep(2) if wait_element(pic("_screen_lock_by_user")): log.error("unlock fail") log.debug( "unlock fail", cf.get_current_dir( 'Test_Report', 'img', '{}.png'.format(case_name.replace(' ', '_')))) screensaver.resume_screensaver_by_keyboard() pyautogui.screenshot( cf.get_current_dir("Test_Report/screen_lock_citrix_error.png")) return [False, "unlock fail"] log.info("unlock success") return [True, "unlock success"] except: log.error(traceback.format_exc()) return [False, traceback.format_exc()]
def lock_screen(): log.info('lock the screen') path = common_function.get_current_dir('Test_Data', 'td_power_manager', 'desktop') for _ in range(3): pyautogui.hotkey('ctrl', 'alt', 'l') time.sleep(2) if not wait_element(path): break time.sleep(2)
def clear_text(self, name): log.info('clear {} proxy info'.format(name)) icon_location = wait_element(self.dns_pic(name), offset=(200, 10)) if icon_location: tool.click(icon_location[0][0], icon_location[0][1], 3) else: return time.sleep(1) pyautogui.press('backspace') time.sleep(0.5) return True
def connect_vdi_by_pic(self): pth = get_current_dir("Test_Data/td_vdi/vdi_pic/{}".format(self.vdi)) res = wait_element(pth) if not res: log.error('picture {} match fail'.format(pth)) return False offset, shape = res print(offset, shape) # mouse.click(offset[0] + int(shape[1] / 2), offset[1] + int(shape[0] / 2), n=3) pyautogui.click(offset[0] + int(shape[1] / 2), offset[1] + int(shape[0] / 2), interval=0.1, clicks=3) return True
def __set_value(self, name, text): icon_location = wait_element(self.dns_pic(name), offset=(200, 10)) if icon_location: tool.click(icon_location[0][0], icon_location[0][1], 3) time.sleep(0.5) pyautogui.press('backspace') else: log.info('not find position {}'.format(self.dns_pic(name))) return time.sleep(1) pyautogui.typewrite(text) return True
def open_dns(self): log.info('Open NetWork DNS from Control Panel') for i in range(2): self.open_network() time.sleep(5) icon_location = wait_element(self.dns_pic("dns"), offset=(10, 10)) if not icon_location: log.info('not find position {}'.format(self.dns_pic("dns"))) continue tool.click(icon_location[0][0], icon_location[0][1], 1) break return True
def wait_pictures(self, pic_folder_name): ''' Wait a desired picture. If exists, return its coordinate. :param pic_folder_name: folder name of pictures. e.g. 'right_down_corner' :return: tuple of coordinate. e.g. () ''' pic_folder = self.path + '/Test_Data/td_network/wireless/{}'.format(pic_folder_name) result = wait_element(pic_folder, rate=0.97) if result: return result[0] else: self.log.info('Not found {} picture.'.format(pic_folder_name)) 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