admin管理员组

文章数量:1191316

How to extend WebdriverIO V9 capability to add some additional parameters.I have tried the following method, but it's not met my requirement.

wdio.conf.ts
interface CustomParams {
  testCaseId?: number;
  testRunId?: number;
}

export const config: WebdriverIO.Config & { customParams: CustomParams } = {
  runner: "local",
  tsConfigPath: "./tsconfig.json",
  specs: ["./test/specs/**/*.ts"],
  exclude: [],
  maxInstances: 10,
  capabilities: [
    {
      browserName: "chrome"
    }
  ],
  customParams: {
    testCaseId: 1,
    testRunId: 1
  },
  after: function (result, capabilities, specs) {
    console.log("capabilities: ------", capabilities);
  }
};
custom-reporter.ts
import WDIOReporter, { RunnerStats } from "@wdio/reporter";
import type { Reporters } from "@wdio/types";
import type TestStats from "@wdio/reporter/build/stats/test"; 
interface CustomRunnerStats extends RunnerStats {
  config: RunnerStats["config"] & { customParams: { testCaseId?: number; testRunId?: number } };
}
let customParams: { testCaseId?: number | undefined; testRunId?: number | undefined };

export default class CustomReporter extends WDIOReporter {
  constructor(options: Partial<Reporters.Options>) {
    options = Object.assign(options, { stdout: true });
    super(options);
  }

  async onRunnerStart(runnerStats: CustomRunnerStats) {
    customParams = runnerStats.config.customParams;
    console.log("::::::::::::::::::::  onRunnerStart ~ customParams:", customParams);
  }

  async onTestPass(test: TestStats) {
    this.write(`Congratulations! Your test "${test.title}" passed 

本文标签: webdriver ioHow to extend and use WebdriverIO V9 capabilitiesStack Overflow