React native 用webdriver崩溃来响应本机应用程序

React native 用webdriver崩溃来响应本机应用程序,react-native,testing,appium,chai,React Native,Testing,Appium,Chai,我遵循这一点,使用appium和webdriver在我的应用程序中设置测试 我的wdio.config是 exports.config = { services: ['appium'], port: 4723, runner: 'local', specs: ['./tests/*.js'], capabilities: [ { maxInstances: 1, browserName: '', appiumVersion:

我遵循这一点,使用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();
  });
});
skipButton.click() is not function
我犯了这个错误

 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中发现错误

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();
  });
});
skipButton.click() is not function

在此处查找配置:

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

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();
  });
});

您好,您有[Appium]服务器提示符的日志吗?没有,只是我添加的。我发现本教程缺少Appium服务器url的路径,我将重写配置文件,并且不要忘记重新启动Appium服务器。您好,您解决了您的问题吗?您能分享一些可复制的代码吗?您好,我得到错误@wdio/utils:initialiseServices:error:找不到模块“appium”。此外,它看起来像是打开了应用程序,2秒钟后关闭了应用程序,但测试成功。使用什么语法?我应该暂停驱动程序吗?您好,第一个错误是:尝试在您的测试文件夹上重新运行Thread install或NPM install命令,然后我更新了我的答案,向您展示如何创建简单的expect测试,不要忘了更改[YourAccessibilityLabel]:)您好,我在测试文件夹中运行npm安装,但仍然得到错误@wdio/utils:initialiseServices:initialise service“appium”作为npm包。这不是一个错误,如果您得到类似以下内容:DEBUG@wdio/utils:initialiseServices:initialise service“appium”作为npm包,您的错误已经修复(错误:找不到模块“appium”)。这是一个简单的日志,告诉您Appium服务即将启动。你解决了我的问题。非常感谢。