WebDriverIO - 运行 在 Google Chrome 时的奇怪行为
WebDriverIO - Strange behaviour while running on Google Chrome
我一直在为我们的项目使用 JavaScript 和 Cucumber 使用 wdio。
似乎 chrome 选项似乎没有任何效果。 Chrome 浏览器未启动最大化。
goog:chromeOptions': {
args: ['--start-maximized']
}
在这个网站的某个地方,我看到有人提到在选项中使用“disable-gpu”,我也试过了,但没有效果。
当脚本在浏览器上运行时,奇怪的行为是,它通过捏住屏幕来执行每个操作。我想知道,也许是由于不兼容,因此将每个 npm 包更新到最新版本,但它仍然以相同的方式运行。
使用的版本 -
WebDriver Version: 6.3.5
Chrome Driver Version: 84.0.1
Google Chrome Version: 84.0.4147.105
package.json 依赖关系 -
"devDependencies": {
"@wdio/cli": "^6.3.6",
"@wdio/cucumber-framework": "^6.3.0",
"@wdio/local-runner": "^6.3.6",
"chromedriver": "^84.0.1",
"cucumber-html-reporter": "^5.2.0",
"eslint": "^7.2.0",
"eslint-config-standard": "^14.1.1",
"eslint-plugin-import": "^2.21.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"wdio-cucumber-framework": "^2.2.8",
"wdio-cucumber-reporter": "0.0.2",
"wdio-cucumberjs-json-reporter": "^2.0.2",
"wdio-firefox-profile-service": "^0.1.3",
"wdio-selenium-standalone-service": "0.0.12",
"wdio-viewport-size": "^1.0.1",
"webdriver-manager": "^12.1.7",
"webdriverio": "^6.3.5"
},
"dependencies": {
"@wdio/sync": "^6.3.6",
"axios": "^0.19.2",
"chai": "^4.2.0",
"chance": "^1.1.6",
"cucumber": "^6.0.5",
"cucumber-pretty": "^6.0.0",
"fs-extra": "^9.0.1",
"knex": "^0.21.1",
"lodash": "^4.17.15",
"moment": "^2.26.0",
"multiple-cucumber-html-reporter": "^1.18.0",
"postgres": "^1.0.2",
"ramda": "^0.27.0",
"rimraf": "^3.0.2",
"underscore": "^1.10.2",
"wdio": "^4.0.0",
}
wdio.conf.js 文件 -
const cucumberJSON = require('wdio-cucumberjs-json-reporter')
const multipleCucumberHtmlReporter = require('multiple-cucumber-html-reporter')
const moment = require('moment')
const { removeSync } = require('fs-extra')
exports.config = {
runner: 'local',
specs: [
'./features/E2E/E2E.feature'
],
exclude: [
],
maxInstances: 10,
services: ['selenium-standalone'],
capabilities: [{
maxInstances: 5,
browserName: 'chrome',
'goog:chromeOptions': {
args: ['--start-maximized']
},
'cjson:metadata': {
// For a browser
browser: {
name: 'chrome',
version: '58'
},
device: 'HP Elite',
platform: {
name: 'windows',
version: '10'
}
}
}],
logLevel: 'debug',
bail: 0,
waitforTimeout: 10000,
connectionRetryTimeout: 120000,
connectionRetryCount: 3,
services: ['selenium-standalone'],
framework: 'cucumber',
reporters: ['cucumberjs-json'],
cucumberOpts: {
require: ['./stepDefinitions/given.js', './stepDefinitions/when.js', './stepDefinitions/then.js'],
backtrace: true,
requireModule: [],
dryRun: false,
failFast: false,
format: ['pretty'],
snippets: true,
source: true,
profile: [],
strict: true,
tagExpression: '@E2E',
timeout: 60000,
ignoreUndefinedDefinitions: false
},
onPrepare () {
removeSync('.tmp/')
console.log('Starting cucumber tests')
},
async afterStep () {
await browser.takeScreenshot().then((val) => {
cucumberJSON.default.attach(val, 'image/png')
}).catch((err) => {
console.log('Error in capturing screenshots', err)
})
},
onComplete () {
multipleCucumberHtmlReporter.generate({
openReportInBrowser: true,
reportName: 'Project Report',
screenshotPath: './reports/screenshots/',
displayDuration: true,
saveCollectedJSON: false,
jsonDir: '.tmp/json/',
reportPath: './reports/',
customData: {
title: 'Project Data',
data: [
{ label: 'Project', value: 'Project Value'},
{ label: 'Release', value: '1.0' },
{ label: 'Execution Start Date', value: moment().format('dddd, MMMM Do YYYY') }
]
}
})
}
}
任何人都可以帮忙。我尝试了很多方法,但结果总是一样。也许我在这里做错了什么。请指导。
我想我明白了,为什么它不起作用。我已按照以下步骤解决。希望它能帮助面临同样问题的人。
- 已执行
npx wdio config
- 已回答必填问题
- 在安装服务的时候,我选择了
chromdriver
而不是selenium-standalone
- 安装了所有必需的软件包,其中包括 -
(猜猜你也可以单独安装这些,我只是选择了这条路线来执行)
chromedriver
wdio-chromedriver-service
- 用新配置替换了我的旧配置,它又开始工作了。它甚至以最大化模式启动浏览器。
运行-
的结果
Starting cucumber tests
Starting ChromeDriver 84.0.4147.30 (48b3e868b4cc0aa7e8149519690b6f6949e110a8-refs/branch-heads/4147@{#310}) on port 9515
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
我真的不知道为什么它会表现得如此奇怪,因为 Selenium-standalone 确实包含 chromeDriver。如果有人知道这个问题的答案,请补充,会很好学习!
我一直在为我们的项目使用 JavaScript 和 Cucumber 使用 wdio。
似乎 chrome 选项似乎没有任何效果。 Chrome 浏览器未启动最大化。
goog:chromeOptions': {
args: ['--start-maximized']
}
在这个网站的某个地方,我看到有人提到在选项中使用“disable-gpu”,我也试过了,但没有效果。
当脚本在浏览器上运行时,奇怪的行为是,它通过捏住屏幕来执行每个操作。我想知道,也许是由于不兼容,因此将每个 npm 包更新到最新版本,但它仍然以相同的方式运行。
使用的版本 -
WebDriver Version: 6.3.5
Chrome Driver Version: 84.0.1
Google Chrome Version: 84.0.4147.105
package.json 依赖关系 -
"devDependencies": {
"@wdio/cli": "^6.3.6",
"@wdio/cucumber-framework": "^6.3.0",
"@wdio/local-runner": "^6.3.6",
"chromedriver": "^84.0.1",
"cucumber-html-reporter": "^5.2.0",
"eslint": "^7.2.0",
"eslint-config-standard": "^14.1.1",
"eslint-plugin-import": "^2.21.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"wdio-cucumber-framework": "^2.2.8",
"wdio-cucumber-reporter": "0.0.2",
"wdio-cucumberjs-json-reporter": "^2.0.2",
"wdio-firefox-profile-service": "^0.1.3",
"wdio-selenium-standalone-service": "0.0.12",
"wdio-viewport-size": "^1.0.1",
"webdriver-manager": "^12.1.7",
"webdriverio": "^6.3.5"
},
"dependencies": {
"@wdio/sync": "^6.3.6",
"axios": "^0.19.2",
"chai": "^4.2.0",
"chance": "^1.1.6",
"cucumber": "^6.0.5",
"cucumber-pretty": "^6.0.0",
"fs-extra": "^9.0.1",
"knex": "^0.21.1",
"lodash": "^4.17.15",
"moment": "^2.26.0",
"multiple-cucumber-html-reporter": "^1.18.0",
"postgres": "^1.0.2",
"ramda": "^0.27.0",
"rimraf": "^3.0.2",
"underscore": "^1.10.2",
"wdio": "^4.0.0",
}
wdio.conf.js 文件 -
const cucumberJSON = require('wdio-cucumberjs-json-reporter')
const multipleCucumberHtmlReporter = require('multiple-cucumber-html-reporter')
const moment = require('moment')
const { removeSync } = require('fs-extra')
exports.config = {
runner: 'local',
specs: [
'./features/E2E/E2E.feature'
],
exclude: [
],
maxInstances: 10,
services: ['selenium-standalone'],
capabilities: [{
maxInstances: 5,
browserName: 'chrome',
'goog:chromeOptions': {
args: ['--start-maximized']
},
'cjson:metadata': {
// For a browser
browser: {
name: 'chrome',
version: '58'
},
device: 'HP Elite',
platform: {
name: 'windows',
version: '10'
}
}
}],
logLevel: 'debug',
bail: 0,
waitforTimeout: 10000,
connectionRetryTimeout: 120000,
connectionRetryCount: 3,
services: ['selenium-standalone'],
framework: 'cucumber',
reporters: ['cucumberjs-json'],
cucumberOpts: {
require: ['./stepDefinitions/given.js', './stepDefinitions/when.js', './stepDefinitions/then.js'],
backtrace: true,
requireModule: [],
dryRun: false,
failFast: false,
format: ['pretty'],
snippets: true,
source: true,
profile: [],
strict: true,
tagExpression: '@E2E',
timeout: 60000,
ignoreUndefinedDefinitions: false
},
onPrepare () {
removeSync('.tmp/')
console.log('Starting cucumber tests')
},
async afterStep () {
await browser.takeScreenshot().then((val) => {
cucumberJSON.default.attach(val, 'image/png')
}).catch((err) => {
console.log('Error in capturing screenshots', err)
})
},
onComplete () {
multipleCucumberHtmlReporter.generate({
openReportInBrowser: true,
reportName: 'Project Report',
screenshotPath: './reports/screenshots/',
displayDuration: true,
saveCollectedJSON: false,
jsonDir: '.tmp/json/',
reportPath: './reports/',
customData: {
title: 'Project Data',
data: [
{ label: 'Project', value: 'Project Value'},
{ label: 'Release', value: '1.0' },
{ label: 'Execution Start Date', value: moment().format('dddd, MMMM Do YYYY') }
]
}
})
}
}
任何人都可以帮忙。我尝试了很多方法,但结果总是一样。也许我在这里做错了什么。请指导。
我想我明白了,为什么它不起作用。我已按照以下步骤解决。希望它能帮助面临同样问题的人。
- 已执行
npx wdio config
- 已回答必填问题
- 在安装服务的时候,我选择了
chromdriver
而不是selenium-standalone
- 安装了所有必需的软件包,其中包括 - (猜猜你也可以单独安装这些,我只是选择了这条路线来执行)
chromedriver
wdio-chromedriver-service
- 用新配置替换了我的旧配置,它又开始工作了。它甚至以最大化模式启动浏览器。
运行-
的结果Starting cucumber tests
Starting ChromeDriver 84.0.4147.30 (48b3e868b4cc0aa7e8149519690b6f6949e110a8-refs/branch-heads/4147@{#310}) on port 9515
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
我真的不知道为什么它会表现得如此奇怪,因为 Selenium-standalone 确实包含 chromeDriver。如果有人知道这个问题的答案,请补充,会很好学习!