def test_gitgui(): # Clone폴더 값 정의 clone_folder = "C:\\dev\\git\\UIAutomationExample" # Clone 대상 폴더가 존재할 경우 폴더를 지운다. import os if os.path.exists(clone_folder): os.system('rmdir /S /Q "{}"'.format(clone_folder)) # Clone 대상 폴더가 없는지 확인한다. if os.path.exists(clone_folder): assert False, "clone대상폴더가 지워지지 않음" # GIT GUI를 실행시킨다. import uiautomation as auto # 검색영역 클릭하기 auto.ButtonControl(searchDepth=3, Name='검색하려면 여기에 입력하십시오.').Click() # 검색영역에 값 입력하기 auto.EditControl(searchDepth=3, Name='검색 상자').SendKeys('git gui') # Git GUI아이콘 클릭하기 auto.TextControl(searchDepth=10, Name="Git GUI").Click() # 프로그램이 정상적으로 수행되었는지 확인한다. auto.WindowControl(searchDepth=1, Name="Git Gui") # 상단 메뉴를 통해 Clone을 수행 auto.MenuItemControl(searchDepth=8, Name="Repository").Click() auto.MenuItemControl(searchDepth=8, Name="Repository") # inspect를 통해서 menu의 AutomationId가 48이므로 이를 활용 auto.MenuItemControl(AutomationId = "48").Click() # 화면이 Clone Existing Repository 세부설정화면으로 이동되었는지 확인한다. # 아쉽게도 해당 APP은 "Clone Existing Repository"에 대한 정보를 확인할 수 없는 앱이어서 # 이후 동작으로 확인할 수 밖에 없다. # Source location 및 Target Directory 값 정의 source_location = "https://github.com/jjunghyup/UIAutomationExample.git" target_directory = "C:\\dev\\git\\UIAutomationExample" # Source Location값과 Target Directory값을 입력한다. auto.PaneControl(ClassName="TkChild", foundIndex=14).Click() auto.PaneControl(ClassName="TkChild", foundIndex=14).SendKeys(source_location) auto.PaneControl(ClassName="TkChild", foundIndex=11).Click() auto.PaneControl(ClassName="TkChild", foundIndex=11).SendKeys(target_directory) # 값이 정상적으로 입력된다. # 값을 Clipboard에 복사하고 붙여넣기 식으로 확인이 가능하지만 해당 내용은 이후에 작성 예정 # Clone 버튼을 클릭한다. auto.PaneControl(ClassName="TkChild", foundIndex=18).Click() # Clone 대상폴더가 존재하는지 확인한다. 10초 동안 확인한다. result = False for i in range(0, 10): if os.path.exists(clone_folder): result = True assert result, "clone대상폴더가 존재 하지 않음"
def get_menuItem_control(self, loc): try: if loc[0] == Wby.NAME: menuItem_control = auto.MenuItemControl(searchDepth=loc[2], Name=loc[1]) logger.info("深度为_{}_,名字为_{}__的menuItem_control获取成功".format( loc[2], loc[1])) return menuItem_control if loc[0] == Wby.AUTOMATIONID: menuItem_control = auto.MenuItemControl(searchDepth=loc[2], AutomationId=loc[1]) logger.info("深度为_{}_,id为_{}__的menuItem_control获取成功".format( loc[2], loc[1])) return menuItem_control except: if loc[0] == Wby.NAME: logger.exception( "深度为_{}_,名字为_{}__的menuItem_control获取失败".format( loc[2], loc[1])) if loc[0] == Wby.AUTOMATIONID: logger.exception( "深度为_{}_,名字为_{}__的menuItem_control获取失败".format( loc[2], loc[1]))
def staffSchedule(self, Name="人员排班", Depth=23, foundIndex=6): """ 选择原始数据页签 :param Name: 标签元素名称 :param Depth: 空间深度 :param foundIndex: 同种类控件序列号 :return: 页签控件 """ try: flag = uiautomation.MenuItemControl(Name=Name, Depth=Depth, fondIndex=foundIndex) flag.Click() except Exception as e: log.debug("Can not control EZAccess, because: %s" % e)
def accessPermissions(self, Name="门禁授权", Depth=11, foundIndex=1): """ 门禁授权 :param Name: :param Depth: :param foundIndex: :return: """ try: flag = uiautomation.MenuItemControl(Name=Name, Depth=Depth, fondIndex=foundIndex) flag.Click() except Exception as e: log.debug("Can not control EZAccess, because: %s" % e)
def holidayManagement(self, Name="假日管理", Depth=11, foundIndex=2): """ 假日管理 :param Name: :param Depth: :param foundIndex: :return: """ try: flag = uiautomation.MenuItemControl(Name=Name, Depth=Depth, fondIndex=foundIndex) flag.Click() except Exception as e: log.debug("Can not control EZAccess, because: %s" % e)
def tab_KeyWords(self, Name="请输入关键字", Depth=22, foundIndex=2): """ 点击右侧搜索框 :param Name: 标签元素名称 :param Depth: 空间深度 :param foundIndex: 同种类控件序列号 :return: 页签控件 """ try: flag = uiautomation.MenuItemControl(Name=Name, Depth=Depth, fondIndex=foundIndex) flag.Click() except Exception as e: log.debug("Can not control EZAccess, because: %s" % e)
def LeaveMgt(self, Name="请假处理", Depth=23, foundIndex=5): """ 选择请假处理页签 :param Name: 标签元素名称 :param Depth: 空间深度 :param foundIndex: 同种类控件序列号 :return: 页签控件 """ try: flag = uiautomation.MenuItemControl(Name=Name, Depth=Depth, fondIndex=foundIndex) flag.Click() except Exception as e: log.debug("Can not control EZAccess, because: %s" % e)
def buttenSort(self, Name="排序", Depth=23, foundIndex=30): """ 点击按钮排序,未识别 :param Name: :param Depth: :param foundIndex: :return: """ try: flag = uiautomation.MenuItemControl(Name=Name, Depth=Depth, fondIndex=foundIndex) flag.Click() return flag except Exception as e: log.debug("Can not control EZAccess, because: %s" % e)
def buttenPressDown(self, Name="下一页", Depth=16, foundIndex=31): """ 点击跳转下一页 :param Name: :param Depth: :param foundIndex: :return: """ try: flag = uiautomation.MenuItemControl(Name=Name, Depth=Depth, fondIndex=foundIndex) flag.Click() return flag except Exception as e: log.debug("Can not control EZAccess, because: %s" % e)
def checkbox(self, Name="全选", Depth=22, foundIndex=8): """ 全选,暂未识别 :param Name: :param Depth: :param foundIndex: :return: """ try: flag = uiautomation.MenuItemControl(Name=Name, Depth=Depth, fondIndex=foundIndex) flag.Click() return flag except Exception as e: log.debug("Can not control EZAccess, because: %s" % e)
def click_setting(): AvayaComm_Window = uiautomation.WindowControl(Name="Avaya Communicator") AvayaComm_Window.SetFocus() # logout old phone number not_login = AvayaComm_Window.TextControl(Name="Logged in") btn_ActionButton = AvayaComm_Window.ButtonControl( AutomationId="ActionButton") if not_login.Exists(1): not_login.Click() btn_logout = uiautomation.ButtonControl(Name="Logout") btn_logout.Click() time.sleep(2) btn_ActionButton.Click() # click Action button time.sleep(1) btn_ActionButton.Click() choose_setting = uiautomation.MenuItemControl(Name="Settings") choose_setting.Click()
def verify_content_email(): # mess = uiautomation.PaneControl(Name="Message") # mess.Click() # mess.SendKeys('{Ctrl}' '{A}') # mess.SendKeys('{Ctrl}' '{C}') # # get_mess = mess.SendKeys('{Ctrl}' '{V}') # get_mess = pywinauto.controls.mess.texts() inbox_table = uiautomation.PaneControl(Name="Message Unread") inbox_table.SendKeys('{Enter}') receive_win = uiautomation.WindowControl(Class="rctrl_renwnd32") receive_win.SetFocus() time.sleep(0.5) # #check inline image # show_image = receive_win.EditControl(Name="Info Bar") # if show_image.Exists(2): # show_image.Click() # time.sleep(1) # download_inline_image = uiautomation.MenuItemControl(Name="Download Pictures") # if download_inline_image.Exists(2): # download_inline_image.Click() # time.sleep(1) mess = uiautomation.PaneControl(Name="Message") mess.Click() time.sleep(1) select_btn = receive_win.SplitButtonControl(Name="Select") select_btn.Click() # mess.SendKeys('{Alt}' '{H}') # mess.SendKeys('{S}' '{L}') time.sleep(1) # mess.SendKeys('{A}') select_all = uiautomation.MenuItemControl(Name="Select All") select_all.Click() time.sleep(1) mess.SendKeys('{Ctrl}' '{C}') time.sleep(1) mess.SendKeys('{Alt}' '{F4}') time.sleep(1)
def find(self, ControlTypeName="Control", **kwargs): if ControlTypeName == "Control": control = auto.Control(**kwargs) if ControlTypeName == "ButtonControl": control = auto.ButtonControl(**kwargs) if ControlTypeName == "CalendarControl": control = auto.CalendarControl(**kwargs) if ControlTypeName == "CheckBoxControl": control = auto.CheckBoxControl(**kwargs) if ControlTypeName == "ComboBoxControl": control = auto.ComboBoxControl(**kwargs) if ControlTypeName == "CustomControl": control = auto.CustomControl(**kwargs) if ControlTypeName == "DataGridControl": control = auto.DataGridControl(**kwargs) if ControlTypeName == "DataItemControl": control = auto.DataItemControl(**kwargs) if ControlTypeName == "DocumentControl": control = auto.DocumentControl(**kwargs) if ControlTypeName == "EditControl": control = auto.EditControl(**kwargs) if ControlTypeName == "GroupControl": control = auto.GroupControl(**kwargs) if ControlTypeName == "HeaderControl": control = auto.HeaderControl(**kwargs) if ControlTypeName == "HeaderItemControl": control = auto.HeaderItemControl(**kwargs) if ControlTypeName == "HyperlinkControl": control = auto.HyperlinkControl(**kwargs) if ControlTypeName == "ImageControl": control = auto.ImageControl(**kwargs) if ControlTypeName == "ListControl": control = auto.ListControl(**kwargs) if ControlTypeName == "ListItemControl": control = auto.ListItemControl(**kwargs) if ControlTypeName == "MenuControl": control = auto.MenuControl(**kwargs) if ControlTypeName == "MenuBarControl": control = auto.MenuBarControl(**kwargs) if ControlTypeName == "MenuItemControl": control = auto.MenuItemControl(**kwargs) if ControlTypeName == "PaneControl": control = auto.PaneControl(**kwargs) if ControlTypeName == "ProgressBarControl": control = auto.ProgressBarControl(**kwargs) if ControlTypeName == "RadioButtonControl": control = auto.RadioButtonControl(**kwargs) if ControlTypeName == "ScrollBarControl": control = auto.ScrollBarControl(**kwargs) if ControlTypeName == "SemanticZoomControl": control = auto.SemanticZoomControl(**kwargs) if ControlTypeName == "SeparatorControl": control = auto.SeparatorControl(**kwargs) if ControlTypeName == "SliderControl": control = auto.SliderControl(**kwargs) if ControlTypeName == "SpinnerControl": control = auto.SpinnerControl(**kwargs) if ControlTypeName == "SplitButtonControl": control = auto.SplitButtonControl(**kwargs) if ControlTypeName == "StatusBarControl": control = auto.StatusBarControl(**kwargs) if ControlTypeName == "TabControl": control = auto.TabControl(**kwargs) if ControlTypeName == "TabItemControl": control = auto.TabItemControl(**kwargs) if ControlTypeName == "TextControl": control = auto.TextControl(**kwargs) if ControlTypeName == "ThumbControl": control = auto.ThumbControl(**kwargs) if ControlTypeName == "TitleBarControl": control = auto.TitleBarControl(**kwargs) if ControlTypeName == "ToolBarControl": control = auto.ToolBarControl(**kwargs) if ControlTypeName == "ToolTipControl": control = auto.ToolTipControl(**kwargs) if ControlTypeName == "TreeControl": control = auto.TreeControl(**kwargs) if ControlTypeName == "TreeItemControl": control = auto.TreeItemControl(**kwargs) if ControlTypeName == "WindowControl": control = auto.WindowControl(**kwargs) if control.Exists(): return control else: name = kwargs.__str__().replace(":", ":") Log.logger().error("元素查找失败%s" % name) autogui.screenshot("../log/%s.png" % name)
def RightClickMenuItemByName(self, name): try: sleep(2) automation.MenuItemControl(Name=name).RightClick() except Exception as e: print("按钮右击异常" + '||原因:' + str(e))
def ClickMenuByClassName(self, classname): try: sleep(2) automation.MenuItemControl(ClassName=classname).Click() except Exception as e: print("菜单按钮点击异常" + '||原因:' + str(e))
def mnuitemSave(): return automation.MenuItemControl(SubName="Save")
def mnuitemFile(): return automation.MenuItemControl(Name="File")
self.__log.info("删除案例成功") except: self.__log.info("自定义案例集里的所有案例删除成功") break def deleteList(self, case, select_item): custom_select_dict = { '银联发出的报文': 0, '银联接收的报文': 1, '删除案例': 2, } case.DoubleClick() self.__log.info('点击:{}'.format(case.Name)) case.RightClick() time.sleep(self.clcikout) select_list = auto.MenuItemControl( ClassName='MenuItem').GetParentControl().GetChildren() number = custom_select_dict[select_item] selection = select_list[number].TextControl() self.__log.info('选择菜单:{}-选项'.format(selection.Name)) selection.Click() def click_self(self): self.__log.info("点击【认证案例集】") return self.__AuthPO.getTab1().DoubleClick() def getCaseList(self): case_lists = [] case_list = auto.TreeItemControl( ClassName='TreeViewItem').GetChildren() for case in case_list: if case.ClassName == 'TreeViewItem':
class StepOne(): def __init__(self, Logger, conf1, conf2, DataLoad): self.__Conf1 = conf1 self.__Conf2 = conf2 self.__DataLoad = DataLoad self.__upwin = None self.__AuthPO = None self.__CustomPO = None self.__log = Logger self.setpOneinitControl() def setpOneinitControl(self): self.clcikout = int(self.__Conf1.get("timeout", "clickout")) self.logwait = int(self.__Conf1.get("timeout", "logwait")) self.click_menu = int(self.__Conf1.get("timeout", "click_menu")) self.inputtime = int(self.__Conf1.get("timeout", "inputtime")) self.__AuthPO = AuthPO.AuthPO(self.__Conf2.items("AuthPO")) self.__AuthPO.initControl(auto) self.__CustomPO = CustomPO.CustomPO(self.__Conf2.items("CostomPO")) self.__CustomPO.CustominitControl(auto) "左侧栏向右最大化" def rigthSide(self): try: splitter = auto.ThumbControl( ClassName='GridSplitter').GetClickablePoint() if splitter[0] < 400: auto.DragDrop(splitter[0], splitter[1], 600, splitter[1], 1) self.__log.info("左侧栏滑倒最右端") except: pass "添加案例" def addCase(self): self.__log.info("正在开始添加案例......") casepath = self.__DataLoad.load()[1] self.__log.info(f"获取到了案例数据>>>:{casepath}") self.__AuthPO.getTab1().DoubleClick() count = 0 for case in casepath: if count > 0: if case[0] != casepath[count - 1][0]: # 寻找左下角路径 self.clickLeftMeus(case[0]) else: self.clickLeftMeus(case[0]) self.findCase(case) count += 1 def CaseCompartion(self): self.__log.info("开始进行案例对比") self.__CustomPO.getTab2().DoubleClick() oldcase = [] newCase = {} exeNewList = [] for i in range(len(self.getCaseList())): oldcase.append(self.getCaseList()[i].TextControl().Name) path = self.__DataLoad.load() for i in range(len(path[1])): newCase[path[1][i][-1]] = path[1][i] for i in range(len(newCase)): if path[1][i][-1] in oldcase: newCase.pop(path[1][i][-1]) for a in newCase.values(): exeNewList.append(a) self.__log.info(f"添加案例失败的路径是{exeNewList}") if len(exeNewList) == 0: self.__log.info(f"没有需要额外添加的案例") else: self.__AuthPO.getTab1.DoubleClick() self.__log.info(f"开始执行失败案例的添加") count = 0 for case in exeNewList: if count > 0: if case[0] != exeNewList[count - 1][0]: self.clickLeftMeus(case[0]) else: self.clickLeftMeus(case[0]) self.findCase(case) count += 1 def findCase(self, case_list): self.__log.info("开始查找案例") count = 0 flag = True root = self.__AuthPO.getTree1().TextControl(Name=case_list[0]) temp_list = [ i for i in root.GetParentControl().GetChildren() if i.Name == 'emd.ViewModel.SubLevelViewModel' ] for path in range(1, len(case_list)): # 从路径的第二个开始搜索 for i in temp_list: focus_path = case_list[path] if i.TextControl().Name == case_list[path]: count += 1 if i.ButtonControl(): try: if i.ButtonControl().GetTogglePattern( ).ToggleState == 0: i.GetExpandCollapsePattern().Expand(0) except: pass # 获取展开节点的子节点 temp_list = [ temp for temp in i.GetChildren() if temp.Name == 'emd.ViewModel.SubLevelViewModel' ] if path == len(case_list) - 1: self.__log.info(f"自动滚到{case_list[path]}路径下") i.GetScrollItemPattern().ScrollIntoView() i.TextControl().Click() self.addList(i.TextControl(), "案例另存为自定义案例集") if count < len(case_list) - 1: self.__log.error(f'案例路径:{focus_path}书写错误,未找到该路径,请检查路径文件!') print(f'案例路径:{focus_path}书写错误,未找到该路径,请检查路径文件!') input("请按任意键退出。。。") exit(0) if flag is False: self.__log.error(f'案例路径:{focus_path}书写错误,未找到该路径,请检查路径文件!') print(f'案例路径:{focus_path}书写错误,未找到该路径,请检查路径文件!') input("请按任意键退出。。。") exit(0) def addList(self, case, select_item): certification_select_dict = { '案例另存为自定义案例集': 0, '银联发出的报文': 1, '银联接收的报文': 2, } case.DoubleClick() time.sleep(self.clcikout) case.RightClick() select_list = auto.MenuItemControl( ClassName='MenuItem').GetParentControl().GetChildren() number = certification_select_dict[select_item] selection = select_list[number].TextControl() self.__log.info('选择菜单:{}-选项'.format(selection.Name)) selection.Click()
def _passmark9_run(): try: auto.WindowControl(Name='PerformanceTest 9.0', searchDepth=1).GetWindowPattern().Close() except: time.sleep(1) run_path = 'C://Program Files//PerformanceTest//' os.chdir(run_path) os.system('start PerformanceTest64.exe') #等待更新窗口出现并关闭 while (1): try: #如果出现注册窗口 if auto.WindowControl( searchDepth=1, ClassName='PT' ).Name == 'PerformanceTest 9.0 Evaluation Version': reg_win = auto.WindowControl(searchDepth=2, Name='PassMark® PerformanceTest') regedit = reg_win.EditControl(searchDepth=3, AutomationId='1034') regedit.Click() regedit.GetValuePattern().SetValue('''BABAE HAN #AEESAQAB8VU7IDH999NMAEK9UAAPPTPKNFEUN86KXXY6V55Z5GAQHPBRUDHKZAS5553PQ5SGNSDSWX93RMZAPQ2QSN3TFSJSV536RR9ZYY5526KEUIVSUATG''' ) #regedit.SendKey('BABAE HAN{Enter}') #regedit.SendKey('{Ctrl}{End}{Enter}#AEESAQAB8VU7IDH999NMAEK9UAAPPTPKNFEUN86KXXY6V55Z5GAQHPBRUDHKZAS5553PQ5SGNSDSWX93RMZAPQ2QSN3TFSJSV536RR9ZYY5526KEUIVSUATG') auto.ButtonControl(AutomationId='10', searchDepth=3, Name='Register').Click() time.sleep(2) auto.ButtonControl(searchDepth=4, AutomationId='2').Click() else: break except: time.sleep(2) #先点击Test,然后RUN ALL Test,然后确定弹窗 while (1): try: auto.MenuItemControl(Name='Tests', searchDepth=3).Click() auto.MenuItemControl(searchDepth=3, Name='Run All Tests').Click() if auto.ButtonControl(searchDepth=3, AutomationId='2').Exists(): auto.ButtonControl(searchDepth=3, AutomationId='2').Click() time.sleep(60) continue auto.WindowControl(searchDepth=2, Name='Run all benchmark tests?').ButtonControl( searchDepth=3, AutomationId='6').Click() break except: auto.ButtonControl(searchDepth=3, AutomationId='2').Click() time.sleep(5) while (1): try: auto.CheckBoxControl(searchDepth=3, AutomationId='12104').Click() auto.ButtonControl(searchDepth=3, AutomationId='12100').Click() break except: time.sleep(5) auto.MenuItemControl(Name='File', searchDepth=3).Click() auto.MenuItemControl(searchDepth=3, Name='Save results as text...').Click() #C:\Users\QMW\Documents\PassMark\PerformanceTest9\PerfRes.txt auto.ButtonControl(searchDepth=3, AutomationId='1006').Click() if auto.WindowControl(searchDepth=3, Name='WARNING').Exists(): auto.ButtonControl(searchDepth=4, AutomationId='6').Click() file_path = os.path.join(os.path.expanduser("~"), 'Documents') filename = file_path + '//PassMark//PerformanceTest9//PerfRes.txt' print(filename) result_dict = {} with open(filename) as read_file: for line in read_file: if 'PassMark Rating (Composite average) : ' in line: line = line.replace('PassMark Rating (Composite average) : ', '') result_dict['PassMark Rating'] = "".join(line.split()) break if 'CPU Mark (Composite average) : ' in line: line = line.replace('CPU Mark (Composite average) : ', '') result_dict['CPU Mark'] = "".join(line.split()) if '3D Graphics Mark (Composite average) : ' in line: line = line.replace('3D Graphics Mark (Composite average) : ', '') result_dict['3D Graphics Mark'] = "".join(line.split()) if 'Disk Mark (Composite average) : ' in line: line = line.replace('Disk Mark (Composite average) : ', '') result_dict['Disk Mark'] = "".join(line.split()) if '2D Graphics Mark (Composite average) : ' in line: line = line.replace('2D Graphics Mark (Composite average) : ', '') result_dict['2D Graphics Mark'] = "".join(line.split()) if 'Memory Mark (Composite average) : ' in line: line = line.replace('Memory Mark (Composite average) : ', '') result_dict['Memory Mark'] = "".join(line.split()) auto.WindowControl(Name='PerformanceTest 9.0', searchDepth=1).GetWindowPattern().Close() return result_dict