appium實現 windows app UI自動化

1:環境和要求node

    1.1  windows PC 或 windows10 或更高版本python

    1.2  開啓電腦的開發者模式web

    1.3  appium安裝的時候會幫你默認安裝winappdriver,但可能版本不匹配,因此你須要從新下載winappdriver,json

    1.4 除了winappdriver,你還要下載windows sdk windows

2:啓動會話參數session

    2.1   對於uwp應用(對於uwp應用能夠自行百度),官網稱之爲通用windows平臺應用程序,對於這種uwp應用,啓動參數如圖所示:app

from appium import webdriver
desired_caps={
'platformName':'Windows',
'deviceName':'WindowsPC',
#'app':'C:\Program Files (x86)\E-Ceph\e-ceph.exe',#通用windows應用程序
'app':'application id',# application id 能夠經過向開發詢問,相似這種的Microsoft.WindowsAlarms_8wekyb3d8bbwe!App
}
driver=webdriver.Remote("http://127.0.0.1:4724/wd/hub",desired_capabilities=desired_caps)
2.2 對於飛uwp應用,官網稱之爲經典windows應用程序,啓動參數如圖所示:
from appium import webdriver
desired_caps={
'platformName':'Windows',
'deviceName':'WindowsPC',
'app':'C:\Program Files (x86)\E-Ceph\e-ceph.exe',#經典windows應用程序,爲應用程序的安裝路徑
#'app':'application id', application id 能夠經過向開發詢問,相似這種的Microsoft.WindowsAlarms_8wekyb3d8bbwe!App
}
driver=webdriver.Remote("http://127.0.0.1:4724/wd/hub",desired_capabilities=desired_caps)
3:啓動會話參數遇到過的問題
3.1 -r restall winappdriver (我一開始沒有本身從新安裝winappdriver,因此包這個錯,後面從新安裝winappdriver後解決了)
3.2 Failed to locate opened application window with appId: C:\Program Files (x86)\E-Ceph\e-ceph.exe, and processId: 480(對於這個報錯,我試過不少種方法都沒有解決,後面查看appium日誌的時候發現個人appium監聽
的是localhost:4723端口,python代碼中寫的也是localhost:4723,可是經過查看appium日誌,發現winappdriver啓動的監聽端口是loccalhost:4724端口,後面在python代碼中把啓動會話參數改爲localhost:4724端口就解決了,附上
appium的winappdriver日誌
The server is running [Appium] Welcome to Appium v1.10.0 [Appium] Non-default server args: [Appium] address: 127.0.0.1 [Appium] Appium REST http interface listener started on 127.0.0.1:4723 [HTTP] --> POST /wd/hub/session [HTTP] {"capabilities":{"firstMatch":[{"appium:deviceName":"WindowsPC","platformName":"Windows","appium:app":"C:\\Program Files (x86)\\E-Ceph\\e-ceph.exe"}]},"desiredCapabilities":{"app":"C:\\Program Files (x86)\\E-Ceph\\e-ceph.exe","platformName":"Windows","deviceName":"WindowsPC"}} [W3C] Calling AppiumDriver.createSession() with args: [{"app":"C:\\Program Files (x86)\\E-Ceph\\e-ceph.exe","platformName":"Windows","deviceName":"WindowsPC"},null,{"firstMatch":[{"appium:deviceName":"WindowsPC","platformName":"Windows","appium:app":"C:\\Program Files (x86)\\E-Ceph\\e-ceph.exe"}]}] [BaseDriver] Event 'newSessionRequested' logged at 1568945998600 (10:19:58 GMT+0800 (中國標準時間)) [Appium] Creating new WindowsDriver (v1.5.1) session [Appium] Capabilities: [Appium] platformName: Windows [Appium] deviceName: WindowsPC [Appium] app: C:\Program Files (x86)\E-Ceph\e-ceph.exe [BaseDriver] Creating session with MJSONWP desired capabilities: {"app":"C:\\Program Files (...
[BaseDriver] The following capabilities were provided, but are not recognized by appium: app. [BaseDriver] Session created with session id: 9f0d3fbc-1e48-4825-b81d-d3f7bb416b27 [WinAppDriver] You must use WinAppDriver version 1.1 [WinAppDriver] Verifying WinAppDriver version 1.1 is installed via comparing the checksum. [WinAppDriver] WinAppDriver changed state to 'starting' [WinAppDriver] Killing any old WinAppDrivers on same port, running: FOR /F "usebackq tokens=5" %a in (`netstat -nao ^| findstr /R /C:"4724 "`) do (FOR /F "usebackq" %b in (`TASKLIST /FI "PID eq %a" ^| findstr /I winappdriver.exe`) do (IF NOT %b=="" TASKKILL /F /PID %a)) [WinAppDriver] No old WinAppDrivers seemed to exist [WinAppDriver] Spawning winappdriver with: 4724/wd/hub [WinAppDriver] [STDOUT] Windows Application Driver listening for requests at: http://127.0.0.1:4724/wd/hub
[JSONWP Proxy] Proxying [GET /status] to [GET http://127.0.0.1:4724/wd/hub/status] with no body
[WinAppDriver] [STDOUT] Press ENTER to exit. [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] ========================================== [WinAppDriver] [STDOUT] GET /wd/hub/status HTTP/1.1 [WinAppDriver] [STDOUT] Accept: application/json, */* [WinAppDriver] [STDOUT] Connection: close [WinAppDriver] [STDOUT] Content-Type: application/json; charset=utf-8 [WinAppDriver] [STDOUT] Host: 127.0.0.1:4724 [WinAppDriver] [STDOUT] User-Agent: appium [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] HTTP/1.1 200 OK [WinAppDriver] [STDOUT] Content-Length: 147 [WinAppDriver] [STDOUT] Content-Type: application/json [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] {"build":{"revision":"18001","time":"Tue Sep 18 18:35:38 2018","version":"1.1.1809"},"os":{"arch":"amd64","name":"windows","version":"10.0.18362"}} [JSONWP Proxy] Got response with status 200: "{\"build\":{\"revision\":\"18001\",\"time\":\"Tue Sep 18 18:35:38 2018\",\"version\":\"1.1.1809\"},\"os\":{\"arch\":\"amd64\",\"name\":\"windows\",\"version\":\"10.0.18362\"}}" [WinAppDriver] Status call returned 200. we're online and ready to run tests [WinAppDriver] WinAppDriver changed state to 'online' [JSONWP Proxy] Matched '/session' to command name 'createSession' [JSONWP Proxy] Proxying [POST /session] to [POST http://127.0.0.1:4724/wd/hub/session] with body: {"desiredCapabilities":{"app":"C:\\Program Files (x86)\\E-Ceph\\e-ceph.exe","platformName":"Windows","deviceName":"WindowsPC"}} [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] ========================================== [WinAppDriver] [STDOUT] POST /wd/hub/session HTTP/1.1 [WinAppDriver] [STDOUT] Accept: application/json, */* [WinAppDriver] [STDOUT] Connection: close [WinAppDriver] [STDOUT] Content-Length: 127 [WinAppDriver] [STDOUT] Content-Type: application/json; charset=utf-8 [WinAppDriver] [STDOUT] Host: 127.0.0.1:4724 [WinAppDriver] [STDOUT] User-Agent: appium [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] {"desiredCapabilities":{"app":"C:\\Program Files (x86)\\E-Ceph\\e-ceph.exe","platformName":"Windows","deviceName":"WindowsPC"}} [WinAppDriver] [STDOUT] HTTP/1.1 500 Internal Error [WinAppDriver] [STDOUT] Content-Length: 180 [WinAppDriver] [STDOUT] Content-Type: application/json [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] {"status":13,"value":{"error":"unknown error","message":"Failed to locate opened application window with appId: C:\\Program Files (x86)\\E-Ceph\\e-ceph.exe, and processId: 13284"}} [JSONWP Proxy] Got an unexpected response: {"status":13,"value":{"error":"unknown error","message":"Failed to locate opened application window with appId: C:\\Program Files (x86)\\E-Ceph\\e-ceph.exe, and processId: 13284"}} [W3C] Matched W3C error code 'unknown error' to UnknownError [WinAppDriver] Deleting WinAppDriver session [BaseDriver] Event 'newSessionStarted' logged at 1568946006679 (10:20:06 GMT+0800 (中國標準時間)) [W3C] Encountered internal error running command: UnknownError: An unknown server-side error occurred while processing the command. Original error: Failed to locate opened application window with appId: C:\Program Files (x86)\E-Ceph\e-ceph.exe, and processId: 13284 [W3C] at errorFromW3CJsonCode (C:\Users\edz\AppData\Local\appium-desktop\app-1.10.0\resources\app\node_modules\appium-base-driver\lib\protocol\errors.js:802:25) [W3C] at ProxyRequestError.getActualError (C:\Users\edz\AppData\Local\appium-desktop\app-1.10.0\resources\app\node_modules\appium-base-driver\lib\protocol\errors.js:685:14) [W3C] at JWProxy.command (C:\Users\edz\AppData\Local\appium-desktop\app-1.10.0\resources\app\node_modules\appium-base-driver\lib\jsonwp-proxy\proxy.js:234:19) [HTTP] <-- POST /wd/hub/session 500 8102 ms - 1015 [HTTP] [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] ========================================== [WinAppDriver] [STDOUT] POST /wd/hub/session HTTP/1.1 [WinAppDriver] [STDOUT] Accept: application/json [WinAppDriver] [STDOUT] Accept-Encoding: identity [WinAppDriver] [STDOUT] Content-Length: 291 [WinAppDriver] [STDOUT] Content-Type: application/json;charset=UTF-8 [WinAppDriver] [STDOUT] Host: 127.0.0.1:4724 [WinAppDriver] [STDOUT] User-Agent: appium/python 0.38 (selenium/3.141.0 (python windows)) [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] HTTP/1.1 200 OK [WinAppDriver] [STDOUT] Content-Length: 150 [WinAppDriver] [STDOUT] Content-Type: application/json [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] {"sessionId":"877F8D9D-8BBE-4A38-B91F-F158EC4FF1E7","status":0,"value":{"app":"C:\\Program Files (x86)\\E-Ceph\\e-ceph.exe","platformName":"Windows"}} [HTTP] --> POST /wd/hub/session [HTTP] {"desiredCapabilities":{"app":"C:\\Program Files (x86)\\E-Ceph\\e-ceph.exe","platformName":"Windows","deviceName":"WindowsPC"},"capabilities":{"firstMatch":[{"appium:app":"C:\\Program Files (x86)\\E-Ceph\\e-ceph.exe","platformName":"Windows","appium:deviceName":"WindowsPC"}]}} [W3C] Calling AppiumDriver.createSession() with args: [{"app":"C:\\Program Files (x86)\\E-Ceph\\e-ceph.exe","platformName":"Windows","deviceName":"WindowsPC"},null,{"firstMatch":[{"appium:app":"C:\\Program Files (x86)\\E-Ceph\\e-ceph.exe","platformName":"Windows","appium:deviceName":"WindowsPC"}]}] [BaseDriver] Event 'newSessionRequested' logged at 1568948065140 (10:54:25 GMT+0800 (中國標準時間)) [Appium] Creating new WindowsDriver (v1.5.1) session [Appium] Capabilities: [Appium] platformName: Windows [Appium] app: C:\Program Files (x86)\E-Ceph\e-ceph.exe [Appium] deviceName: WindowsPC [BaseDriver] Creating session with MJSONWP desired capabilities: {"app":"C:\\Program Files (...
[BaseDriver] The following capabilities were provided, but are not recognized by appium: app. [BaseDriver] Session created with session id: d9ea408b-d92a-4993-afab-b8a387307e39 [WinAppDriver] You must use WinAppDriver version 1.1 [WinAppDriver] Verifying WinAppDriver version 1.1 is installed via comparing the checksum. [WinAppDriver] WinAppDriver changed state to 'starting' [WinAppDriver] Killing any old WinAppDrivers on same port, running: FOR /F "usebackq tokens=5" %a in (`netstat -nao ^| findstr /R /C:"4724 "`) do (FOR /F "usebackq" %b in (`TASKLIST /FI "PID eq %a" ^| findstr /I winappdriver.exe`) do (IF NOT %b=="" TASKKILL /F /PID %a)) [WinAppDriver] No old WinAppDrivers seemed to exist [WinAppDriver] Spawning winappdriver with: 4724/wd/hub [WinAppDriver] [STDOUT] Windows Application Driver listening for requests at: http://127.0.0.1:4724/wd/hub
[JSONWP Proxy] Proxying [GET /status] to [GET http://127.0.0.1:4724/wd/hub/status] with no body
[WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] Address 'http://127.0.0.1:4724/wd/hub' is already in use [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] Failed to initialize: 0x80004005 [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] ========================================== [WinAppDriver] [STDOUT] GET /wd/hub/status HTTP/1.1 [WinAppDriver] [STDOUT] Accept: application/json, */* [WinAppDriver] [STDOUT] Connection: close [WinAppDriver] [STDOUT] Content-Type: application/json; charset=utf-8 [WinAppDriver] [STDOUT] Host: 127.0.0.1:4724 [WinAppDriver] [STDOUT] User-Agent: appium [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] HTTP/1.1 200 OK [WinAppDriver] [STDOUT] Content-Length: 147 [WinAppDriver] [STDOUT] Content-Type: application/json [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] {"build":{"revision":"18001","time":"Tue Sep 18 18:35:38 2018","version":"1.1.1809"},"os":{"arch":"amd64","name":"windows","version":"10.0.18362"}} [JSONWP Proxy] Got response with status 200: "{\"build\":{\"revision\":\"18001\",\"time\":\"Tue Sep 18 18:35:38 2018\",\"version\":\"1.1.1809\"},\"os\":{\"arch\":\"amd64\",\"name\":\"windows\",\"version\":\"10.0.18362\"}}" [WinAppDriver] Status call returned 200. we're online and ready to run tests [WinAppDriver] WinAppDriver changed state to 'online' [JSONWP Proxy] Matched '/session' to command name 'createSession' [JSONWP Proxy] Proxying [POST /session] to [POST http://127.0.0.1:4724/wd/hub/session] with body: {"desiredCapabilities":{"app":"C:\\Program Files (x86)\\E-Ceph\\e-ceph.exe","platformName":"Windows","deviceName":"WindowsPC"}} [WinAppDriver] WinAppDriver exited unexpectedly with code 2147500037, signal null [WinAppDriver] WinAppDriver changed state to 'stopped' [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] ========================================== [WinAppDriver] [STDOUT] POST /wd/hub/session HTTP/1.1 [WinAppDriver] [STDOUT] Accept: application/json, */* [WinAppDriver] [STDOUT] Connection: close [WinAppDriver] [STDOUT] Content-Length: 127 [WinAppDriver] [STDOUT] Content-Type: application/json; charset=utf-8 [WinAppDriver] [STDOUT] Host: 127.0.0.1:4724 [WinAppDriver] [STDOUT] User-Agent: appium [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] HTTP/1.1 500 Internal Error [WinAppDriver] [STDOUT] Content-Length: 178 [WinAppDriver] [STDOUT] Content-Type: application/json [WinAppDriver] [STDOUT] [WinAppDriver] [STDOUT] {"status":13,"value":{"error":"unknown error","message":"Failed to locate opened application window with appId: C:\\Program Files (x86)\\E-Ceph\\e-ceph.exe, and processId: 480"}} [JSONWP Proxy] Got an unexpected response: {"status":13,"value":{"error":"unknown error","message":"Failed to locate opened application window with appId: C:\\Program Files (x86)\\E-Ceph\\e-ceph.exe, and processId: 480"}} [W3C] Matched W3C error code 'unknown error' to UnknownError [WinAppDriver] Deleting WinAppDriver session [BaseDriver] Event 'newSessionStarted' logged at 1568948072616 (10:54:32 GMT+0800 (中國標準時間)) [W3C] Encountered internal error running command: UnknownError: An unknown server-side error occurred while processing the command. Original error: Failed to locate opened application window with appId: C:\Program Files (x86)\E-Ceph\e-ceph.exe, and processId: 480 [W3C] at errorFromW3CJsonCode (C:\Users\edz\AppData\Local\appium-desktop\app-1.10.0\resources\app\node_modules\appium-base-driver\lib\protocol\errors.js:802:25) [W3C] at ProxyRequestError.getActualError (C:\Users\edz\AppData\Local\appium-desktop\app-1.10.0\resources\app\node_modules\appium-base-driver\lib\protocol\errors.js:685:14) [W3C] at JWProxy.command (C:\Users\edz\AppData\Local\appium-desktop\app-1.10.0\resources\app\node_modules\appium-base-driver\lib\jsonwp-proxy\proxy.js:234:19) [HTTP] <-- POST /wd/hub/session 500 7478 ms - 1011 [HTTP] 
相關文章
相關標籤/搜索