测试人社区

【求助】appium grid课程中,在PyCharm中执行udid命令时,显示不识别的问题

在app自动化测试平台实战课程中,有个地方需要指定udid来运行脚本,我在运行这条命令时会报错:(venv) D:\CMB>udid=‘127.0.0.1:7555’ pytest test_test001.py
‘udid’ is not recognized as an internal or external command,
operable program or batch file.

还有后面run.sh的shell脚本,我这边运行会报找不到路劲:(venv) D:\CMB\testCase>/bin/sh D:/CMB/testCase/run.sh
The system cannot find the path specified.


这两个地方没太看明白,看老师是直接就可以运行的,是因为Windows本和Mac本的区别吗?还是我这边有什么地方没有设置?Windows的话需要怎么操作呢?求助老师解答,谢谢

win 用下set udid=‘127.0.0.1:7555’
然后再执行pytest test_test001.py 试试

先set udid=‘127.0.0.1:7555’
然后再执行pytest test_test001.py ,
没有报错,但是脚本也没有运行,是还差了哪一步嘛?:
image

疑问2.你的devicesname的value我有些疑问,是不是127.0.0.1:7555

appium日志截下图,看下

因为是准备学习appium同时操作多台设备的课程,所有操作都是按照测开12期课程【APP自动化测试平台实战】来的,devicesname的value是粘贴复制来的,应该不会有错吧。。


如果直接写caps[“udid”] = “127.0.0.1:7555”,可以直接运行的。按照刚才先set udid=‘127.0.0.1:7555’
然后再pytest test_test001.py 的方法执行,appium没有日志:

看一下有没有报错信息, 代码里打印一下udid的值 ,看是不是传进去了。
挂一台试试。

没有报错信息,运行完是这样的提示:
(venv) D:\CMB\testCase>set udid=‘127.0.0.1:7555’

(venv) D:\CMB\testCase>pytest test_test001.py
============================ test session starts =============================
platform win32 – Python 3.8.5, pytest-6.1.1, py-1.9.0, pluggy-0.13.1
rootdir: D:\CMB\testCase
plugins: allure-pytest-2.8.18, repeat-0.8.0, rerunfailures-9.1.1
collected 1 item
appium也没有任何运行迹象, udid的值应该在哪里打印呀?不好意思基础比较差,麻烦老师了

在设置的地方用print打印输出就可以
或者看一下appium server里 的desirecaps 对象里的udid设置的正确么。

先看一下一台设备运行有没有问题。

image
是这样打印吗?是显示没有启动成功,但是我直接adb devices 是连接着的呀?
appium server里 的desirecaps 对象里的udid设置怎么看呀?

看appium server端的日志, 你把server的日志和配置的node文件都贴上来看看

appium一直没有运行,但是把初始化driver哪里的caps[“udid”] = os.getenv(“udid”, None)改写成caps[“udid”] = “127.0.0.1:7555”,可以直接在脚本里点击Run运行,现在的appium截图:


node截图:
image
{
“capabilities”:
[
{
“browserName”: “ANDROID”,
“deviceName”: “127.0.0.1:7555”,
“version”:“6.0.1”,
“maxInstances”: 1,
“platform”:“ANDROID”
}
],
“configuration”:
{
“cleanUpCycle”:2000,
“timeout”:30000,
“proxy”: “org.openqa.grid.selenium.proxy.DefaultRemoteProxy”,
“url”:“http://localhost:4723/wd/hub”,
“host”: “localhost”,
“port”: 4723,
“maxSession”: 1,
“register”: true,
“registerCycle”: 5000,
“hubPort”: 4444,
“hubHost”: “172.254.222.172”,
“hubProtocol”: “http”
}
}

1、appium server日志全部贴过来
2、查看一下node版本

现在的问题是一台能执行,两台执行不了么?

如果把初始化driver写成caps[“udid”] = os.getenv(“udid”, None),一台都执行不了,刚才重启了下appium,又执行了下set udid=‘127.0.0.1:7555’然后再执行pytest test_test001.py有报错了
appium报错日志:

[debug] [HTTP] Request idempotency key: 4ec16ed9-40e9-461c-b5d9-0c2fd14ba5e7
[HTTP] --> POST /wd/hub/session
[HTTP] {"desiredCapabilities":{"appActivity":"cmb.pb.app.mainframe.container.PBMainActivity","appPackage":"cmb.pb","server:CONFIG_UUID":"329ffb1b-eee6-49a7-846a-4111a0067fc0","chromedriverChromeMappingFile":"D:/best/page/mapping.json","noReset":true,"unicodeKeyboard":true,"platformName":"android","udid":"‘127.0.0.1:7555’","chromedriverExecutableDir":"D:/Chrome/drive","deviceName":"CMB","resetKeyboard":true},"capabilities":{"firstMatch":[{"platformName":"android","server:CONFIG_UUID":"329ffb1b-eee6-49a7-846a-4111a0067fc0"}]}}
[debug] [W3C] Calling AppiumDriver.createSession() with args: [{"appActivity":"cmb.pb.app.mainframe.container.PBMainActivity","appPackage":"cmb.pb","server:CONFIG_UUID":"329ffb1b-eee6-49a7-846a-4111a0067fc0","chromedriverChromeMappingFile":"D:/best/page/mapping.json","noReset":true,"unicodeKeyboard":true,"platformName":"android","udid":"‘127.0.0.1:7555’","chromedriverExecutableDir":"D:/Chrome/drive","deviceName":"CMB","resetKeyboard":true},null,{"firstMatch":[{"platformName":"android","server:CONFIG_UUID":"329ffb1b-eee6-49a7-846a-4111a0067fc0"}]}]
[debug] [BaseDriver] Event 'newSessionRequested' logged at 1605682237047 (14:50:37 GMT+0800 (GMT+08:00))
[Appium] The following capabilities were provided in the JSONWP desired capabilities that are missing in W3C capabilities: ["appActivity","appPackage","chromedriverChromeMappingFile","noReset","unicodeKeyboard","udid","chromedriverExecutableDir","deviceName","resetKeyboard"]
[Appium] Trying to fix W3C capabilities by merging them with JSONWP caps
[BaseDriver] The following capabilities are not standard capabilities and should have an extension prefix:
[BaseDriver]   appActivity
[BaseDriver]   appPackage
[BaseDriver]   chromedriverChromeMappingFile
[BaseDriver]   noReset
[BaseDriver]   unicodeKeyboard
[BaseDriver]   udid
[BaseDriver]   chromedriverExecutableDir
[BaseDriver]   deviceName
[BaseDriver]   resetKeyboard
[Appium]
[Appium] ======================================================================
[Appium]   DEPRECATION WARNING:
[Appium]
[Appium]   The 'automationName' capability was not provided in the desired
[Appium]   capabilities for this Android session
[Appium]
[Appium]   Setting 'automationName=UiAutomator2' by default and using the
[Appium]   UiAutomator2 Driver
[Appium]
[Appium]   The next major version of Appium (2.x) will **require** the
[Appium]   'automationName' capability to be set for all sessions on all
[Appium]   platforms
[Appium]
[Appium]   In previous versions (Appium <= 1.13.x), the default was
[Appium]   'automationName=UiAutomator1'
[Appium]
[Appium]   If you wish to use that automation instead of UiAutomator2, please
[Appium]   add 'automationName=UiAutomator1' to your desired capabilities
[Appium]
[Appium]   For more information about drivers, please visit
[Appium]   http://appium.io/docs/en/about-appium/intro/ and explore the
[Appium]   'Drivers' menu
[Appium]
[Appium] ======================================================================
[Appium]
[Appium] Appium v1.18.1 creating new AndroidUiautomator2Driver (v1.57.1) session
[debug] [BaseDriver] W3C capabilities and MJSONWP desired capabilities were provided
[debug] [BaseDriver] Creating session with W3C capabilities: {
[debug] [BaseDriver]   "alwaysMatch": {
[debug] [BaseDriver]     "appium:appActivity": "cmb.pb.app.mainframe.container.PBMainActivity",
[debug] [BaseDriver]     "appium:appPackage": "cmb.pb",
[debug] [BaseDriver]     "appium:chromedriverChromeMappingFile": "D:/best/page/mapping.json",
[debug] [BaseDriver]     "appium:noReset": true,
[debug] [BaseDriver]     "appium:unicodeKeyboard": true,
[debug] [BaseDriver]     "appium:udid": "‘127.0.0.1:7555’",
[debug] [BaseDriver]     "appium:chromedriverExecutableDir": "D:/Chrome/drive",
[debug] [BaseDriver]     "appium:deviceName": "CMB",
[debug] [BaseDriver]     "appium:resetKeyboard": true,
[debug] [BaseDriver]     "platformName": "android",
[debug] [BaseDriver]     "server:CONFIG_UUID": "329ffb1b-eee6-49a7-846a-4111a0067fc0"
[debug] [BaseDriver]   },
[debug] [BaseDriver]   "firstMatch": [
[debug] [BaseDriver]     {}
[debug] [BaseDriver]   ]
[debug] [BaseDriver] }
[BaseDriver] The following capabilities were provided, but are not recognized by Appium:
[BaseDriver]   server:CONFIG_UUID
[BaseDriver] Session created with session id: 9fc3c2fa-806d-407f-ba2b-04b1de4889ad
[UiAutomator2] Starting 'cmb.pb' directly on the device
[ADB] Found 1 'build-tools' folders under 'D:\SDK\Andriod_SDK' (newest first):
[ADB]     D:/SDK/Andriod_SDK/build-tools/27.0.1
[ADB] Using 'adb.exe' from 'D:\SDK\Andriod_SDK\platform-tools\adb.exe'
[debug] [ADB] Running 'D:\SDK\Andriod_SDK\platform-tools\adb.exe -P 5037 start-server'
[AndroidDriver] Retrieving device list
[debug] [ADB] Trying to find a connected android device
[debug] [ADB] Getting connected devices
[debug] [ADB] Connected devices: [{"udid":"127.0.0.1:7555","state":"device"}]
[AndroidDriver] Device ‘127.0.0.1:7555’ was not in the list of connected devices
[debug] [UiAutomator2] Deleting UiAutomator2 session
[debug] [BaseDriver] Event 'newSessionStarted' logged at 1605682237986 (14:50:37 GMT+0800 (GMT+08:00))
[debug] [W3C] Encountered internal error running command: Error: Device ‘127.0.0.1:7555’ was not in the list of connected devices
[debug] [W3C]     at Object.errorAndThrow (C:\Users\admin\AppData\Roaming\npm\node_modules\appium\node_modules\_appium-support@2.49.0@appium-support\lib\logging.js:94:35)
[debug] [W3C]     at Object.getDeviceInfoFromCaps (C:\Users\admin\AppData\Roaming\npm\node_modules\appium\node_modules\_appium-android-driver@4.39.2@appium-android-driver\lib\android-helpers.js:208:16)
[debug] [W3C]     at AndroidUiautomator2Driver.startUiAutomator2Session (C:\Users\admin\AppData\Roaming\npm\node_modules\appium\node_modules\_appium-uiautomator2-driver@1.57.1@appium-uiautomator2-driver\lib\driver.js:312:26)
[debug] [W3C]     at AndroidUiautomator2Driver.createSession (C:\Users\admin\AppData\Roaming\npm\node_modules\appium\node_modules\_appium-uiautomator2-driver@1.57.1@appium-uiautomator2-driver\lib\driver.js:223:7)
[debug] [W3C]     at AppiumDriver.createSession (C:\Users\admin\AppData\Roaming\npm\node_modules\appium\lib\appium.js:358:35)
[debug] [W3C] Destroying socket connection
[HTTP] <-- POST /wd/hub/session 500 1014 ms - 749
[HTTP]
[HTTP] --> GET /wd/hub/status
[HTTP] {}
[debug] [GENERIC] Calling AppiumDriver.getStatus() with args: []
[debug] [GENERIC] Responding to client with driver.getStatus() result: {"build":{"version":"1.18.1"}}
[HTTP] <-- GET /wd/hub/status 200 2 ms - 68

node版本是:v12.18.3

set udid=‘127.0.0.1:7555’ 改成 set udid=127.0.0.1:7555,去掉引号

谢谢老师,可以运行了,还有一个问题,Windows好像不能直接在pycharm里直接运行shell脚本,报错说找不到路径,这个怎么解决呢?

测试文件给个全路径


是这里给全路径吗?好像还是不行呀,我在shell脚本里只执行adb devices也会报这个错

应该是需要在gitbash里执行

我把pycharm里的shell path改成了gitbash的路径,执行run.sh不报错了,但是appium没有运行,重启了appium也不会运行。
不过我在下面执行 udid=127.0.0.1:7555 pytest test_test001.py可以直接成功运行了


感觉快成功了,是不是我的shell脚本哪里写错啦?老师帮我看一下 :flushed:

你调试一下,只执行一下echo看有没有问题