问题描述
由于某种原因,我无法开始使用 WebdriverIO 和 Mocha + Chai 测试框架编写的测试。当我运行 yarn start 命令来启动它们时,每次测试都会得到这样的输出:
Execution of 31 spec files started at 2021-07-22T13:36:42.326Z
[0-0] RUNNING in chrome - C:\Users\ADOMAS-PC\Desktop\Automation Projects\driveweb\test\e2e\specs\e2e\cancelDownload.spec.js
[0-0] Error: Failed to create session.
Unable to create session from {
"desiredCapabilities": {
"browserName": "chrome","goog:chromeOptions": {
"binary": "C:\u002f\u002fProgram Files\u002f\u002fGoogle\u002f\u002fChrome\u002f\u002fApplication\u002f\u002fchrome.exe","prefs": {
"directory_upgrade": true,"prompt_for_download": false,"download.default_directory": "C:\\Users\\ADOMAS-PC\\Desktop\\Automation Projects\\driveweb\\test\\data\\downloads","download.prompt_for_download": false,"profile.default_content_setting_values.automatic_downloads": 1
},"args": [
"--headless","--no-sandBox","--incognito","--disable-gpu","--window-size=1600,1000"
]
}
},"capabilities": {
"firstMatch": [
{
"browserName": "chrome","goog:chromeOptions": {
"binary": "C:\u002f\u002fProgram Files\u002f\u002fGoogle\u002f\u002fChrome\u002f\u002fApplication\u002f\u002fchrome.exe","prefs": {
"directory_upgrade": true,"profile.default_content_setting_values.automatic_downloads": 1
},"args": [
"--headless",1000"
]
}
}
]
}
}
Build info: version: '3.141.5',revision: 'd54ebd709a',time: '2018-11-06T11:58:47'
System info: host: 'DESKTOP-AK6OAUH',ip: '10.18.0.3',os.name: 'Windows 10',os.arch: 'amd64',os.version: '10.0',java.version: '16.0.1'
Driver info: driver.version: unkNown
这就是 wdio.webapp.conf.js 的样子:
const { createDir,removeDirContents } = require('./test/e2e/helpers/folderHelper');
const { populateData } = require('./test/e2e/helpers/apiHelper');
const { Timelineservice } = require('wdio-timeline-reporter/timeline-service');
var mkdirp = require('mkdirp');
const path = require('path');
global.downloadDir = path.join(process.cwd(),'test/data/downloads');
global.uploadDir = path.join(process.cwd(),'test/data/uploads');
global.uploadPermDir = path.join(process.cwd(),'test/data/uploadsPerm');
global.baseUrl = 'https://drive.automation.com/';
exports.config = {
hostname: 'automation-selenium',port: 4444,path: '/wd/hub',specs: [
'./test/e2e/specs/e2e/**/*.spec.js','./test/e2e/specs/pages/*.spec.js'
],maxInstances: 1,capabilities: [
{
maxInstances: 1,browserName: 'chrome','goog:chromeOptions': {
binary: "C://Program Files//Google//Chrome//Application//chrome.exe",prefs: {
directory_upgrade: true,prompt_for_download: false,'download.default_directory': global.downloadDir,'download.prompt_for_download': false,'profile.default_content_setting_values.automatic_downloads': 1
},args: [
'--headless','--no-sandBox','--incognito','--disable-gpu','--window-size=1600,1000']
}
}
],logLevel: 'debug',outputDir: './reports/output',bail: 0,baseUrl: global.baseUrl,waitforTimeout: 50000,connectionRetryTimeout: 60000,connectionRetryCount: 3,framework: 'mocha',mochaOpts: {
ui: 'bdd',compilers: ['js:@babel/register'],timeout: 60000,retries: 1
},reporters: [
'spec',[
'allure',{
outputDir: './reports/allure-results/',disableWebdriverStepsReporting: true,disableWebdriverScreenshotsReporting: false
}
]
],onPrepare: async function(config,capabilities) {
global.baseUrl = config.baseUrl;
createDir(global.downloadDir);
createDir(global.uploadDir);
if (!global.baseUrl.includes('automation.com')) {
await populateData(config.baseUrl);
}
},afterTest: async function (test,context,{ error,result,duration,passed,retries }) {
if (!passed) {
const current_datetime = new Date();
const time = current_datetime.getHours() + "h-" + current_datetime.getMinutes() + "m-" + current_datetime.getSeconds() + "s";
const screenshotDir = path.join(process.cwd(),`screenshots`);
await mkdirp(screenshotDir);
const filename = test.title.replace(/\s+/g,'-');
const screenshotImg = `${screenshotDir}/${time}-${filename}.png`;
browser.saveScreenshot(screenshotImg);
}
},onComplete: function() {
removeDirContents(global.downloadDir);
removeDirContents(global.uploadDir);
}
};
我已经尝试过什么?
- 在我的电脑上重新安装 Chrome 浏览器。
- 安装/重新安装各种库,如 wdio、selenium-standalone 等。
- 使用管理员模式从 CMD 运行测试。
- 将二进制值设置为 C://Program Files//Google//Chrome//Application//chromedriver.exe
- 将节点降级到 12.8.1 版本
我还能尝试什么来使它们工作?
解决方法
yarn add @wdio/selenium-standalone-service
解决了这个问题。