如何通过 webdriverio wdio 文件更改 selenium-standalone 端口号?

How to change selenium-standalone port number via webdriverio wdio file?

我需要更改 selenium 独立服务器默认使用的端口号 (4444)。端口 4444 当前正在使用中,有没有办法通过 wdio 文件更改端口号?

// Test runner services
// Services take over a specific job you don't want to take care of. They enhance
// your test setup with almost no effort. Unlike plugins, they don't add new
// commands. Instead, they hook themselves up into the test process.
services: ['selenium-standalone'],

目前我正在通过以下命令启动 selenium 服务器:

./node_modules/.bin/selenium-standalone start

我也曾尝试使用以下方法,但没有成功:

./node_modules/.bin/selenium-standalone start -port 7777

运行 上面的命令仍然尝试 运行 端口 4444 上的 selenium 服务器。

到 运行 特定端口上的 selenium-standalone 您应该使用以下语法:

./node_modules/.bin/selenium-standalone start -- -port 7777

更改 wdi.conf.js 中的端口:

seleniumArgs: {
  seleniumArgs: ["-port", "7777"],
},

此外,阅读有关 wdio 配置文件的更多信息 here and about wdio-cli here

因此,您的最终 wdio.conf.js 应该如下所示:

exports.config = {
  /**
  * server configurations
  */
  services: ['selenium-standalone'],
  port: 7777,
  seleniumArgs: {
    seleniumArgs: ["-port", "7777"],
  },
}
nodejs webdriver-manager start --seleniumPort 5555