由于工作需要进行 Windows 应用程序的 UI 自动化,今天发现 Appium 还真的支持,但 Appium 只支持 Win10 上的应用。 Appium 使用 WinAppDriver 测试 Windows 应用,在安装 Appium 的时候会自动安装 WinAppDriver。WinAppDriver 官网:https://github.com/Microsoft/WinAppDriver。
和移动端 UI 测试没什么区别了,就是调整一些参数而已。下面的例子是打开了印象笔记,并新建一篇笔记。
# -*- coding:utf-8 -*-
from appium import webdriver
class Windows(object):
def __init__(self, app, host='localhost', port=4723):
self.desired_caps = {}
self.desired_caps['platformName'] = 'Windows'
self.desired_caps['app'] = app
self.desired_caps['deviceName'] = 'WindowsPC'
self.host = host
self.port = port
self.appVersion = None
try:
self.driver = webdriver.Remote('http://{}:{}/wd/hub'.format(self.host, self.port), self.desired_caps)
except Exception as e:
raise AssertionError(e)
if __name__ == '__main__':
import time
evernote = 'C:\\Program Files (x86)\\Evernote\\Evernote\\Evernote.exe'
notepad = Windows(evernote)
time.sleep(3)
notepad.driver.find_element_by_name('新建笔记').click()
类似于 Android 的 Uiautomatorviewer,Windows 使用 inspect.exe 查看应用程序的 UI 元素信息。inspect.exe 可以在 Windows SDK 的目录中找到它,例如: C:\Program Files (x86)\Windows Kits\10\bin\x86。
微软有个 UIAutomation,这个东西可以实现对 Winform、WPF、UWP 等应用的 UI 自动化
如果你要在 Win 上测 UWP 什么的应用,就用微软的 UIAutomation 吧,用法以前写了点https://testerhome.com/topics/6369
我只是想说在 win 平台上,用.Net 和 C# 是最好的(当然暂时不包括.Net Core,因为.Net Core 发展得太晚了)
UWP ID 根据你提供的 ID 在系统中搜索了下,如果发现有,进一步验证猜想,下载一个应用测试 C:\Users\xx\AppData\Local\Packages 开始目录有 64 个
然后下载了微信 目录下变成 65 个,具体是不是需要的 ID 还需要验证
谢谢,我主要还是做移动端的 UI 自动化,有些功能需要 Windows 上软件的配合,看到 Appium 也支持 Windows,就试用了一下。
补充一下公众号收到的一个如何获取 ID 的方法:
APP ID 可以到 APP 文件夹看(命令进入),也可以用 powershell 命令查,也可以直接看程序属性(程序要先调出 explorer.exe 文件夹)
1.6.3 上会自动安装 WinAppDriver 吗。我在 1.6.4 上运行直接抛异常了
[debug] [WinAppDriver] Deleting WinAppDriver session
[MJSONWP] Encountered internal error running command: Error: Could not verify WinAppDriver install; re-run install
擦,老早以前我是用 autoit 来实现 windows 客户端程序的 UI 自动操作。
请更新个人资料中的微信和支付宝的打赏二维码,用于精华帖打赏
我试验成功了,
解决掉了,这种报错:
MSBUILD : error MSB3428: 未能加载 Visual C++ 组件“VCBuild.exe”。要解决此问题,1) 安装 .NET Framework 2.0 SDK;2) 安装 Microsoft Vis ual Studio 2005;或 3)
如果将该组件安装到了其他位置,请将其位置添加到系统路径中。 [D:\nodejs\node-global\node_modules\appium\node_modules\heapdump\build\bi nding.sln]
和这种警告:
> appium-windows-driver@1.0.0 install D:\nodejs\node-global\node_modules\appium\node_modules\appium-windows-driver
> node install-npm.js
info WinAppDriver You must use WinAppDriver version 1.0
info WinAppDriver Verifying WinAppDriver version 1.0 is installed via comparing the checksum.
info WinAppDriver WinAppDriver.exe doesn't exist at the correct version 1.0, setting up
WARNING: You are not running as an administrator so WinAppDriver cannot be installed for you; please reinstall as admin
WinAppDriver was not installed; please check your system and re-run npm install if you need WinAppDriver
> heapdump@0.3.9 install D:\nodejs\node-global\node_modules\appium\node_modules\heapdump
> node-gyp rebuild
D:\nodejs\node-global\node_modules\appium\node_modules\heapdump>if not defined npm_config_node_gyp (node "D:\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "D:\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
在此解决方案中一次生成一个项目。若要启用并行生成,请添加“/m”开关。
方法告诉你吧:
最终的方法,期间参考一些折腾了一些其他的,反复试了几次,应该是这样的步骤:
1 卸载 npm uninstall appium -g
哦 实际 我也开启了 win10 的开发人员模式,此步是不是必要 我暂时不清楚,参考乱七八糟的帖子 折腾了许多,所以并不知道 是否此步必要
2 去 https://developer.microsoft.com/zh-cn/windows/downloads/windows-10-sdk 下载 .iso
一共 760 多 MB 16299.15.170928-1534.rs3_release_WindowsSDK.iso win10 可以直接双击该 iso 便会加载为一个光盘 DVD 驱动器,进去,直接双击 WinSDKSetup.exe 安装即可.默
认路径,默认 features 全选择
3 https://github.com/Microsoft/WinAppDriver/releases 下载 v1.0 的 WindowsApplicationDriver.msi .
安装到默认 C:\Program Files (x86)\Windows Application Driver
路径,然后命令行到该路径,尝试启动下
保证启动正常.
4 管理员权限 powershell 执行 npm install --global --production windows-build-tools
过程很长,需要在线下载一些组件.我全程科学上网.
Windows PowerShell
版权所有 (C) Microsoft Corporation。保留所有权利。
PS C:\WINDOWS\system32> npm install --global --production windows-build-tools
> windows-build-tools@2.2.1 postinstall D:\nodejs\node-global\node_modules\windows-build-tools
> node ./lib/index.js
Downloading BuildTools_Full.exe
Downloading python-2.7.14.amd64.msi
[> ] 0.0% (0 B/s)
Downloaded python-2.7.14.amd64.msi. Saved to C:\Users\cmd\.windows-build-tools\python-2.7.14.amd64.msi.
Starting installation...
Launched installers, now waiting for them to finish.
This will likely take some time - please be patient!
Status from the installers:
---------- Visual Studio Build Tools ----------
Successfully installed Visual Studio Build Tools.
------------------- Python --------------------
Successfully installed Python 2.7
+ windows-build-tools@2.2.1
added 132 packages in 1365.525s
5 管理员权限 powershell 执行 npm i appium -g
然后就正常了 没 WARNING 了.
PS C:\WINDOWS\system32> npm i appium -g
D:\nodejs\node-global\appium -> D:\nodejs\node-global\node_modules\appium\build\lib\main.js
> appium-chromedriver@3.1.4 install D:\nodejs\node-global\node_modules\appium\node_modules\appium-chromedriver
> node install-npm.js
info Chromedriver Install Installing Chromedriver version '2.33' for platform 'win' and architecture '32'
info Chromedriver Install Opening temp file to write chromedriver_win32 to...
info Chromedriver Install Downloading https://chromedriver.storage.googleapis.com/2.33/chromedriver_win32.zip...
info Chromedriver Install Writing binary content to C:\Users\cmd\AppData\Local\Temp\2018317-14572-briz5r.jt6ow\chromedriver_win32.zip...
info Chromedriver Install Extracting C:\Users\cmd\AppData\Local\Temp\2018317-14572-briz5r.jt6ow\chromedriver_win32.zip to C:\Users\cmd\AppData\Local\Temp\2018317-14572-briz5r.jt6ow\chromedriver_win32
info Chromedriver Install Creating D:\nodejs\node-global\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win...
info Chromedriver Install Copying unzipped binary, reading from C:\Users\cmd\AppData\Local\Temp\2018317-14572-briz5r.jt6ow\chromedriver_win32\chromedriver.exe...
info Chromedriver Install Writing to D:\nodejs\node-global\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win\chromedriver.exe...
info Chromedriver Install D:\nodejs\node-global\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win\chromedriver.exe successfully put in place
> appium-selendroid-driver@1.6.6 install D:\nodejs\node-global\node_modules\appium\node_modules\appium-selendroid-driver> node ./bin/install.js
dbug AndroidDriver Getting Java version
info AndroidDriver Java version is: 1.8.0_121
info Selendroid Ensuring D:\nodejs\node-global\node_modules\appium\node_modules\appium-selendroid-driver\selendroid\download exists
info Selendroid Downloading Selendroid standalone server version 0.17.0 from http://repo1.maven.org/maven2/io/selendroid/selendroid-standalone/0.17.0/selendroid-standalone-0.17.0-with-dependencies.jar --> D:\nodejs\node-global\node_modules\appium\node_modules\appium-selendroid-driver\selendroid\download\selendroid-server-7cf7163ac47f1c46eff95b62f78b58c1dabdec534acc6632da3784739f6e9d82.jar
info Selendroid Writing binary content to D:\nodejs\node-global\node_modules\appium\node_modules\appium-selendroid-driver\selendroid\download\selendroid-server.jar.tmp
info Selendroid Selendroid standalone server downloaded
info Selendroid Determining AndroidManifest location
info Selendroid Determining server apk location
info Selendroid Extracting manifest and apk to D:\nodejs\node-global\node_modules\appium\node_modules\appium-selendroid-driver\selendroid\download
info Selendroid Copying manifest and apk to D:\nodejs\node-global\node_modules\appium\node_modules\appium-selendroid-driver\selendroid
info Selendroid Cleaning up temp files
info Selendroid Fixing AndroidManifest icon bug
> appium-uiautomator2-driver@0.11.0 install D:\nodejs\node-global\node_modules\appium\node_modules\appium-uiautomator2-driver
> node ./bin/install.js
dbug AndroidDriver Getting Java version
info AndroidDriver Java version is: 1.8.0_121
info UiAutomator2 downloading UiAutomator2 Server APK v0.3.0 : https://github.com/appium/appium-uiautomator2-server/releases/download/v0.3.0/appium-uiautomator2-server-v0.3.0.apk
info UiAutomator2 downloading UiAutomator2 Server test APK v0.3.0 : https://github.com/appium/appium-uiautomator2-server/releases/download/v0.3.0/appium-uiautomator2-server-debug-androidTest.apk
info UiAutomator2 UiAutomator2 Server APKs downloaded
> appium-windows-driver@1.0.0 install D:\nodejs\node-global\node_modules\appium\node_modules\appium-windows-driver
> node install-npm.js
info WinAppDriver You must use WinAppDriver version 1.0
info WinAppDriver Verifying WinAppDriver version 1.0 is installed via comparing the checksum.
info WinAppDriver WinAppDriver.exe version 1.0 already exists with correct checksum, not re-downloading
> heapdump@0.3.9 install D:\nodejs\node-global\node_modules\appium\node_modules\heapdump
> node-gyp rebuild
D:\nodejs\node-global\node_modules\appium\node_modules\heapdump>if not defined npm_config_node_gyp (node "D:\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "D:\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
在此解决方案中一次生成一个项目。若要启用并行生成,请添加“/m”开关。
heapdump.cc
Creating library D:\nodejs\node-global\node_modules\appium\node_modules\heapdump\build\Release\addon.lib and object D:\nodejs\node-global\node_modules\appium\node_modules\heapdump\build\Release\addon.exp
Generating code
Finished generating code
addon.vcxproj -> D:\nodejs\node-global\node_modules\appium\node_modules\heapdump\build\Release\\addon.node
addon.vcxproj -> D:\nodejs\node-global\node_modules\appium\node_modules\heapdump\build\Release\addon.pdb (Full PDB)
> pre-commit@1.2.2 install D:\nodejs\node-global\node_modules\appium\node_modules\pre-commit
> node install.js
> wd@1.5.0 install D:\nodejs\node-global\node_modules\appium\node_modules\wd
> node scripts/build-browser-scripts
> spawn-sync@1.0.15 postinstall D:\nodejs\node-global\node_modules\appium\node_modules\spawn-sync
> node postinstall
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.3 (node_modules\appium\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
+ appium@1.7.2
added 1375 packages in 682.967s
求教:用这种方法,能对其他主机上的程序进行测试吗?我要用一个测试工具,测试多台主机上协同进行的业务
windows 的 app id 好像可以这样获得,打开 cmd,输入 powershell,再输入 Get-StartApps,但这些 APPID 有好几种格式,不知道是怎么个回事
Could not verify WinAppDriver install; re-run install 未能解决,大家有解决方案吗?
手动下载 winappdriver releases 1.1 版本就可以解决啦
下载链接:https://github.com/microsoft/WinAppDriver/releases/tag/v1.1
代码和 appium 设置的都是 4723 的端口,为什么 appium 日志中显示的 4724,并且还报图上这个错误。
求解,公司的客户端后面加 test 表示测试环境,staging 表示预发环境,我在 host 里面写了这个就说找不到系统文件,请问这种情况要怎么处理
def setUpClass(self):
# set up appium
desired_caps = {}
desired_caps["app"] = "D:\\soft\\TeamViewer\\TeamViewer.exe"
desired_caps["platformName"] = "Windows"
desired_caps["deviceName"] = "WindowsPC"
self.driver = webdriver.Remote(
command_executor='http://127.0.0.1:4723/wd/hub',
desired_capabilities=desired_caps)
print("11111")
time.sleep(8)
print("22222")
[W3C] Calling AppiumDriver.createSession() with args: [{"app":"D:\\soft\\TeamViewer\\TeamViewer.exe","platformName":"Windows","deviceName":"WindowsPC"},null,{"firstMatch":[{"appium:app":"D:\\soft\\TeamViewer\\TeamViewer.exe","platformName":"Windows","appium:deviceName":"WindowsPC"}]}]
[BaseDriver] Event 'newSessionRequested' logged at 1629845760468 (06:56:00 GMT+0800 (中国标准时间))
[Appium] Appium v1.21.0 creating new WindowsDriver (v1.18.1) session
[Appium] Applying relaxed security to 'WindowsDriver' as per server command line argument. All insecure features will be enabled unless explicitly disabled by --deny-insecure
[BaseDriver] W3C capabilities and MJSONWP desired capabilities were provided
[BaseDriver] Creating session with W3C capabilities: {
[BaseDriver] "alwaysMatch": {
[BaseDriver] "platformName": "Windows",
[BaseDriver] "appium:app": "D:\\soft\\TeamViewer\\TeamViewer.exe",
[BaseDriver] "appium:deviceName": "WindowsPC"
[BaseDriver] },
[BaseDriver] "firstMatch": [
[BaseDriver] {}
[BaseDriver] ]
[BaseDriver] }
[BaseDriver] Session created with session id: f6279929-8445-4a07-9940-e07a5d1492f8
[WinAppDriver] WinAppDriver exists, but the checksum did not match. Was it replaced manually?
[WinAppDriver] Spawning 'C:\Program Files (x86)\Windows Application Driver\WinAppDriver.exe' with args: ["4725/wd/hub"]
[WD Proxy] Matched '/status' to command name 'getStatus'
[WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:4725/wd/hub/status] with no body
[WinAppDriver] 楗摮睯灁汰捩瑡潩牄癩牥䈠瑥楬瑳湥湩潦敲畱獥獴愠㩴栠瑴㩰⼯㈱⸷⸰⸰㨱㜴㔲眯⽤畨ൢ
[WinAppDriver] 倊敲獳䔠呎剅琠硥瑩മ
[WinAppDriver] ഊഊ㴊㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽ഽ䜊呅⼠摷栯扵猯慴畴呈偔ㄯㄮ䄊捣灥㩴愠灰楬慣楴湯樯潳Ɱ⨠⨯䌊湯敮瑣潩㩮欠敥⵰污癩潃瑮湥祔数›灡汰捩瑡潩⽮獪湯※档牡敳㵴瑵ⵦസ潈瑳›㈱⸷⸰⸰㨱㜴㔲唊敳杁湥㩴愠浤⽣摷ㄯㄮ⸳‰灡楰浵椭獮数瑣牯ㄯ㈮⸱രഊ
[WinAppDriver] 䠊呔⽐⸱‱〲‰䭏䌊湯整瑮䰭湥瑧㩨ㄠ㠰䌊湯整瑮吭灹㩥愠灰楬慣楴湯樯潳൮笊戢極摬㨢≻敲楶楳湯㨢〢Ⱒ琢浩≥∺ⴭ⼭ⴭⰢ瘢牥楳湯㨢〢索∬獯㨢≻牡档㨢砢㘸Ⱒ渢浡≥∺楷摮睯≳∬敶獲潩≮∺索ൽ
[WD Proxy] Got response with status 200: {"build":{"revision":"0","time":"--/--/--","version":"0"},"os":{"arch":"x86","name":"windows","version":""}}
[WinAppDriver] Starting WinAppDriver session. Will timeout in '20000' ms.
[WD Proxy] Matched '/session' to command name 'createSession'
[WD Proxy] Proxying [POST /session] to [POST http://127.0.0.1:4725/wd/hub/session] with body: {"desiredCapabilities":{"platformName":"Windows","app":"D:\\soft\\TeamViewer\\TeamViewer.exe","deviceName":"WindowsPC"}}
[WinAppDriver] ഊഊ㴊㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽ഽ倊协⁔眯⽤畨⽢敳獳潩呈偔ㄯㄮ䄊捣灥㩴愠灰楬慣楴湯樯潳Ɱ⨠⨯䌊湯敮瑣潩㩮欠敥⵰污癩潃瑮湥敌杮桴›㈱ര潃瑮湥祔数›灡汰捩瑡潩⽮獪湯※档牡敳㵴瑵ⵦസ潈瑳›㈱⸷⸰⸰㨱㜴㔲唊敳杁湥㩴愠浤⽣摷ㄯㄮ⸳‰灡楰浵椭獮数瑣牯ㄯ㈮⸱രഊ
[WinAppDriver] 匊獥楳湯慍慮敧牃慥楴杮猠獥楳湯映牯䐠尺潳瑦呜慥噭敩敷屲敔浡楖睥牥攮數敓獳潩䵮湡条牥ⴠ圠湩灁䑰楲敶畳捣敥敤潬摡湩楍慴牂歯牥呈偔ㄯㄮ㔠〰䤠瑮牥慮牅潲൲潃瑮湥敌杮桴›〱റ潃瑮湥祔数›灡汰捩瑡潩⽮獪湯ഊ≻瑳瑡獵㨢㌳∬慶畬≥笺攢牲牯㨢猢獥楳湯渠瑯挠敲瑡摥Ⱒ洢獥慳敧㨢䄢渠睥猠獥楳湯挠畯摬渠瑯戠牣慥整索ൽ
[WD Proxy] Got response with status 500: {"status":33,"value":{"error":"session not created","message":"A new session could not be created."}}
[W3C] Matched W3C error code 'session not created' to SessionNotCreatedError
[WinAppDriver] Could not start WinAppDriver session error = 'A new session could not be created. Details: A new session could not be created.', attempt = '1' from 'undefined'
[WD Proxy] Matched '/session' to command name 'createSession'
[WD Proxy] Proxying [POST /session] to [POST http://127.0.0.1:4725/wd/hub/session] with body: {"desiredCapabilities":{"platformName":"Windows","app":"D:\\soft\\TeamViewer\\TeamViewer.exe","deviceName":"WindowsPC"}}
[WinAppDriver] ഊഊ㴊㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽ഽ倊协⁔眯⽤畨⽢敳獳潩呈偔ㄯㄮ䄊捣灥㩴愠灰楬慣楴湯樯潳Ɱ⨠⨯䌊湯敮瑣潩㩮欠敥⵰污癩潃瑮湥敌杮桴›㈱ര潃瑮湥祔数›灡汰捩瑡潩⽮獪湯※档牡敳㵴瑵ⵦസ潈瑳›㈱⸷⸰⸰㨱㜴㔲唊敳杁湥㩴愠浤⽣摷ㄯㄮ⸳‰灡楰浵椭獮数瑣牯ㄯ㈮⸱ര笊搢獥物摥慃慰楢楬楴獥㨢≻汰瑡潦浲慎敭㨢圢湩潤獷Ⱒ愢灰㨢䐢尺獜景屴呜慥噭敩敷屲呜慥噭敩敷硥≥∬敤楶散慎敭㨢圢湩潤獷䍐索ൽ
[WinAppDriver] 匊獥楳湯慍慮敧牃慥楴杮猠獥楳湯映牯䐠尺潳瑦呜慥噭敩敷屲敔浡楖睥牥攮數敓獳潩䵮湡条牥ⴠ圠湩灁䑰楲敶畳捣敥敤潬摡湩楍慴牂歯牥呈偔ㄯㄮ㔠〰䤠瑮牥慮牅潲൲潃瑮湥敌杮桴›〱റ潃瑮湥祔数›灡汰捩瑡潩⽮獪湯ഊ≻瑳瑡獵㨢㌳∬慶畬≥笺攢牲牯㨢猢獥楳湯渠瑯挠敲瑡摥Ⱒ洢獥慳敧㨢䄢渠睥猠獥楳湯挠畯摬渠瑯戠牣慥整索ൽ
[WD Proxy] Got response with status 500: {"status":33,"value":{"error":"session not created","message":"A new session could not be created."}}
[W3C] Matched W3C error code 'session not created' to SessionNotCreatedError
[WinAppDriver] Could not start WinAppDriver session error = 'A new session could not be created. Details: A new session could not be created.', attempt = '2' from 'undefined'
[WinAppDriver] timeoutError was Condition unmet after 27613 ms. Timing out.
[WinAppDriver] Deleting WinAppDriver session
[WinAppDriver] WinAppDriver exited with code null, signal SIGTERM
[BaseDriver] Event 'newSessionStarted' logged at 1629845789032 (06:56:29 GMT+0800 (中国标准时间))
[W3C] Encountered internal error running command: SessionNotCreatedError: A new session could not be created. Details: A new session could not be created.
[W3C] at errorFromW3CJsonCode (C:\Program Files\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\protocol\errors.js:780:25)
[W3C] at ProxyRequestError.getActualError (C:\Program Files\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\protocol\errors.js:663:14)
[W3C] at WADProxy.command (C:\Program Files\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\jsonwp-proxy\proxy.js:272:19)
[W3C] at processTicksAndRejections (internal/process/task_queues.js:85:5)
[HTTP] <-- POST /wd/hub/session 500 28565 ms - 824
[HTTP]