Appium Macbook 环境使用 Appium Inspector 连接真机,报错"deviceName can't be blank"

杉菜 · 2022年09月28日 · 最后由 lzy 回复于 2022年09月28日 · 6710 次阅读

在 mac 环境,连接 android 真机,使用 Appium Inspector 启动测试,报错" SessionNotCreatedError: A new session could not be created. Details: The desiredCapabilities object was not valid for the following reason(s): deviceName can't be blank"
1、这个问题很奇怪,因为在参数中我已经传了 deviceName,adb devices 也显示设备连接正常
相关的软件版本为 App Version:2022.3.2,Electron 为 13.6.3,Node.js 为 14.16.0

2.下面是完整的 appium 的 log

[HTTP] --> POST /wd/hub/session {"capabilities":{"alwaysMatch":{"appium:appPackage":"com.wj.wallet","appium:appActivity":"com.wj.wallet.login.BlankActivity","platformName":"Android","appium:deviceName":"583be6e1","appium:ensureWebviewsHavePages":true,"appium:nativeWebScreenshot":true,"appium:newCommandTimeout":3600,"appium:connectHardwareKeyboard":true},"firstMatch":[{}]},"desiredCapabilities":{"appium:appPackage":"com.wj.wallet","appium:appActivity":"com.wj.wallet.login.BlankActivity","platformName":"Android","appium:deviceName":"583be6e1","appium:ensureWebviewsHavePages":true,"appium:nativeWebScreenshot":true,"appium:newCommandTimeout":3600,"appium:connectHardwareKeyboard":true}}
[debug] [MJSONWP] Calling AppiumDriver.createSession() with args: [{"appium:appPackage":"com.wj.wallet","appium:appActivity":"com.wj.wallet.login.BlankActivity","platformName":"Android","appium:deviceName":"583be6e1","appium:ensureWebviewsHavePages":true,"appium:nativeWebScreenshot":true,"appium:newCommandTimeout":3600,"appium:connectHardwareKeyboard":true},null,{"alwaysMatch":{"appium:appPackage":"com.wj.wallet","appium:appActivity":"com.wj.wallet.login.BlankActivity","platformName":"Android","appium:deviceName":"583be6e1","appium:ensureWebviewsHavePages":true,"appium:nativeWebScreenshot":true,"appium:newCommandTimeout":3600,"appium:connectHardwareKeyboard":true},"firstMatch":[{}]}]
[debug] [BaseDriver] Event 'newSessionRequested' logged at 1664347551366 (14:45:51 GMT+0800 (中国标准时间))
[Appium] Creating new AndroidDriver (v1.28.1) session
[Appium] Capabilities:
[Appium]   appium:appPackage: 'com.wj.wallet'
[Appium]   appium:appActivity: 'com.wj.wallet.login.BlankActivity'
[Appium]   platformName: 'Android'
[Appium]   appium:deviceName: '583be6e1'
[Appium]   appium:ensureWebviewsHavePages: true
[Appium]   appium:nativeWebScreenshot: true
[Appium]   appium:newCommandTimeout: 3600
[Appium]   appium:connectHardwareKeyboard: true
[BaseDriver] SessionNotCreatedError: A new session could not be created. Details: The desiredCapabilities object was not valid for the following reason(s):  deviceName can't be blank,
    at AndroidDriver.validateDesiredCaps (../../../lib/basedriver/driver.js:182:25)
    at AndroidDriver.validateDesiredCaps (../../lib/driver.js:31:20)
    at AndroidDriver.callee$0$0$ (../../../../lib/basedriver/commands/session.js:23:8)
    at tryCatch (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
    at GeneratorFunctionPrototype.prototype.<computed> [as next] (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
    at invoke (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
    at enqueueResult (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:185:17)
    at new Promise (<anonymous>)
    at new F (/opt/homebrew/lib/node_modules/appium/node_modules/core-js/library/modules/$.export.js:30:36)
    at AsyncIterator.enqueue (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:184:12)
    at AsyncIterator.prototype.<computed> [as next] (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
    at Object.runtime.async (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:209:12)
    at AndroidDriver.callee$0$0 [as createSession] (../../../../lib/basedriver/commands/session.js:15:11)
    at AndroidDriver.createSession$ (../../lib/driver.js:31:20)
    at tryCatch (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
    at GeneratorFunctionPrototype.prototype.<computed> [as next] (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
    at invoke (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
    at enqueueResult (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:185:17)
    at new Promise (<anonymous>)
    at new F (/opt/homebrew/lib/node_modules/appium/node_modules/core-js/library/modules/$.export.js:30:36)
    at AsyncIterator.enqueue (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:184:12)
    at AsyncIterator.prototype.<computed> [as next] (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
    at Object.runtime.async (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:209:12)
    at AndroidDriver.createSession (../../lib/driver.js:163:27)
    at AppiumDriver.createSession$ (../../lib/appium.js:207:41)
    at tryCatch (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
    at GeneratorFunctionPrototype.prototype.<computed> [as next] (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
    at GeneratorFunctionPrototype.invoke (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
 SessionNotCreatedError: A new session could not be created. Details: The desiredCapabilities object was not valid for the following reason(s):  deviceName can't be blank,
    at AndroidDriver.validateDesiredCaps (../../../lib/basedriver/driver.js:182:25)
    at AndroidDriver.validateDesiredCaps (../../lib/driver.js:31:20)
    at AndroidDriver.callee$0$0$ (../../../../lib/basedriver/commands/session.js:23:8)
    at tryCatch (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
    at GeneratorFunctionPrototype.prototype.<computed> [as next] (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
    at invoke (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
    at enqueueResult (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:185:17)
    at new Promise (<anonymous>)
    at new F (/opt/homebrew/lib/node_modules/appium/node_modules/core-js/library/modules/$.export.js:30:36)
    at AsyncIterator.enqueue (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:184:12)
    at AsyncIterator.prototype.<computed> [as next] (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
    at Object.runtime.async (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:209:12)
    at AndroidDriver.callee$0$0 [as createSession] (../../../../lib/basedriver/commands/session.js:15:11)
    at AndroidDriver.createSession$ (../../lib/driver.js:31:20)
    at tryCatch (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
    at GeneratorFunctionPrototype.prototype.<computed> [as next] (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
    at invoke (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
    at enqueueResult (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:185:17)
    at new Promise (<anonymous>)
    at new F (/opt/homebrew/lib/node_modules/appium/node_modules/core-js/library/modules/$.export.js:30:36)
    at AsyncIterator.enqueue (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:184:12)
    at AsyncIterator.prototype.<computed> [as next] (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
    at Object.runtime.async (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:209:12)
    at AndroidDriver.createSession (../../lib/driver.js:163:27)
    at AppiumDriver.createSession$ (../../lib/appium.js:207:41)
    at tryCatch (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
    at GeneratorFunctionPrototype.prototype.<computed> [as next] (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
    at GeneratorFunctionPrototype.invoke (/opt/homebrew/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  jsonwpCode: 33
}
[debug] [AndroidDriver] Shutting down Android driver
[debug] [AndroidDriver] Called deleteSession but bootstrap wasn't active
[HTTP] <-- POST /wd/hub/session 500 28 ms - 199

共收到 3 条回复 时间 点赞

以前 deviceName 这个配置项,名字就叫 deviceName 。刚查了下官网 https://appium.io/docs/en/writing-running-appium/caps/index.html ,名字好像没变。

楼主是在哪个资料看到名字叫 appium:deviceName 这个的?

楼主,启动参数里面,把 Appium:去掉,启动参数不需要加这个 appium:的前缀的,所以才失败的,去掉就好了

appium2.0 开始使用 w3c 标准,用前缀区分不同服务的设置。
deviceName 不在 selenium caps 内,是 appium 独有,前缀 appium:是勾选了
Automatically add necessary Appium vendor prefixes on start 后 appium inspector 自动加的,是正确的。
类型不应该选择 JSON object,选择 Text 试试,JSON object 多数情况下是给其他服务用的,如 bstack:options

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册