反应本机 appium 与 webdriver 崩溃

react native appium with webdriver crash

我按照此 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

在此处查找配置: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();
  });
});