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

React Native使用Webdriver运行Appium测试提示用例被跳过如何解决

问题修复步骤

1. 修正wdio.conf.js配置

你当前的配置文件是针对Chrome浏览器测试的,和安卓原生应用测试需求不匹配,且多余配置了不需要的chromedriver服务,直接替换配置文件内容如下:

exports.config = {
  port: 4723,
  // Appium 2.x 默认basePath为/,如果你用的是Appium 1.x版本就填/wd/hub
  path: '/',
  specs: ["./test/specs/**/*.js"],
  exclude: [],
  maxInstances: 10,
  capabilities: [
    {
      maxInstances: 1,
      platformName: "Android",
      platformVersion: "9",
      deviceName: "Pixel API 28 AOSP",
      app: "./android/app/build/outputs/apk/flavor/debug/app-flavor-debug.apk",
      // 这里替换成你自己应用的包名,从android/app/src/main/AndroidManifest.xml的package属性取值
      appPackage: "你的应用实际包名",
      appActivity: ".MainActivity",
      automationName: "Espresso",
      noReset: true // 可选配置,避免每次测试都重装应用,提升执行速度
    },
  ],
  logLevel: "info",
  bail: 0,
  waitforTimeout: 10000,
  connectionRetryTimeout: 120000,
  connectionRetryCount: 3,
  // 移除不需要的chromedriver服务
  services: ["appium"],
  framework: "jasmine",
  reporters: ["spec"],
  jasmineOpts: {
    defaultTimeoutInterval: 60000,
  },
};

2. 修正测试文件代码

使用WDIO官方运行器执行测试时,会自动全局注入browser对象,不需要手动初始化WebDriverIO连接,修改测试文件内容如下:

describe('应用基础测试', () => {
  it('验证header正常显示', async () => {
    const header = await browser.$("~header");
    await expect(header).toBeDisplayed();
  });
});

3. 前置校验项

  • 执行appium driver list确认已安装Espresso驱动,如果没有安装,执行appium driver install espresso
  • 确认Appium服务启动时的路径和配置文件一致,如果你启动Appium时加了--base-path /wd/hub参数,就把配置文件里的path值改成/wd/hub
  • 确认配置文件里填写的apk路径是正确的,相对路径以项目根目录为基准

修改完成后重新执行npx wdio run ./wdio.conf.js即可正常运行测试。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.24 13:54:05