在 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


↙↙↙阅读原文可查看相关链接,并与作者交流