我在跟着网络上的教程配置appium inspector后,运行的时候报错:
Could not connect to Appium server URL ‘http://127.0.0.1:7555/wd/hub’. Please check if the server is running and the URL is correct (valid URLs can be found at the start of the Appium server log). If you are using the Inspector’s browser version, ensure the server has been started with ‘–allow-cors’.
查看appium server发现
[HTTP] No route found for /wd/hub/session
[HTTP] <-- POST /wd/hub/session 404 6 ms - 211
表示在向 Appium 服务器发起 POST 请求时,路径 /wd/hub/session
没有找到。这通常意味着 Appium 服务器的路径配置不正确,或者你可能正在使用的是 Appium 2.x。
Appium 版本问题
Appium 1.x 和 Appium 2.x 的 API 路径存在一些变化。
-
在 Appium 1.x 中,所有请求的基础路径是
/wd/hub
,所以命令会发到http://127.0.0.1:4723/wd/hub/session
。 -
在 Appium 2.x 中,默认情况下基础路径不再包含
/wd/hub
,所有请求路径是直接从根路径/
开始。所以命令应该发到http://127.0.0.1:4723/session
。
网上很多配置教程都是用的老版本。
所有跟着教程在 Appium 2.x 中仍然使用 /wd/hub/session
,就会出现这个 “No route found” 的问题。
解决方法:
更新客户端 URL
如果你不想修改 Appium 服务器的基础路径,可以直接更新你的客户端代码,将 Appium 服务器的 URL 更新为不包含 /wd/hub
,如下:
const serverUrl = 'http://127.0.0.1:4723'; // 不再包含 /wd/hub