appium实现 windows app UI自动化

1:环境和要求

    1.1  windows PC 或 windows10 或更高版本

    1.2  开启电脑的开发者模式

    1.3  appium安装的时候会帮你默认安装winappdriver,但可能版本不匹配,所以你需要重新下载winappdriver,

    1.4 除了winappdriver,你还要下载windows sdk 

2:启动会话参数

    2.1   对于uwp应用(对于uwp应用可以自行百度),官网称之为通用windows平台应用程序,对于这种uwp应用,启动参数如图所示:

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] 
 
 

 


你可能感兴趣的:(appium实现 windows app UI自动化)