我必須爲WinForms應用程序構建一個自動化ui測試。我使用python 3.4與python的Windows擴展和pywinauto。使用menuStrip及其python項目
需要進行測試才能訪問應用程序的菜單,然後單擊其中一個子菜單項。
我使用下面的代碼來嘗試找到菜單。
#arrays to store the controls found
classes = []
objects = []
#recursive method to get all the controls
def getClasses(childHwnd, lparam):
objects.append(childHwnd)
classes.append(win32gui.GetWindowText(childHwnd))
return 1
#find handle of the main window
hwnd = win32gui.FindWindow(None, 'Form1')
#get all controls
win32gui.EnumChildWindows(hwnd, getClasses, "a")
# Result:
# objects [1509794, 3344468]
# classes ['Test', 'menuStrip1']
#trying to get the menu of the form
win32gui.GetMenu(hwnd) #Returns 0
圖片上,我測試了上面的代碼的形式爲:
正如你所看到的,menuStrip1被發現,但我還沒有找到一種方式來獲得它的孩子(Meniu 1,Meniu 2)。
有關如何查找菜單及其子項的任何想法?
你有沒有找到解決方案?我開始認爲pywinauto可能不支持這個選項。 – AdamMc331 2015-06-02 13:58:40
不幸的是,我沒有找到一種方法來使用pywinauto來做到這一點。嘗試其他解決方案後。我選擇使用另一種工具進行名爲Sikuli(http://www.sikuli.org/)的自動化測試。希望能幫助到你! – CristisS 2015-06-04 13:47:49
很高興知道。我轉而使用了AutoIt,這也是一種不同的腳本語言。它沒有我發現的菜單支持,但我學會了使用鍵盤上的「alt」鍵訪問Windows菜單,所以我只是使用鍵盤快捷鍵來做我所需要的。不過謝謝。 :) – AdamMc331 2015-06-04 13:49:32