Webdriverio 和 Appium,无法附加检查器和会话问题

Webdriverio and Appium, can't attach inspector and troubles with sessions

我是 Appium 和 WebdriverIO 的新手,我创建了一个应用程序(一个 .zip 文件),我想用这两个框架测试它。

TL:DR - 转到第四个代码块。

我按照一些教程创建了一个包含

的项目

当然还有 package.json.

首先,我的 package.json:

{
  "name": "my-test",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "wdio": "wdio run ./config/wdio.conf.js",
    "ios.app": "./node_modules/.bin/wdio ./config/wdio.ios.app.conf.js"
  },
  "devDependencies": {
    "@wdio/appium-service": "^7.16.16",
    "@wdio/cli": "^7.16.16",
    "@wdio/devtools-service": "^7.16.16",
    "@wdio/local-runner": "^7.16.16",
    "@wdio/mocha-framework": "^7.16.15",
    "@wdio/spec-reporter": "^7.16.14",
    "chai": "^4.3.6",
    "chromedriver": "^99.0.0",
    "wdio-chromedriver-service": "^7.2.8",
    "webdriverio": "^7.16.16"
  }
}

然后,我的 config 文件,分为 sharedios :

shared.conf.js

exports.config = {
  // ====================
  // Runner and framework
  // Configuration
  // ====================
  runner: "local",
  framework: "mocha",
  mochaOpts: {
    timeout: 30000,
  },
  sync: true,
  logLevel: "info",
  deprecationWarnings: true,
  bail: 0,
  baseUrl: "localhost",
  // path for appium sessions
  path: "/wd/hub",
  waitforTimeout: 15000,
  connectionRetryTimeout: 90000,
  connectionRetryCount: 3,
  reporters: ["spec"],
  autoGrantPermissions: true,
  autoAcceptAlerts: true,
  nativeWebTap: true,

  // ====================
  // Appium Configuration
  // ====================
  services: [
    [
      "appium",
      {
        // For options see
        // https://github.com/webdriverio/webdriverio/tree/master/packages/wdio-appium-service
        args: {
          // Auto download ChromeDriver
          relaxedSecurity: true,
          // chromedriverAutodownload: true,
          // For more arguments see
          // https://github.com/webdriverio/webdriverio/tree/master/packages/wdio-appium-service
        },
        command: "appium",
      },
    ],
  ],
  port: 4723,
};

wdio.ios.app.conf.js

const { join } = require("path");
const { config } = require("./shared.conf");

// ============
// Specs
// ============
config.specs = ["./tests/specs/**/*.spec.js"];

// ============
// Capabilities
// ============
// For all capabilities please check
// http://appium.io/docs/en/writing-running-appium/caps/#general-capabilities
config.capabilities = [
  {
    // The defaults you need to have in your config
    platformName: "iOS",
    maxInstances: 1,
    // For W3C the appium capabilities need to have an extension prefix
    // This is `appium:` for all Appium Capabilities which can be found here
    // http://appium.io/docs/en/writing-running-appium/caps/
    "appium:deviceName": "iPhone 7",
    "appium:platformVersion": "15.2",
    "appium:orientation": "PORTRAIT",
    // `automationName` will be mandatory, see
    // https://github.com/appium/appium/releases/tag/v1.13.0
    "appium:automationName": "XCUITest",
    // The path to the app
    "appium:app": join(process.cwd(), "../../../my-test.zip"),
    // Read the reset strategies very well, they differ per platform, see
    // http://appium.io/docs/en/writing-running-appium/other/reset-strategies/
    "appium:noReset": true,
    // How long (in seconds) Appium will wait for a new command from the client before assuming the client quit and ending the session
    // default: 240
    "appium:newCommandTimeout": 240,
  },
];

exports.config = config;

所以我创建了一个非常简单的测试文件:有一个登录屏幕,它找到登录文本区域,写登录名,同样的密码,然后按下按钮“登录” :

describe("a test group", function () {
  it("a test", async function () {
    console.log("*******start*******");
    // commands here
    const selectUsername = 'type == "XCUIElementTypeTextField"';
    const selectPassword = 'type == "XCUIElementTypeSecureTextField"';
    const username = await $(`-ios predicate string:${selectUsername}`);
    const password = await $(`-ios predicate string:${selectPassword}`);
    const btnText = 'label == "SIGNIN"';
    const loginBtn = await $(`-ios predicate string:${btnText}`);
    await username.click();
    await username.addValue("my@email.com");
    await password.click();
    await password.addValue("mypassword");
    await loginBtn.click();
  });
});

我的问题是当测试是 运行 a) 如果我打开 appium inspector,我找不到任何 运行 session,即使它必须存在于某处:

plus(次要)我认为 session 永远不会停止。如果我 re-run 测试,模拟器中的应用程序 运行 显示已经 logged-in 的页面,测试失败(因为没有找到 login/password 字段)。

session在哪里?我做错了什么?

已解决。

我无法编辑 config 文件中的路径,但如果我将 appium inspector 中的 remote path 更改为 / ,它会找到当前会话。