【问题标题】:react native appium with webdriver crash用 webdriver 崩溃反应原生 appium
【发布时间】:2021-05-21 11:53:12
【问题描述】:

我按照此tutorial 使用 appium 和 webdriver 在我的应用中设置测试。

我的 wdio.config 是

    exports.config = {
  services: ['appium'],
  port: 4723,
  runner: 'local',
  specs: ['./tests/*.js'],
  capabilities: [
    {
      maxInstances: 1,
      browserName: '',
      appiumVersion: '1.20.2',
      platformName: 'Android',
      platformVersion: '11',
      deviceName: '99211FFAZ00843',
      app: './apps/app-dev-debug.apk',
      automationName: 'UiAutomator2',
    },
  ],

  logLevel: 'trace',
  bail: 0,
  waitforTimeout: 10000,
  connectionRetryTimeout: 90000,
  connectionRetryCount: 3,
  framework: 'mocha',
  reporters: ['spec'],
  mochaOpts: {
    ui: 'bdd',
    timeout: 60000,
  },
};

package.json

{
  "name": "automationTests",
  "version": "1.0.0",
  "description": "",
  "main": "wdio.conf.js",
  "directories": {
    "test": "tests"
  },
  "dependencies": {
    "@wdio/cli": "^7.0.5",
    "chai": "^4.3.0",
    "wdio-appium-service": "^0.2.3",
    "webdriverio": "^7.0.5"
  },
  "devDependencies": {
    "@wdio/local-runner": "^7.0.5",
    "@wdio/mocha-framework": "^7.0.4",
    "@wdio/spec-reporter": "^7.0.4",
    "@wdio/sync": "^7.0.5",
    "chromedriver": "^88.0.0",
    "wdio-chromedriver-service": "^6.0.4"
  },
  "scripts": {
    "test": "mocha"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

我有带有测试文件 App.test.js 的测试文件夹

const TestsIds = require('../../../src/assets/test_ids');
var expect = require('chai').expect;

describe('Simple App testing', () => {
  beforeEach(() => {});

  it('Valid Login Test', () => {
    const skipButton = $(`~$view-app-id`).waitForDisplayed(3000, false);
    skipButton.click();
  });
});

我收到了这个错误

 ERROR webdriver: Request failed with status 404 due to unknown command: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource
[0-0] 2021-02-18T12:34:11.688Z ERROR webdriver: unknown command: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource
    at Object.getErrorFromResponseBody (/Users/XXX/Desktop/projects/XXXXX/node_modules/webdriver/build/utils.js:189:12)
    at WebDriverRequest._request (//Users/XXX/Desktop/projects/XXXXX/node_modules/webdriver/build/request.js:168:31)
    at process._tickCallback (internal/process/next_tick.js:68:7)
[0-0] 2021-02-18T12:34:11.690Z ERROR @wdio/runner: Error: Failed to create session.
The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource
    at Object.startWebDriverSession (//Users/XXX/Desktop/projects/XXXXX/node_modules/webdriver/build/utils.js:68:15)
    at process._tickCallback (internal/process/next_tick.js:68:7)
2021-02-18T12:34:11.810Z DEBUG @wdio/local-runner: Runner 0-0 finished with exit code 1
[0-0] FAILED in undefined - /tests/App.test.js
2021-02-18T12:34:11.811Z INFO @wdio/cli:launcher: Run onComplete hook

Spec Files:      0 passed, 1 failed, 1 total (100% completed) in 00:00:01

另外我在 app.test.js 中遇到错误

skipButton.click() is not function

【问题讨论】:

  • 嗨,您有来自 [Appium] 服务器提示符的日志吗?
  • 不,只是我添加的内容
  • ok 发现本教程缺少appium server url路径,我会重写config文件,别忘了重启appium server
  • 您好,您的问题解决了吗?
  • 你能分享一些可重现的代码吗?

标签: react-native testing appium chai


【解决方案1】:

在此处查找配置:https://webdriver.io/docs/options/#webdriver-options

您需要像这样更改配置文件:

exports.config = {
  services: ['appium'],
  port: 4723,

  // PATH is important for appium local server :
  path: '/wd/hub/',
  
  runner: 'local',
  specs: ['./tests/*.js'],
  capabilities: [
    {
      maxInstances: 1,
      browserName: '',
      appiumVersion: '1.20.2',
      platformName: 'Android',
      platformVersion: '11',
      deviceName: '99211FFAZ00843',
      app: './apps/app-dev-debug.apk',
      automationName: 'UiAutomator2',
    },
  ],

  logLevel: 'trace',
  bail: 0,
  waitforTimeout: 10000,
  connectionRetryTimeout: 90000,
  connectionRetryCount: 3,
  framework: 'mocha',
  reporters: ['spec'],
  mochaOpts: {
    ui: 'bdd',
    timeout: 60000,
  },
};

为了期待您的测试有所收获,请尝试对您的 App.test.js 进行此更新:

const expect = require('chai').expect;
const TestsIds = require('../../../src/assets/test_ids');

const delay = millis => new Promise((resolve, reject) => {
    setTimeout(_ => resolve(), millis)
});


describe('Simple App testing', () => {
    
  // Adding time (20sec) to make sure the app is load prior to test is run
  before(async () => {
    await delay(20000);
  });

  it('My first test', async => {
    // here we uss waitForDisplayed with default settings from wdio.conf.js
    $('~[YourAccessibilityLabel]').waitForDisplayed();

    // make sure [YourAccessibilityLabel] exist with simple expect :
    let isHome = $('~[YourAccessibilityLabel]').isExisting();
    expect(isHome).to.equal(true);

    // then click to continue your app testing
    skipButton.click();
  });
});

【讨论】:

  • 嗨,我收到错误 @wdio/utils:initialiseServices: 错误:找不到模块“appium”。此外,它看起来像是打开了应用程序并在 2 秒后关闭了它,但测试成功。使用什么语法?我应该暂停驱动程序吗?
  • 您好,对于第一个错误:尝试在您的测试文件夹上重新运行 Yarn install 或 NPM install 命令,然后我更新了我的答案以向您展示如何创建一个简单的期望测试,不要忘记更改 [YourAccessibilityLabel] :)
  • 嗨,我在 test 文件夹中运行 npm install 仍然收到错误 @wdio/utils:initialiseServices: initialise service "appium" as NPM package
  • 好的,这不是错误,如果你得到类似的东西:DEBUG @wdio/utils:initialiseServices: 将服务“appium”初始化为 NPM 包,你的错误已修复(错误:找不到模块 'appium' )。这是一个简单的日志,通知您 Appium 服务即将启动
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-11-11
  • 1970-01-01
  • 2022-11-11
  • 1970-01-01
  • 2018-02-21
  • 1970-01-01
  • 2021-12-26
相关资源
最近更新 更多