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 delete_old_email(): Outlook_Window = uiautomation.WindowControl( Name="Inbox - Microsoft Outlook") Outlook_Window.SetFocus() # delete all email in Inbox tree_control = Outlook_Window.TreeControl(Name="Favorite Folders") tree_control.SetFocus() inbox = tree_control.TreeItemControl(Name="Inbox") inbox.Click() # inbox_table = uiautomation.PaneControl(Name="Message Read") #(Name="Message Read") while uiautomation.PaneControl(Name="Message Read").Exists(1): inbox_table = uiautomation.PaneControl(Name="Message Read") inbox_table.Click() inbox_table.SendKeys('{Ctrl}' '{D}') while uiautomation.PaneControl(Name="Message Unread").Exists(1): inbox_table = uiautomation.PaneControl(Name="Message Unread") inbox_table.Click() inbox_table.SendKeys('{Ctrl}' '{D}') while uiautomation.PaneControl(Name="Message Unread").Exists(1): inbox_table = uiautomation.PaneControl(Name="Message Unread") inbox_table.Click() inbox_table.SendKeys('{Ctrl}' '{D}') while uiautomation.PaneControl(Name="Message Read").Exists(1): inbox_table = uiautomation.PaneControl(Name="Message Read") inbox_table.Click() inbox_table.SendKeys('{Ctrl}' '{D}') time.sleep(1)
def get_qrcode(): # 点击多开 duokai = uiautomation.WindowControl(searchDepth=1, SubName=u'电脑端微信多开') duokai.SetActive() time.sleep(1) edit = duokai.EditControl(LocalizedControlType=u'编辑') edit.Click(simulateMove=False) duokai.SendKeys('{Home}' + '{Shift}{End}' + 'C:\\WeChat') qidong = duokai.ButtonControl(Name=u'启动微信') qidong.Click(simulateMove=False) # 查找新的微信PC TODO wxlogin = uiautomation.PaneControl(searchDepth=2, ClassName='WeChatLoginWndForPC', Name=u'登录') # 可能是已登录,所以点击“切换账号” time.sleep(1) wxlogin.Click(ratioY=0.9, simulateMove=False) # window = uiautomation.WindowControl(searchDepth=1, SubName=u'启动微信') # ClassName='WeChatMainWndForPC', # window.SetActive() time.sleep(3) qrfile = './qr.png' wxlogin.CaptureToImage(qrfile) # f = open('./1.png', 'rb') # b = f.read() # f.close() return zbar_scan_qrcode(qrfile)
def open_qqbox(): """ 打开QQ群对话框界面 :return: """ # 1、任务栏窗口 task_mainWindow = auto.PaneControl(searchDepth=1, Name='任务栏') print(task_mainWindow) # 2、通过任务栏窗口获取用户提示通知区域 warn_part = task_mainWindow.ToolBarControl(Name="用户提示通知区域") print(warn_part) # 3、获取并点击QQ按钮 qq_button = warn_part.ButtonControl(foundIndex=2, searchDepth=1) # QQ名称 = '''QQ: 祝佰航(990095293)\r\n声音: 关闭\r\n消息提醒框: 关闭\r\n会话消息: 任务栏头像闪动''' # qq_button = warn_part.ButtonControl(Name=QQ名称, searchDepth=1) print(qq_button) qq_button.Click(waitTime=1.5) sleep(0.5) # 获取并激活QQ界面 main_window = auto.WindowControl(searchDepth=1, Name='QQ') main_window.SetActive() print(main_window) sleep(0.5) # 获取搜索框 search_Edit = main_window.EditControl(searchDepth=6, Name="搜索:联系人、群聊、企业") sleep(0.5) # 搜索群名称 search_Edit.SetFocus() search_Edit.SendKeys('中泰证券二部技术讨论') search_Edit.SendKeys('{Enter}') sleep(0.5) # 最大化打开的对话框 dialog_box = auto.WindowControl(Name='中泰证券二部技术讨论', searchDepth=1) print(dialog_box) dialog_box.Maximize()
def cards(self, combo, i, ii): while 1: try: self.stemTwoinitControl() data = self.getInputData(i, ii) card1 = data.get("卡号1") self._log.info(f"获得到的卡1数据是>>: {card1}") base_name = combo.GetSelectionPattern().GetSelection()[0].Name if len(re.compile(card1).findall(base_name)) != 0: self._log.info(f'以选择案例卡号>: {base_name}') else: combo.Click() card_id_list = [ i for i in combo.GetChildren() if i.ClassName == 'ListBoxItem' and i.Name ] for card_id in card_id_list: if len(re.compile(card1).findall(card_id.Name)) != 0: combo.Select(card_id.Name) break except Exception as e: tab = auto.TabControl(AutomationId='mainTab').TabItemControl( Name="emd.ViewModel.ColGridViewModel") tab.DoubleClick() auto.PaneControl( AutomationId='scroll').GetScrollPattern().SetScrollPercent( horizontalPercent=-1, verticalPercent=100) self._log.error(f"卡号对象消失,正在重新查找,报错信息为{e}") continue
def unhold_call(): OneX_Window = uiautomation.WindowControl(Name="Avaya one-X® Communicator") OneX_Window.SetFocus() onex_call = uiautomation.PaneControl(ClassName="ScrollViewer") onex_call.SetFocus() btn_end = onex_call.ButtonControl(AutomationId="ButtonHold") btn_end.Click()
def BatchRename(): foxitWindow = automation.WindowControl(searchDepth=1, ClassName='classFoxitReader') foxitWindow.ShowWindow(automation.ShowWindow.ShowMaximized) foxitWindow.SetActive() automation.Logger.Log(foxitWindow.Name[:-len(' - Foxit Reader')] + '\n') time.sleep(1) automation.SendKeys('{Ctrl}0') time.sleep(0.5) editToolBar = automation.ToolBarControl(searchFromControl=foxitWindow, AutomationId='59583', Name='Caption Bar') if editToolBar.Exists(0, 0): editToolBar.Click(0.96, 0.5) time.sleep(0.5) automation.SendKeys('{Alt}y') time.sleep(0.5) editToolBar = automation.ToolBarControl(searchFromControl=foxitWindow, AutomationId='60683', Name='Caption Bar') if editToolBar.Exists(0, 0): editToolBar.Click(0.96, 0.5) time.sleep(0.5) automation.SendKeys('{Alt}y') time.sleep(0.5) paneWindow = automation.WindowControl(searchFromControl=foxitWindow, AutomationId='65280') bookmarkPane = automation.PaneControl(searchFromControl=paneWindow, searchDepth=1, foundIndex=1) l, t, r, b = bookmarkPane.BoundingRectangle #bookmarkButton = automation.ButtonControl(searchFromControl= bookmarkPane, Name = '书签') # can't find, but automation -a can find it, why if bookmarkPane.Name == '书签': if r - l < 40: bookmarkButton = automation.ControlFromPoint(l + 10, t + 40) if bookmarkButton.Name == '书签': bookmarkButton.Click(simulateMove=False) else: bookmarkButton = automation.ControlFromPoint(l + 10, t + 40) if bookmarkButton.Name == '书签': bookmarkButton.Click(simulateMove=False) tree = automation.TreeControl(searchFromControl=foxitWindow, ClassName='SysTreeView32') childItems = tree.GetChildren() bookMarks = [] depth = 1 for treeItem in childItems: if treeItem.ControlType == automation.ControlType.TreeItemControl: RenameTreeItem(tree, treeItem, bookMarks, depth) fout = open('rename_pdf_bookmark.txt', 'wt', encoding='utf-8') depth = 1 for bookMark in bookMarks: DumpBookMark(fout, bookMark, depth) fout.close() if Renamed: automation.Logger.Log('rename pdf: ' + foxitWindow.Name) automation.SendKeys('{Ctrl}s') time.sleep(0.5) while '*' in foxitWindow.Name: time.sleep(0.5)
def call_out(phone_num): # OneX_Window = uiautomation.WindowControl(Name="Avaya one-X® Communicator") # OneX_Window.SetFocus() onex_call = uiautomation.PaneControl(ClassName = "ScrollViewer") onex_call.SetFocus() input_num = onex_call.EditControl(AutomationId = "TextBoxSearch") input_num.SetFocus() input_num.SendKeys(phone_num + '{Enter}')
def choose_account(num_email): # Utitled_Window = uiautomation.WindowControl(Name="Untitled - Message (HTML) ") # Utitled_Window.SetFocus() Utitled_Window = uiautomation.PaneControl(Name="Form Regions") Utitled_Window.SetFocus() btn_Account = Utitled_Window.SendKeys('{Alt}' '{A}') time.sleep(1) cust_email_1 = Utitled_Window.MenuControl(Name="Context Menu") Utitled_Window.SendKeys(num_email)
def click_logout(): OneX_Window = uiautomation.WindowControl(Name="Avaya one-X® Communicator") OneX_Window.SetFocus() onex_call = uiautomation.PaneControl(ClassName="ScrollViewer") onex_call.SetFocus() btn_setting = uiautomation.ButtonControl(AutomationId="ButtonMenu") btn_setting.Click() Menu = uiautomation.MenuControl(ClassName="ContextMenu") Menu.SetFocus() choose_logout = Menu.MenuItemControl(Name="Log Out") choose_logout.Click()
def click_receive_button(): Outlook_Window = uiautomation.WindowControl( Name="Inbox - Microsoft Outlook") Outlook_Window.SetFocus() Outlook_Window.SendKeys('{F9}') time.sleep(1) tree_control = Outlook_Window.TreeControl(Name="Favorite Folders") tree_control.SetFocus() inbox = tree_control.TreeItemControl(Name="Inbox") inbox.Click() inbox_table = uiautomation.PaneControl(Name="Message Unread") inbox_table.Click()
def get_pane_control(self, loc): try: if loc[0] == Wby.NAME: pane_control = auto.PaneControl(searchDepth=loc[2], Name=loc[1]) logger.info("深度为_{}_,名字为_{}__的pane_control获取成功".format( loc[2], loc[1])) return pane_control if loc[0] == Wby.AUTOMATIONID: pane_control = auto.PaneControl(searchDepth=loc[2], AutomationId=loc[1]) logger.info("深度为_{}_,id为_{}__的Pane_control获取成功".format( loc[2], loc[1])) return pane_control except: if loc[0] == Wby.NAME: logger.exception("深度为_{}_,名字为_{}__的pane_control获取失败".format( loc[2], loc[1])) if loc[0] == Wby.AUTOMATIONID: logger.exception("深度为_{}_,名字为_{}__的pane_control获取失败".format( loc[2], loc[1]))
def count_qr(): count = 1 log('start: ') while True: wxlogin = uiautomation.PaneControl(searchDepth=1, foundIndex=count, ClassName='WeChatLoginWndForPC', Name=u'登录') if not wxlogin.Exists(): break log('foundIndex: ' + str(count)) count += 1 log('stop: ') log('count: ' + str(count - 1))
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)
class LoginWindows: #登录界面主窗口 root_window = uiautomation.PaneControl(searchDepth=1, ClassName='Qt5QWindow') #登录窗口 login_root_window = root_window.CustomControl(searchDepth=1, Name='') auto_login=login_root_window.CheckBoxControl(searchDepth=1, Name='自动登录') remember_passwd = login_root_window.CheckBoxControl(searchDepth=1, Name='记住密码') username_edit=login_root_window.EditControl(searchDepth=1, foundIndex=1) password_edit=login_root_window.EditControl(searchDepth=1, foundIndex=2) login_button=login_root_window.ButtonControl(searchDepth=1, Name='登 录') #错误提示语获取 account_error_location=login_root_window.TextControl(foundIndex=2) #account_error_message=account_error_location.Name #服务器设置 server_config=login_root_window.ButtonControl(foundIndex=1, searchDepth=1)
def insert_inline_image(link_file): # Utitled_Window = uiautomation.WindowControl(Name="Untitled - Message (HTML) ") # Utitled_Window.SetFocus() set_Message = uiautomation.PaneControl(Name="Message") set_Message.SetFocus() # open insert picture window set_Message.SendKeys('{Alt}' '{N}' '{P}') time.sleep(1) insert_win = uiautomation.WindowControl(Name="Insert Picture") insert_win.SetFocus() insert_win.SendKeys('{Alt}' '{N}') insert_win.SendKeys(link_file) time.sleep(1) #click Insert button insert_win.SendKeys('{Alt}' '{S}') time.sleep(2)
def prepare_qr(): global handles global index handles = [] index = 0 log('prepare_qr(): ') count = 1 while True: wxlogin = uiautomation.PaneControl(searchDepth=1, foundIndex=count, ClassName='WeChatLoginWndForPC', Name=u'登录') if not wxlogin.Exists(): break log('foundIndex: ' + str(count)) handles.append(wxlogin.Handle) count += 1 log('count: ' + str(count-1)) log('prepare_qr() handles: ' + str(handles))
def GetPersonDetail(): detailWindow = automation.WindowControl(searchDepth=1, ClassName='TXGuiFoundation', SubName='的资料') detailPane = automation.PaneControl(searchFromControl=detailWindow, Name='资料') details = '' for control, depth in automation.WalkTree(detailPane, lambda c: c.GetChildren()): if control.ControlType == automation.ControlType.TextControl: details += control.Name elif control.ControlType == automation.ControlType.EditControl: details += control.CurrentValue() + '\n' details += '\n' * 2 detailWindow.Click(0.95, 0.02) return details
def get_browser_tab_url(browser: str): """ Get browser tab url, browser must already open :param browser: Support 'Edge' 'Google Chrome' and other Chromium engine browsers :return: Current tab url """ if browser.lower() == 'edge': addr_bar = auto.EditControl(AutomationId='addressEditBox') else: win = auto.PaneControl(Depth=1, ClassName='Chrome_WidgetWin_1', SubName=browser) temp = win.PaneControl(Depth=1, Name=browser).GetChildren()[1].GetChildren()[0] for bar in temp.GetChildren(): last = bar.GetLastChildControl() if last and last.Name != '': break addr_bar = bar.GroupControl(Depth=1, Name='').EditControl() url = addr_bar.GetValuePattern().Value return url
def rootCardInfo(self): while 1: try: group = auto.GroupControl(Name='账号基本信息').GetChildren() combo = group[2] break except: tab = auto.TabControl(AutomationId='mainTab').TabItemControl( Name='emd.ViewModel.ColGridViewModel') tab.DoubleClick() continue try: auto.PaneControl( AutomationId='scroll').GetScrollPattern().SetScrollPercent( horizontalPercent=-1, verticalPercent=100) self._log.info(f"滚动到选择卡号的位置") except: pass return combo
class LoginSuccessWindow: #登录后的主窗口 root_window = uiautomation.PaneControl(searchDepth=1, ClassName='Qt5QWindowIcon') #最上排元素位置 top_location = root_window.CustomControl(searchDepth=1, foundIndex=1) #聊天窗口 chat_box = top_location.ButtonControl(Name='') #用户消息 user_message = top_location.CustomControl(foundIndex=2, Name='') #设置 account_info = top_location.CustomControl(foundIndex=3) setting_options = account_info.MenuItemControl() #点击设置后会弹出框,变为主窗口,ClassName为Qt5QWindowPopupDropShadowSaveBits,ControlType=MenuControlTypeId setting_root_window = uiautomation.MenuControl( ClassName='Qt5QWindowPopupDropShadowSaveBits') #设置里的选项 options = setting_root_window.MenuItemControl(Name='选项') #修改密码 change_pwd_option = setting_root_window.MenuItemControl(Name='修改密码') #帮助手册 help_manual = setting_root_window.MenuItemControl(Name='帮助手册 F1') #意见反馈 feedback = setting_root_window.MenuItemControl(Name='意见反馈') #关于选项 about_option = setting_root_window.MenuItemControl(Name='关于') #退出选项 logout_option = setting_root_window.MenuItemControl(Name='退出') #是否退出当前账号弹框 confirm_to_quit = root_window.PaneControl(ClassName='Qt5QWindow', foundIndex=1) logout_yes = confirm_to_quit.ButtonControl(Name='是 Enter') logout_no = confirm_to_quit.ButtonControl(Name='否') #fast皮肤设置 window_skin_setting = top_location.CustomControl(foundIndex=6) #fast窗口大小、关闭设置 setting_window = top_location.CustomControl(foundIndex=5) min_window_fast = setting_window.ButtonControl(foundIndex=1) max_window_fast = setting_window.ButtonControl(foundIndex=2) close_window_fast = setting_window.ButtonControl(foundIndex=3)
def capture_qr(): # 先开count个微信PC TODO 目前手工做 # 然后对所有的登陆二维码进行截图 log('start: ') res = [] index = 1 firstHandle = 0 while True: wxlogin = uiautomation.PaneControl(searchDepth=1, ClassName='WeChatLoginWndForPC', Name=u'登录') if not wxlogin.Exists(): log('FATAL wxlogin not exists') break qrfile = str(index) + '_' + str(wxlogin.Handle) + '.png' # 如果handle和第一个handle重复,则退出 if firstHandle == 0: firstHandle = wxlogin.Handle elif firstHandle == wxlogin.Handle: break uiautomation.Win32API.SetForegroundWindow(wxlogin.Handle) time.sleep(0.2) wxlogin.CaptureToImage('qr/' + qrfile, x=45, y=80, width=190, height=190) url = 'http://mp.xxying.com:8090/' + qrfile res.append(url) log(str(index) + ': ' + url) index += 1 wxlogin.SendKeys('{ALT}{ESC}') log('total: ' + str(index - 1)) # 目前对方要求格式是每行一个url的文本,不是jsonarray # print(res) for i in range(len(res)): print(res[i]) log('stop: ')
class SystemManage: #新的主窗口,重新定义 sysmanage_root_window = uiautomation.PaneControl( searchDepth=1, ClassName='Qt5QWindowIcon') #系统管理层级 index2_root_windows = sysmanage_root_window.CustomControl(searchDepth=1, foundIndex=2, Name='') #角色、用户管理栏定位框的父级 index_1_i2_root_windows = index2_root_windows.CustomControl(searchDepth=1, foundIndex=1) #新增栏定位父级框 index_2_i2_root_windows = index2_root_windows.CustomControl(searchDepth=1, foundIndex=2) #用户管理栏父级框 chose_user_upgrade = index_1_i2_root_windows.PaneControl() #查找系统管理窗口 x1 = index_1_i2_root_windows.CustomControl(searchDepth=4, Name='') system_manage_window = x1.RadioButtonControl(Name='系统管理') #system_manage_window=sysmanage_root_window.RadioButtonControl(Name='系统管理') #用户管理界面 user_manage_button = chose_user_upgrade.CheckBoxControl(foundIndex=2) #新增按钮 add_new_button = index2_root_windows.ButtonControl(Name='新增')
def _geekbench4_run(): try: auto.WindowControl(searchDepth = 1,Name = 'Untitled - Geekbench 4 Pro').GetWindowPattern().Close() except: time.sleep(1) try: auto.WindowControl(searchDepth = 1,Name = 'Geekbench 4 Pro').GetWindowPattern().Close() except: time.sleep(1) run_path = 'C://Program Files (x86)//Geekbench 4//' os.chdir(run_path) os.system('start "" ".\Geekbench 4.exe"') """ ControlType: ButtonControl ClassName: CCPushButton AutomationId: CommandButton_101 Rect: (837,586,949,611)[112x25] Name: Enter License Handle: 0x90DA0(593312) Depth: 4 SupportedPattern: InvokePattern LegacyIAccessiblePattern """ time.sleep(2) i = 1 while(1): try: if auto.ButtonControl(Name = 'Run CPU Benchmark',searchDepth = 2,AutomationId = '120').Exists(): if auto.WindowControl(Name = 'Geekbench 4 Pro',searchDepth = 1).Exists(0.1): auto.ButtonControl(Name = 'Run CPU Benchmark',searchDepth = 2,AutomationId = '120').Click() break if auto.WindowControl(Name = 'Geekbench 4 Tryout',searchDepth = 1).Exists(0.1): auto.ButtonControl(Name = 'Enter License').Click() time.sleep(1) auto.EditControl(AutomationId = '1004',searchDepth = 4).Click() auto.EditControl(AutomationId = '1004',searchDepth = 4).SendKeys('*****@*****.**') auto.EditControl(AutomationId = '1006',searchDepth = 4).Click() auto.EditControl(AutomationId = '1006',searchDepth = 4).SendKeys('OTCRR-HDYE4-UPAJA-SJZPR-PSYTY-TUR3C-ECRZJ-QMJZF-3C6LE') auto.ButtonControl(Name = 'Unlock',searchDepth = 4).Click() auto.ButtonControl(searchDepth = 5, AutomationId = '2').Click() auto.WindowControl(Name = 'Geekbench 4 Tryout',searchDepth = 1).GetWindowPattern().Close() os.chdir(run_path) os.system('start "" "Geekbench 4.exe"') i = i+1 except: time.sleep(1) time.sleep(1) while(1): try: if not auto.WindowControl(Name = 'Benchmark Progress',searchDepth = 2).Exists(): break except: time.sleep(1) score_win = auto.PaneControl(Name = 'Geekbench Score',searchDepth = 6) result_dict = {} result_dict['Single-Core Score'] = score_win.TextControl(searchDepth = 7,foundIndex = 2).Name result_dict['Multi-Core Score'] = score_win.TextControl(searchDepth = 7,foundIndex = 4).Name time.sleep(10) auto.WindowControl(searchDepth = 1,Name = 'Untitled - Geekbench 4 Pro').GetWindowPattern().Close() auto.WindowControl(searchDepth = 1,Name = 'Geekbench 4 Pro').GetWindowPattern().Close() return result_dict
def multiPlay(): while 1: print(auto.GetRootControl()) subprocess.Popen(r'D:\Program Files\Nox\bin\MultiPlayerManager.exe') time.sleep(2) ysWindow = auto.PaneControl(searchDepth=1, ClassName='Qt5QWindow') if not ysWindow.Exists(3, 1): print('Can not find Qt5QWindow') exit(0) # print(ysWindow) ysWindow.SetTopmost(True) childC = ysWindow.GetChildren() print(childC) allselect = ysWindow.CheckBoxControl(searchDepth=3, Name=r'全选') allselect.Click() time.sleep(1) customC = childC[6] # print(customC) ComboB = customC.GetChildren() ComboBC = ComboB[1] #.GetChildren() # print(ComboBC) ComboBC.Click() time.sleep(2) ListC = ComboBC.ListControl() time.sleep(2) ListItems = ListC.GetChildren() print(ListItems) listitem0 = "" listitem1 = "" listitem2 = "" listitem3 = "" if len(ListItems) == 5: listitem0 = ListItems[0] listitem1 = ListItems[1] listitem2 = ListItems[2] listitem3 = ListItems[3] break else: allselect.Click() continue # listitem0.Click() time.sleep(3) #关闭模拟器 # ComboBC.Click() # time.sleep(1) listitem1.Click() time.sleep(4) SureClose = ysWindow.ButtonControl(searchDepth=4, Name=r"确认 Enter") SureClose.Click() time.sleep(3) #删除模拟器 ComboBC.Click() time.sleep(1) listitem2.Click() time.sleep(3) SureDelete = ysWindow.ButtonControl(searchDepth=4, Name=r"确认 Enter") SureDelete.Click() time.sleep(3) #添加模拟器 addandro = ysWindow.ButtonControl(searchDepth=4, Name=r'添加模拟器') addandro.Click() addan5 = ysWindow.ListItemControl(searchDepth=6, Name=r'Android7.1.2') addan5.Click() time.sleep(1) allselect.Click() time.sleep(1) allselect.Click() time.sleep(3) #启动模拟器 ComboBC.Click() time.sleep(2) listitem0.Click() time.sleep(2) Btc = childC[5] print(Btc) closeB = Btc.GetChildren() clb = closeB[6] print(clb) clb.Click()
def startGame(): ''' Scripts to start benchmarking ''' exeFile = r'{BENCH_DIRECTORY}//{GAME_EXECUTOR}'.format( BENCH_DIRECTORY=BENCH_DIRECTORY, GAME_EXECUTOR=GAME_EXECUTOR) ## Start game launcher # - return 0 and end the whole process, if failed # - otherwise, keep running the process tries = 10 while tries != 0: logger.info("Opening Game Launcher") startGame = win32api.ShellExecute(1, 'open', exeFile, '', '', 1) if tries == 1 and not startGame: screenShootName = utils.screen.saveScreenShoot( GAME_NAME, "OpenLauncherFailed") logger.error( 'Opening Game Launcher Failed! Screenshoot Created: %s' % screenShootName) print( "****** Failed to open Game Launcher!!! Process stopped ******\n" ) return 0 if startGame: logger.info("Open Game Launcher Succeed") print("Open Game Launcher Succeed!!") break else: tries -= 1 time.sleep(1) logger.info(_TAB + 'Waiting for game to start') ## Give 25 sec for the game to start print("Waiting for game to start...") time.sleep(15) #################################################################################### # Start Game loop = LOOP_TIMES while (loop != 0): time.sleep(5) FFXIV3 = auto.PaneControl( searchDepth=1, Name='FINAL FANTASY XIV: Heavensward Benchmark') FFXIV3.SetTopmost(True) FFXIV3.ButtonControl(foundIndex=16, Name='').Click() time.sleep(30) logger.info(_TAB + 'Starting Testing') print("Start Testing...") ## Perform normal Character control for 5 min utils.keyboardUtils.normBenchmarking(300) if loop == -1: break else: loop -= 1 logger.info('Loop times remained: %s' % loop) print("Loop times remained: %s\n" % loop) logger.info(_TAB + 'All Loop Finishbed') print("Finished!") #################################################################################### # Quit Game utils.input.key_input("esc") time.sleep(30) # Quit Game Luncher FFXIV3.SetTopmost(True) utils.input.key_input("esc") time.sleep(10) utils.input.key_input("enter") time.sleep(10) return startGame
def ClickPaneByAutomationId(self, automationId): try: sleep(2) automation.PaneControl(AutomationId=automationId).Click() except Exception as e: print("Pane点击异常" + '||原因:' + str(e))
import time import ctypes import uiautomation as auto import subprocess subprocess.Popen('TextExe.exe') #form1 = auto.WindowControl(searchDepth=1, Name='Form1') form1 = auto.PaneControl(searchDepth=1, ClassName='Chrome_WidgetWin_1') #form1 = auto.WindowControl(searchDepth=1, ClassName='ThunderRT6FormDC') #form1 = auto.WindowControl(searchDepth=1, ClassName='Progman') if not form1.Exists(3, 1): print('Can not find Zoom window') exit(0) # inputbox1 = form1.EditControl(foundIndex=1) # inputbox1.Click() # inputbox1.SendKeys('{Del}{Del}{Del}{Del}{Del}') # inputbox1.SendKeys('Hi') # time.sleep(1) # # inputbox2 = form1.EditControl(foundIndex=2) # inputbox2.Click() # inputbox2.SendKeys('{Del}{Del}{Del}{Del}{Del}') # inputbox2.SendKeys('World') # time.sleep(1) # inputbox3 = form1.EditControl(foundIndex=3) # inputbox3.Click()
def enter_meeting(): """ 未登录状态下腾讯视频会议加入会议! :return: """ window1 = uiautomation.WindowControl(searchDepth=1, Name='腾讯会议(LoadingWnd)') print(window1.Name) window1.SetActive() # 首页点击登录 login = window1.ButtonControl(searchDepth=5, Name='注册/登录') print(login.Name) login.Click() # 跳转后输入用户名,密码 login_user = window1.EditControl(Name='PhoneNumberEdit') print(login_user.Name) login_user.SendKeys('17610379173', interval=0.1) login_pwd = window1.EditControl(Name='Account_login_password_input') print(login_pwd.Name) login_pwd.Click() login_pwd.SendKeys('Wgd123456', interval=0.1) # 点击登录按钮 login_but = window1.ButtonControl(Name='登录') login_but.Click() # 默认为企业直接点击确定 determine_but = window1.ButtonControl(Name='确定') determine_but.Click() # 增加阻塞等待跳转,可使用 auto.uiautomation.SetGlobalSearchTimeout(15) 设置全局搜索超时 15秒 time.sleep(2) enter_meeting_but = window1.ButtonControl(Name='加入会议') print(enter_meeting_but.Name) enter_meeting_but.Click() time.sleep(2) # 获取腾讯会议加入会议页面 window2 = uiautomation.PaneControl(Name='ClientArea') enter_meeting_input = window2.EditControl( Name='Join_meeting_meeting_number') print(enter_meeting_input.Name) enter_meeting_input.Click() enter_meeting_input.SendKeys('792342214', interval=0.1) # 勾选麦克风,摄像头 mic_check_box = window2.CheckBoxControl(Name='自动连接音频') camera_check_box = window2.CheckBoxControl(Name='入会开启摄像头') # mic_check_box.GetTogglePattern().ToggleState 属性可判断是否勾选 返回 int 0,1 # 判断是否勾选 if mic_check_box.GetTogglePattern().ToggleState == 0: mic_check_box.Click() if camera_check_box.GetTogglePattern().ToggleState == 0: camera_check_box.Click() # 加入会议 join_meeting_but = window2.ButtonControl(Name='Join_meeting_Join_meeting') join_meeting_but.Click() # 获取视频会议选择音频接入方式弹窗 try: window3 = uiautomation.WindowControl(Name='(AudioSelectWndNew)') pc_audio_but = window3.ButtonControl(Name='使用电脑音频') audio_check = window3.CheckBoxControl(Name='入会时使用电 脑音频') print(audio_check.GetTogglePattern().ToggleState) if audio_check.GetTogglePattern().ToggleState == 0: audio_check.Click() time.sleep(1) pc_audio_but.Click() except Exception as e: print(e) # 获取视频会议主页面 window4 = uiautomation.WindowControl(Name='腾讯会议(InMeetingWnd)') window4.Maximize()
def _3dmark_run(): try: auto.PaneControl(searchDepth = 1,Name = '3DMark Professional Edition - Google Chrome').GetPattern(10009).Close() except: time.sleep(1) try: auto.WindowControl(Name = '3DMark Professional Edition',searchDepth = 1).GetWindowPattern().Close() except: time.sleep(1) run_path = 'C://Program Files//UL//3DMark//' os.chdir(run_path) os.system('start 3DMark.exe') time.sleep(5) try: setup_path = 'C://Program Files (x86)//Google//Chrome//Application' os.chdir(setup_path) except: setup_path = os.path.join(os.path.expanduser("~"), 'AppData') setup_path +='//Local//Google//Chrome//Application//' os.chdir(setup_path) while(1): try: web_path = 'start chrome.exe --start-maximized ' + auto.TextControl(searchDepth = 8,Name = 'HOME').GetLegacyIAccessiblePattern().Value break except: time.sleep(1) try: web_path = 'start chrome.exe --start-maximized ' + auto.HyperlinkControl(searchDepth = 8,Name = 'HOME').GetLegacyIAccessiblePattern().Value break except: time.sleep(1) os.system(web_path) #关闭提示 time.sleep(4) try: auto.ButtonControl(searchDepth = 3,Name = 'Advanced').Click() auto.HyperlinkControl(searchDepth = 5,Name = 'Proceed to 127.0.0.1 (unsafe)').Click() except: time.sleep(1) try: auto.ButtonControl(searchDepth = 3,Name = '高级').Click() auto.HyperlinkControl(searchDepth = 5,Name = '继续前往127.0.0.1(不安全)').Click() except: time.sleep(1) try: auto.PaneControl(searchDepth = 1,Name = '3DMark Professional Edition - Google Chrome').SetActive() except: time.sleep(1) result_dict = {} #跳转到basic选项卡运行测试并等待结果 while(1): try: auto.HyperlinkControl(searchDepth= 8,Name = 'BENCHMARKS').Click() break except: time.sleep(1) time.sleep(3) while(1): try: auto.TextControl(searchDepth = 11,Name = 'Benchmarks').Click() auto.TextControl(searchDepth = 11,Name = 'Benchmarks').SendKeys('{Down 3}') auto.TextControl(searchDepth = 14,Name = 'Time Spy').Click() time.sleep(2) auto.HyperlinkControl(searchDepth = 15,Name = 'RUN').Click() break except: time.sleep(1) #等待运行结果 while(1): try: if not auto.TextControl(searchDepth = 11,Name = 'Running benchmark').Exists(0.1): break except: time.sleep(3) #光标移动到结果读取结果 time_spy = {} while(1): try: try: time_spy['Score'] = "".join(auto.CustomControl(searchDepth = 10,AutomationId = 'viewResultsControls').TextControl(foundIndex = 3).Name.split()) time_result = auto.CustomControl(searchDepth = 10,AutomationId = 'RESULT_SINGLE') except: time_spy['Score'] = "".join(auto.GroupControl(searchDepth = 10,AutomationId = 'viewResultsControls').TextControl(foundIndex = 3).Name.split()) time_result = auto.GroupControl(searchDepth = 10,AutomationId = 'RESULT_SINGLE') time_spy['Graphics Score'] = "".join(time_result.ListControl(searchDepth = 11,foundIndex = 1).TextControl(foundIndex = 3).Name.split()) time_spy['CPU score'] = "".join(time_result.ListControl(searchDepth = 11,foundIndex = 4).TextControl(foundIndex = 3).Name.split()) result_dict['Time Spy'] = time_spy break except: time.sleep(1) time.sleep(180) #fire strike while(1): try: auto.HyperlinkControl(searchDepth= 8,Name = 'BENCHMARKS').Click() auto.TextControl(searchDepth = 11,Name = 'Benchmarks').Click() auto.TextControl(searchDepth = 11,Name = 'Benchmarks').SendKeys('{Down 15}') auto.TextControl(searchDepth = 14,Name = 'Fire Strike').Click() time.sleep(2) auto.HyperlinkControl(searchDepth = 15,Name = 'RUN').Click() break except: time.sleep(1) while(1): try: if not auto.TextControl(searchDepth = 11,Name = 'Running benchmark').Exists(): break except: time.sleep(3) fire_strike = {} while(1): try: try: fire_strike['Score'] = "".join(auto.CustomControl(searchDepth = 10,AutomationId = 'viewResultsControls').TextControl(foundIndex = 3).Name.split()) fire_result = auto.CustomControl(searchDepth = 10,AutomationId = 'RESULT_SINGLE') except: fire_strike['Score'] = "".join(auto.GroupControl(searchDepth = 10,AutomationId = 'viewResultsControls').TextControl(foundIndex = 3).Name.split()) fire_result = auto.GroupControl(searchDepth = 10,AutomationId = 'RESULT_SINGLE') fire_strike['Graphics score'] = "".join(fire_result.ListControl(searchDepth = 11,foundIndex = 1).TextControl(foundIndex = 3).Name.split()) fire_strike['Physics score'] = "".join(fire_result.ListControl(searchDepth = 11,foundIndex = 4).TextControl(foundIndex = 3).Name.split()) fire_strike['Combined score'] = "".join(fire_result.ListControl(searchDepth = 11,foundIndex = 6).TextControl(foundIndex = 3).Name.split()) result_dict['Fire Strike'] = fire_strike break except: time.sleep(1) time.sleep(180) #Night raid while(1): try: auto.HyperlinkControl(searchDepth= 8,Name = 'BENCHMARKS').Click() auto.TextControl(searchDepth = 11,Name = 'Benchmarks').Click() auto.TextControl(searchDepth = 11,Name = 'Benchmarks').SendKeys('{Down 25}') auto.TextControl(searchDepth = 14,Name = 'Night Raid').Click() time.sleep(2) break except: time.sleep(1) try: if auto.HyperlinkControl(searchDepth = 15,Name = 'INSTALL').Exists(): auto.HyperlinkControl(searchDepth = 15,Name = 'INSTALL').Click() except: time.sleep(1) while(1): try: auto.HyperlinkControl(searchDepth = 15,Name = 'RUN').Click() break except: time.sleep(10) while(1): try: if not auto.TextControl(searchDepth = 11,Name = 'Running benchmark').Exists(): break except: time.sleep(3) night_raid = {} while(1): try: try: night_raid['Score'] = "".join(auto.CustomControl(searchDepth = 10,AutomationId = 'viewResultsControls').TextControl(foundIndex = 3).Name.split()) night_result = auto.CustomControl(searchDepth = 10,AutomationId = 'RESULT_SINGLE') except: night_raid['Score'] = "".join(auto.GroupControl(searchDepth = 10,AutomationId = 'viewResultsControls').TextControl(foundIndex = 3).Name.split()) night_result = auto.GroupControl(searchDepth = 10,AutomationId = 'RESULT_SINGLE') night_raid['Graphics score'] = "".join(night_result.ListControl(searchDepth = 11,foundIndex = 1).TextControl(foundIndex = 3).Name.split()) night_raid['CPU score'] = "".join(night_result.ListControl(searchDepth = 11,foundIndex = 4).TextControl(foundIndex = 3).Name.split()) result_dict['Night Raid'] = night_raid break except: time.sleep(1) time.sleep(180) #sky drive while(1): try: auto.HyperlinkControl(searchDepth= 8,Name = 'BENCHMARKS').Click() auto.TextControl(searchDepth = 11,Name = 'Benchmarks').Click() auto.TextControl(searchDepth = 11,Name = 'Benchmarks').SendKeys('{Down 25}') auto.TextControl(searchDepth = 14,Name = 'Sky Diver').Click() time.sleep(2) auto.HyperlinkControl(searchDepth = 15,Name = 'RUN').Click() break except: time.sleep(1) while(1): try: if not auto.TextControl(searchDepth = 11,Name = 'Running benchmark').Exists(): break except: time.sleep(3) sky_drive = {} while(1): try: try: sky_drive['Score'] = "".join(auto.CustomControl(searchDepth = 10,AutomationId = 'viewResultsControls').TextControl(foundIndex = 3).Name.split()) sky_result = auto.CustomControl(searchDepth = 10,AutomationId = 'RESULT_SINGLE') except: sky_drive['Score'] = "".join(auto.GroupControl(searchDepth = 10,AutomationId = 'viewResultsControls').TextControl(foundIndex = 3).Name.split()) sky_result = auto.GroupControl(searchDepth = 10,AutomationId = 'RESULT_SINGLE') sky_drive['Graphics score'] = "".join(sky_result.ListControl(searchDepth = 11,foundIndex = 1).TextControl(foundIndex = 3).Name.split()) sky_drive['Physics score'] = "".join(sky_result.ListControl(searchDepth = 11,foundIndex = 4).TextControl(foundIndex = 3).Name.split()) sky_drive['Combined score'] = "".join(sky_result.ListControl(searchDepth = 11,foundIndex = 9).TextControl(foundIndex = 3).Name.split()) result_dict['Sky Drive'] = sky_drive break except: time.sleep(1) time.sleep(180) #api while(1): try: auto.HyperlinkControl(searchDepth= 8,Name = 'BENCHMARKS').Click() auto.TextControl(searchDepth = 11,Name = 'Benchmarks').Click() auto.TextControl(searchDepth = 11,Name = 'Benchmarks').SendKeys('{Down 30}') auto.TextControl(searchDepth = 14,Name = 'API Overhead feature test').Click() time.sleep(2) auto.HyperlinkControl(searchDepth = 15,Name = 'RUN').Click() break except: time.sleep(1) while(1): try: if not auto.TextControl(searchDepth = 11,Name = 'Running benchmark').Exists(): break except: time.sleep(3) api_score = {} while(1): try: api_result = auto.GroupControl(searchDepth = 10,AutomationId = 'RESULT_SINGLE') api_score['DirectX 11 multi-thread'] = "".join(api_result.ListControl(searchDepth = 11,foundIndex = 1).TextControl(foundIndex = 3).Name.split()) api_score['DirectX 11 single-thread'] = "".join(api_result.ListControl(searchDepth = 11,foundIndex = 2).TextControl(foundIndex = 3).Name.split()) api_score['DirectX 12'] = "".join(api_result.ListControl(searchDepth = 11,foundIndex = 3).TextControl(foundIndex = 3).Name.split()) api_score['Vulkan'] = "".join(api_result.ListControl(searchDepth = 11,foundIndex = 4).TextControl(foundIndex = 3).Name.split()) result_dict['api'] = api_score break except: api_result = auto.CustomControl(searchDepth = 10,AutomationId = 'RESULT_SINGLE') api_score['DirectX 11 multi-thread'] = "".join(api_result.ListControl(searchDepth = 11,foundIndex = 1).TextControl(foundIndex = 3).Name.split()) api_score['DirectX 11 single-thread'] = "".join(api_result.ListControl(searchDepth = 11,foundIndex = 2).TextControl(foundIndex = 3).Name.split()) api_score['DirectX 12'] = "".join(api_result.ListControl(searchDepth = 11,foundIndex = 3).TextControl(foundIndex = 3).Name.split()) api_score['Vulkan'] = "".join(api_result.ListControl(searchDepth = 11,foundIndex = 4).TextControl(foundIndex = 3).Name.split()) result_dict['api'] = api_score break #关闭窗口 while(1): try: auto.PaneControl(searchDepth = 1,Name = '3DMark Professional Edition - Google Chrome').GetPattern(10009).Close() auto.WindowControl(Name = '3DMark Professional Edition',searchDepth = 1).GetWindowPattern().Close() break except: time.sleep(1) return result_dict