我在 Appium(iMac 上的 Android 模拟器)中运行了大约 90 个测试,一切都很好,直到我突然开始观察到这个错误:
Starting logs capture with command: /Users/username/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 logcat -v threadtime
E selenium.common.exceptions.WebDriverException: Message: An unknown server-side
error occurred while processing the command. Original error: Cannot find any free port in range
8200..8299}. Please set the available port number by providing the systemPort capability or
double check the processes that are locking ports within this range and terminate these which
are not needed anymore
我做了一些事情来解决这个问题,但没有任何效果:
1.
adb kill-server
adb reconnect
我确实清理了模拟器并重新启动了。
除此之外,我没有发现8200-8299之间的任何端口已在系统中使用。
我也添加了
systemPort
功能,但我仍然看到相同的错误。
我不知道如何解决这个问题。
更新:
发现更多日志并发现端口转发没有被 UIAutomator 2(或 adb)清除,这就是为什么我在 iOS 上没有问题,但仅在 Android 中发布。以下是 appium 服务器末尾的日志:
[debug] [35m[WD Proxy] [39m Proxying [DELETE /] to [DELETE http://127.0.0.1:8200/wd/hub/session/d1f94433-2c44-4dac-a836-461ab7f41130] with no body
[debug] [35m[UiAutomator2] [39m Deleting UiAutomator2 server session
[debug] [35m[WD Proxy] [39m Matched '/' to command name 'deleteSession'
[debug] [35m[WD Proxy] [39m Proxying [DELETE /] to [DELETE http://127.0.0.1:8201/wd/hub/session/37137b29-a9a6-4d83-b2d9-ce510f601a2d] with no body
[debug] [35m[UiAutomator2] [39m Deleting UiAutomator2 server session
其中
127.0.0.1:8201
上升到 127.0.0.1:8299
并删除 100 个活动会话,这是我没想到的。
此外,在 netstat 输出中,我确实看到 TCP 端口 127.0.0.1:8200 - 127.0.0.1:8299(监听)已打开
adb -s $UDID forward --remove-all
不适合我 我试过这个
--session-override
创建新的 appium 会话时。尽管我担心 get_screenshot() 方法,因为它需要守护进程启动单独的会话,但效果很好。会更新