Appium 求助!!!遇到问题 A new session could not be created.

冰镇 · 2016年07月05日 · 最后由 凝视 回复于 2020年05月25日 · 3431 次阅读

HI 求助啊,我目前遇到一个问题 A new session could not be created. 无法联调测试,当我关闭或者打开模拟器都会出现这个错误,单独执行脚本就会报错。
adb 执行确实可以看到的手机

List of devices attached
192.168.56.101:5555 device

appium 也监测到了我手机,但是为什么联调不成功呢,求大神解救啊。

info: Found device 192.168.56.101:5555
info: [debug] Setting device id to 192.168.56.101:5555
info: [debug] Waiting for device to be ready and to respond to shell commands (timeout = 5)
info: [debug] executing cmd: "D:\Android\sdk\platform-tools\adb.exe" -s 192.168.56.101:5555 wait-for-device
info: [debug] executing cmd: "D:\Android\sdk\platform-tools\adb.exe" -s 192.168.56.101:5555 shell "echo 'ready'"
info: [debug] Starting logcat capture
error: Logcat capture failed: spawn "D:\Android\sdk\platform-tools\adb.exe" ENOENT
info: [debug] Stopping logcat capture
以下是过程 log,写了一个网上看到很简单的 python 测试计算器的脚本,但是出现了一个这么问题,查了好几天没有很好的解决办法。大家有人知道么?

info: --> POST /wd/hub/session {"desiredCapabilities":{"deviceName":"Android Emulator","app":"Calculator.apk","platformVersion":"4.4","appPackage":"com.android.calculator2","platformName":"Android","appActivity":".Calculator"}}
info: Client User-Agent string: Python-urllib/2.7
info: [debug] Error: Requested a new session but one was in progress
at [object Object].Appium.start (D:\Appium\node_modules\appium\lib\appium.js:139:15)
at exports.createSession (D:\Appium\node_modules\appium\lib\server\controller.js:188:16)
at Layer.handle as handle_request
at next (D:\Appium\node_modules\appium\node_modules\express\lib\router\route.js:110:13)
at Route.dispatch (D:\Appium\node_modules\appium\node_modules\express\lib\router\route.js:91:3)
at Layer.handle as handle_request
at D:\Appium\node_modules\appium\node_modules\express\lib\router\index.js:267:22
at Function.proto.process_params (D:\Appium\node_modules\appium\node_modules\express\lib\router\index.js:321:12)
at next (D:\Appium\node_modules\appium\node_modules\express\lib\router\index.js:261:10)
at next (D:\Appium\node_modules\appium\node_modules\express\lib\router\route.js💯14)
at next (D:\Appium\node_modules\appium\node_modules\express\lib\router\route.js:104:14)
at next (D:\Appium\node_modules\appium\node_modules\express\lib\router\route.js:104:14)
at next (D:\Appium\node_modules\appium\node_modules\express\lib\router\route.js:104:14)
at next (D:\Appium\node_modules\appium\node_modules\express\lib\router\route.js:104:14)
at next (D:\Appium\node_modules\appium\node_modules\express\lib\router\route.js:104:14)
at next (D:\Appium\node_modules\appium\node_modules\express\lib\router\route.js:104:14)
at next (D:\Appium\node_modules\appium\node_modules\express\lib\router\route.js:104:14)
at next (D:\Appium\node_modules\appium\node_modules\express\lib\router\route.js:104:14)
at next (D:\Appium\node_modules\appium\node_modules\express\lib\router\route.js:104:14)
at next (D:\Appium\node_modules\appium\node_modules\express\lib\router\route.js:104:14)
at D:\Appium\node_modules\appium\lib\server\controller.js:39:7
at Layer.handle as handle_request
at next (D:\Appium\node_modules\appium\node_modules\express\lib\router\route.js:110:13)
at next (D:\Appium\node_modules\appium\node_modules\express\lib\router\route.js:104:14)
at next (D:\Appium\node_modules\appium\node_modules\express\lib\router\route.js:104:14)
at next (D:\Appium\node_modules\appium\node_modules\express\lib\router\route.js:104:14)
at next (D:\Appium\node_modules\appium\node_modules\express\lib\router\route.js:104:14)
at next (D:\Appium\node_modules\appium\node_modules\express\lib\router\route.js:104:14)
at next (D:\Appium\node_modules\appium\node_modules\express\lib\router\route.js:104:14)
at next (D:\Appium\node_modules\appium\node_modules\express\lib\router\route.js:104:14)
at next (D:\Appium\node_modules\appium\node_modules\express\lib\router\route.js:104:14)
at next (D:\Appium\node_modules\appium\node_modules\express\lib\router\route.js:104:14)
at next (D:\Appium\node_modules\appium\node_modules\express\lib\router\route.js:104:14)
at next (D:\Appium\node_modules\appium\node_modules\express\lib\router\route.js:104:14)
at next (D:\Appium\node_modules\appium\node_modules\express\lib\router\route.js:104:14)
at next (D:\Appium\node_modules\appium\node_modules\express\lib\router\route.js:104:14)
at next (D:\Appium\node_modules\appium\node_modules\express\lib\router\route.js:104:14)
at next (D:\Appium\node_modules\appium\node_modules\express\lib\router\route.js:104:14)
at Route.dispatch (D:\Appium\node_modules\appium\node_modules\express\lib\router\route.js:91:3)
at Layer.handle as handle_request
at D:\Appium\node_modules\appium\node_modules\express\lib\router\index.js:267:22
at Function.proto.process_params (D:\Appium\node_modules\appium\node_modules\express\lib\router\index.js:321:12)
at next (D:\Appium\node_modules\appium\node_modules\express\lib\router\index.js:261:10)
at methodOverride (D:\Appium\node_modules\appium\node_modules\method-override\index.js:79:5)
at Layer.handle as handle_request
at trim_prefix (D:\Appium\node_modules\appium\node_modules\express\lib\router\index.js:302:13)
at D:\Appium\node_modules\appium\node_modules\express\lib\router\index.js:270:7
at Function.proto.process_params (D:\Appium\node_modules\appium\node_modules\express\lib\router\index.js:321:12)
at next (D:\Appium\node_modules\appium\node_modules\express\lib\router\index.js:261:10)
at logger (D:\Appium\node_modules\appium\node_modules\morgan\index.js:136:5)
at Layer.handle as handle_request
at trim_prefix (D:\Appium\node_modules\appium\node_modules\express\lib\router\index.js:302:13)
at D:\Appium\node_modules\appium\node_modules\express\lib\router\index.js:270:7
at Function.proto.process_params (D:\Appium\node_modules\appium\node_modules\express\lib\router\index.js:321:12)
at next (D:\Appium\node_modules\appium\node_modules\express\lib\router\index.js:261:10)
at D:\Appium\node_modules\appium\node_modules\body-parser\lib\read.js:111:5
at done (D:\Appium\node_modules\appium\node_modules\body-parser\node_modules\raw-body\index.js:248:14)
at IncomingMessage.onEnd (D:\Appium\node_modules\appium\node_modules\body-parser\node_modules\raw-body\index.js:294:7)
at IncomingMessage.g (events.js:199:16)
at IncomingMessage.emit (events.js:104:17)
at _stream_readable.js:908:16
at process._tickDomainCallback (node.js:381:11)
info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Requested a new session but one was in progress)","origValue":"Requested a new session but one was in progress"},"sessionId":"e71830ec-51e9-4e8b-93a4-27b424da5c55"}

共收到 8 条回复 时间 点赞

log 里面有这么一句:Requested a new session but one was in progress。 说明 appium server 正在处理上一个 session。

2 个方案:

  1. 这个问题说明你的 appium server 还在运行,此事你可以关掉你的 appium,然后重新打开。
  2. 你可以在启动 appium server 的时候,指定 override old session,这样就不会出现这个问题了。

#1 楼 @hp_test 您好 我试了一下 还是不行?请问有还有其他方法么?与其他软件冲突么、

请先正确使用 markdown 。。。

另外,我相信你试了 @hp_test 的方法后日志不会和帖子正文一样。你先确认下是不是确实试了之后错误日志还是和正文一样?

正如@hp_tests所说的,应该是有 session 没有关闭。把 appium server 关闭再打开,只运行一次测试脚本应该没问题吧?能不能把测试脚本贴上来,大家都看看是哪里不对。

把 sever 重启

—— 来自 TesterHome 官方 安卓客户端

重启手机

直接关闭 server 即可。这是因为 session 已经建立,第二个又要建立

流云 回复

你好,想请教下,怎么能保证每次执行完关闭 session 呢,每次感觉只是调试运行下,结果下次运行就不行了,然后报 UiAutomation not connected!

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