Webdriverio selenium standalone 不更新驱动程序版本

Webdriverio selenium standalone doesn't update driver version

我用 WebdriverIO 6、Typescript 和 Cucumber 制作了一些小演示项目。 我把它放在配置文件中 wdio.CHROME.conf.ts:

import { config } from './wdio.conf';
import { CHROME_ARGS } from './chrome-args';

const seleniumConfig = {
  version: '3.141.59',
  drivers: { chrome: { version: '87.0.4280.20' } },
};

const browserOptions: WebDriver.ChromeOptions & { args: Array<string> } = {
args: [
...CHROME_ARGS,
...(process.argv.includes('--headless') ? ['--headless', '--no-sandbox'] : []),
'--window-size=1920,1080',
 ],
};

const seleniumOpts = config.services?.find(
  (service) => Array.isArray(service) && service[0] === 'selenium-standalone'
) as SeleniumStandaloneOptions;

seleniumOpts.args = { ...seleniumConfig };
seleniumOpts.installArgs = { ...seleniumConfig };

console.log(seleniumOpts);

const browserConfig: WebdriverIO.Config = {
...config,
capabilities: [
{
  browserName: 'chrome',
  'goog:chromeOptions': browserOptions,
  },
 ],
};

exports.config = browserConfig;

wdio.conf.ts中的这个:

import * as path from 'path';
import * as appRoot from 'app-root-path';
import { commandsFactory } from './commands-factory';

export const config: WebdriverIO.Config = {
  
  specs: [
    './src/features/**/*.feature',
    // './src/features/login.feature',
    // './src/features/dashboard.feature'
  ],
  
  exclude: [
    
  ],
 
  maxInstances: 1,
  logLevel: 'trace',
  bail: 0,
  baseUrl: 'http://automationpractice.com',
  waitforTimeout: 10000,
  connectionRetryTimeout: 90000,
  connectionRetryCount: 3,
  services: [
    [
      'selenium-standalone',
      {
        logs: 'logs',
      },
    ],
  ],
  outputDir: path.join(appRoot.path, '/logs'),

  framework: 'cucumber',
  reporters: [
    'spec',
    [
      'allure',
      {
        outputDir: 'allure-results',
        disableWebdriverStepsReporting: true,
        disableWebdriverScreenshotsReporting: false,
        useCucumberStepReporter: true,
      },
    ],
  ],

  cucumberOpts: {
    backtrace: false,
    failAmbiguousDefinitions: true,
    failFast: false,
    ignoreUndefinedDefinitions: false,
    name: [],
    snippets: false,
    source: true,
    profile: [],
    require: [
      './src/step_definitions/*.ts',
    ],
    snippetSyntax: undefined,
    strict: true,
    tagExpression: 'not @Login',
    tagsInTitle: false,
    timeout: 60000,
  },



  before(capabilities, specs) {
    const commands = commandsFactory({ waitForTimeout: this.waitforTimeout });

    /* eslint-disable */
    const chai = require('chai');
    global.should = chai.should();

    // Sample command
    function browserCustomCommandExample(text) {
      console.log(text);
    }

    browser.addCommand('browserCustomCommandExample', browserCustomCommandExample);

    Object.keys(commands).forEach((key) => {
      browser.addCommand(key, commands[key]);
    });
  },

  afterStep(step, context, { error, result, passed, duration }) {
    if (error) {
      browser.takeScreenshot();
    }
  },
};  

但是在我执行 npm install 并尝试 运行 测试 npm run test:chrome:headless 之后,我得到了这个错误:

[0-0]  Error:  Failed to create session.
session not created: This version of ChromeDriver only supports Chrome version 85
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'LAPTOP-QUTK6LBV', ip: '192.168.1.8', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_271'
Driver info: driver.version: unknown  

我曾尝试将 wdio.CHROME.conf.ts 中的驱动程序版本更新到 87,但没有帮助。
它只是不下载 chrome 驱动程序的版本 87,而是卡在版本 85.
当我查看 node_modules\selenium-standalone\.selenium\chromedriver 时,只有版本 85,它不会下载版本 87(85 是我在配置文件中的先前版本)。
在我的机器上,chrome 浏览器版本是 87,它需要相同版本的 chrome 驱动程序才能工作(根据我的理解:D)
我尝试删除 node_modules 并从头开始删除,但没有成功。
这是 link 我的回购 https://github.com/mareru/webdriverIO-shop-demo
有人可以帮忙:) 谢谢!

我替换了这些行:

const seleniumOpts = config.services?.find(
  (service) => Array.isArray(service) && service[0] === 'selenium-standalone'
) as SeleniumStandaloneOptions;

seleniumOpts.args = { ...seleniumConfig };
seleniumOpts.installArgs = { ...seleniumConfig };

有了这些

config.services = [
  [
    'selenium-standalone',
    {
      logs: 'logs',
      args: seleniumConfig,
      installArgs: seleniumConfig,
    },
  ],
];

它奏效了。似乎以前的代码没有很好地生成花括号。
参数 logs、args、installArgs 应该在联合花括号中而不是在单独的花括号中。
它生成了这个:

  [
    'selenium-standalone',
    { logs: 'logs' },
                         args: { version: '3.141.59', drivers: [Object] },
    installArgs: { version: '3.141.59', drivers: [Object] }
  ]
]

本来应该是这样的

[
  [
    'selenium-standalone',
    { logs: 'logs', args: [Object], installArgs: [Object] }
  ]
]