You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

升级至Appium 1.22.3后,程序化启动出现404错误求助

问题分析

升级到Appium 1.22.3后,程序化启动服务时出现GET /status 404错误,核心原因是客户端请求的API路径与Appium Server的实际端点不匹配,或是Java Client与Appium Server版本兼容性未同步。

解决方法

1. 补全API基础路径

Appium 1.x版本默认API基础路径为/wd/hub,旧版Java Client可能自动拼接该路径,但升级后若Client版本未同步,service.getUrl()仅返回http://localhost:端口,缺少/wd/hub后缀,导致请求/status时找不到端点。

修改getServiceUrl()方法,手动添加基础路径:

public URL getServiceUrl() {
    try {
        return new URL(service.getUrl().toString() + "/wd/hub");
    } catch (MalformedURLException e) {
        throw new RuntimeException("Failed to construct Appium service URL", e);
    }
}

2. 同步Java Client与Server版本

确保Appium Java Client版本与1.22.3兼容,推荐使用7.6.0及以上版本,可通过依赖管理工具调整:

  • Maven依赖:
<dependency>
    <groupId>io.appium</groupId>
    <artifactId>java-client</artifactId>
    <version>7.6.0</version>
</dependency>
  • Gradle依赖:
implementation 'io.appium:java-client:7.6.0'

3. 等待服务器完全就绪

避免服务器刚启动就创建Driver,添加等待逻辑确认服务可用:

// 在service.start()后插入以下代码
Wait<AppiumDriverLocalService> wait = new FluentWait<>(service)
        .withTimeout(Duration.ofSeconds(30))
        .pollingEvery(Duration.ofSeconds(2))
        .ignoring(IOException.class);

wait.until(s -> {
    try {
        HttpURLConnection connection = (HttpURLConnection) new URL(s.getUrl() + "/wd/hub/status").openConnection();
        connection.setRequestMethod("GET");
        return connection.getResponseCode() == 200;
    } catch (Exception e) {
        return false;
    }
});
验证步骤
  1. 修改后重新运行测试,查看日志中请求路径是否变为/wd/hub/status
  2. 确认Appium Server日志返回200状态码而非404

内容的提问来源于stack exchange,提问作者manoj

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 20:24:51