Windows App 自動化測試-WinAppDriver-Appium 資料整理

最近負責項目組Windows App自動化測試框架搭建工做,在這裏簡單地把這個過程當中參考的資料整理起來,僅僅是搬運工,感謝大牛們分享的資料。 同時也記下本身遇到的一些問題和解決辦法。html

Windows App 自動化工具選取

11種免費Window App自動化工具介紹(英文版): https://testguild.com/automation-tools-desktop/git

9種 https://www.logigear.com/blog/test-automation/12-best-automation-tools-for-desktop-apps-in-2020/github

12 種 https://blog.testproject.io/2016/12/22/9-free-desktop-test-automation-tools/ windows

 

由於我所作項目測試的APP是部署在server端,須要在測試機上遠程訪問server,這方面對工具的選取有很大限制, 因此我選了集成在Appium裏的WinAppDriver,由於能夠用到Appium的遠程訪問功能。 我的以爲若是用Microsoft UI automation會方便些,它裏面定義了各類各樣的控件(Button, TreetMenu等),基本上直接調用現成的接口就能夠了,不須要花太多精力作二次開發,但它不能遠程訪問。用WinAppDriver須要二次開發,大部控件都要本身定義,須要編碼能力。我花了不少時間去調查是否能夠Mirosoft UI automation和Appium結合起來用, 可是沒有找到方法, 若是有朋友有找到合適的方法,歡迎一塊兒探討。session

 

Mirosoft UI automation

 

花了一些時間研究Mirosoft UI automation, 這裏順帶把以前參考資料列出來app

 

1.      官網介紹: https://docs.microsoft.com/en-us/dotnet/framework/ui-automation/ui-automation-fundamentals 框架

 

2.      詳細說明和例子ide

 

https://docs.microsoft.com/en-us/archive/msdn-magazine/2008/february/test-run-the-microsoft-ui-automation-library工具

 

3.      簡單明瞭的中文介紹: 測試

 

https://blog.csdn.net/ffeiffei/article/details/6637418

 

WinAppDriver 

 

官網介紹: http://appium.io/docs/en/drivers/windows/

 

Winappdriver整體介紹, 環境搭建,代碼樣本, 注意事項: 

 

https://techcommunity.microsoft.com/t5/testingspot-blog/winappdriver-and-desktop-ui-test-automation/ba-p/1124543#

 

環境安裝

1.      安裝Node.js 和Appium :

http://www.javashuo.com/article/p-djixlfqd-nb.html

建議Appium的非GUI和GUI版都安裝,咱們用的通常是非GUI,可是有時候能夠用GUI版本定位問題,好比經過Appium session定位元素。

2.      安裝WinAppDriver (官網上WinAppDriver是集成在Appium, 安裝了Appium,是不須要再安裝WinAppDriver,可是我安裝了Appium後,運行程序會提示WinAppDriver未安裝,多是版本問題)

參考 :https://www.cnblogs.com/nanshufang/p/winappdriver.html

 

基本步驟流程

1, 安裝Nodejs

2. 安裝Appium

3. 安裝WinAPPDriver(雖然Appium官網說不用單獨安裝這個,可是我試了不安裝會遇到問題)

4. 我是用C#, 在vs2015(2017)裏新建一個工程,並把經過Nuget安裝上Appium driver.

  具體設置過程參考: http://appium.io/docs/en/drivers/windows/

5. 啓動Appium 

6. 開啓開發者模式

7.啓動WinAppDriver.exe(這一步通常是不須要的,若是報WinAppDriver沒起來或沒安裝能夠試一試)

  在C:\Program Files (x86)\Windows Application Driver, 能夠雙擊裏面的WinAppDriver.exe文件

8. 環境好啦,開始寫測試代碼

 

定位元素-SDK-Inspect.exe

 

官方介紹: https://docs.microsoft.com/en-us/windows/win32/winauto/inspect-objects

 

這裏要注意:我發現有些朋友說裝了SDK後沒有找到inspect.exe, 我猜是由於有幾個版號,沒有找對文件夾,下圖是我電腦上實際找到的位置(找版號最大的,沒找到的話,把這幾個文件夾都看一下)  

 

C:\Program Files (x86)\Windows Kits\10\bin\10.0.17763.0\x86

 

 

遇到的問題和解決辦法

 

1.      安裝完appium,執行代碼,報如下錯誤:

An unknown server-side error occurred while processing the command. Original error: Could not verify WinAppDriver install; re-run install

解決辦法:下載安裝WinAppDriver

https://github.com/microsoft/WinAppDriver/releases/tag/v1.2-RC

 

Appium官方文檔是說Appium上有內置了WinAppDriver,不用單獨安裝。還有若是隻裝了GUI Appium,也會報這個錯,最好裝非GUI版本。

 

2.    Error:

Message: Test method Winformtest.CalculatorSession.TestMethod3 threw exception: OpenQA.Selenium.WebDriverException: Unexpected error. The URL '/session' did not map to a valid resourcer

緣由:

url 錯了

  //private const string WindowsApplicationDriverUrl = "http://127.0.0.1:4723";

改爲:   private const string WindowsApplicationDriverUrl = "http://127.0.0.1:4723/wd/hub";

3.   設置待測試APP的路徑:

appOptions.AddAdditionalCapability("app", @"C:\Program Files(x86)\....... \****.exe");

報錯:

OpenQA.Selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: The system cannot find the file specified

 

這個是我犯的低級錯誤,目錄中的(x86)前面有一個空格,加上空格就行了,爲了解決這個問題費了好多時間,一開始還覺得本身的方法不對。像這樣路徑之類信息必定要複製, 不能手動輸入

 

4.      以前跑均可以的,能夠執行點擊或者雙擊,忽然執行click()就報
An unknown error occurred in the remote end while processing the command

若是是Actions, 執行doubleclick() 就報Access Denied 

Element 實際是有找到的,由於代碼都沒改變,環境也沒變

網上找了有不少人遇到相似的問題,特別是遠程的時候,若是測試本地沒問題,看了解答的,都沒有找到根本緣由,有時候莫名其妙就行了,有說重啓電腦,切換語言的。

個人解決辦法:一樣的代碼,換成在本地跑,是能夠過的,因而又切換成server上,發現也好了,莫名其妙的, 後面發現若是把行測APP所在server(咱們用的是虛擬機)的窗口關閉或者最小化,就會報這個錯,若是保打開狀態,就沒問題

因此個人解決辦法是:保持窗口打開。

 

下面是網上找一些辦法,可是不能解決個人問題,也許能解決其餘朋友的問題,列在這。

https://github.com/Microsoft/WinAppDriver/issues/361

https://github.com/Microsoft/WinAppDriver/issues/357

https://github.com/microsoft/WinAppDriver/issues/892

https://github.com/microsoft/WinAppDriver/issues/907

相關文章
相關標籤/搜索