【发布时间】:2020-11-21 16:07:28
【问题描述】:
我使用 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,但没有帮助。
它只是不下载 87 版的 chrome 驱动程序,而是卡在 85 版中。
当我查看node_modules\selenium-standalone\.selenium\chromedriver 时,只有版本 85,它不会下载版本 87(85 是我在配置文件中的先前版本)。
在我的机器上,chrome 浏览器版本是 87,它需要相同版本的 chrome 驱动程序才能工作(据我了解:D)
我尝试删除 node_modules 并从头开始,但没有成功。
这是我的回购链接https://github.com/mareru/webdriverIO-shop-demo
有人可以帮忙吗:)
谢谢!
【问题讨论】:
-
我看到你正在尝试使用我来自gitlab.com/bar_foo/wdio-cucumber-typescript/-/blob/master/…的示例
-
不知道是哪里出了问题,可能是复制粘贴的时候打错了,确保使用最新版本的@wdio,删除包锁json和node模块,重新安装包再试一次
-
@MikeG。我修复了它与您的示例略有不同的形式。你会做不同的事吗?它就是这样工作的。
标签: selenium selenium-chromedriver webdriver-io