[英]webdriverio 5 for unit testing and functional testing
我有一个使用node和webpack编写的项目。
我正在为应用程序编写测试,并且由于应用程序的输出是可视化效果,因此我使用了webdriverio 5,并且运行良好(功能测试)。 但是,当我添加单元测试时,它只是失败了,尽管在测试报告器中它表明它是错误的,日志告诉它失败了。
这是我的package.json文件的样子
{
"name": "webdriverio-test",
"version": "1.0.0",
"description": "",
"main": "app/index.js",
"scripts": {
"install-selenium": "./node_modules/.bin/selenium-standalone install",
"start-selenium": "./node_modules/.bin/selenium-standalone start",
"test": "./node_modules/.bin/wdio wdio.conf.js",
"allure-report": "allure generate allure-results --clean && allure open"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@wdio/allure-reporter": "^5.12.1",
"@wdio/cli": "^5.12.5",
"@wdio/local-runner": "^5.12.5",
"@wdio/mocha-framework": "^5.12.1",
"@wdio/selenium-standalone-service": "^5.12.1",
"@wdio/sync": "^5.12.3"
}
}
这是我的测试文件的样子
const assert = require('assert');
const index = require('../../app/index').default
describe('test browser', function () {
it('should have the right title', function () {
browser.url('https://webdriver.io');
const title = browser.getTitle();
//assert.strictEqual(title, 'WebdriverIO · Next-gen WebDriver test framework for Node.js');
console.log("**********I am here*************");
assert.equal(5,5);
});
});
describe('test code', function () {
it('should have do the right thing', function () {
const c = index.add(3,4);
assert.equal(c, 7);
});
});
当我使用webdriverio命令运行此代码时,得到以下堆栈跟踪
> webdriverio-test@1.0.0 test /Users/adsf/Desktop/test_scripts/webdriverio-test
> wdio wdio.conf.js
Execution of 1 spec files started at 2019-09-06T15:21:35.952Z
2019-09-06T15:21:35.979Z INFO @wdio/cli:Launcher: Run onPrepare hook
2019-09-06T15:21:36.093Z ERROR @wdio/cli:utils: A service failed in the 'onPrepare' hook
Error: Could not request headers from https://chromedriver.storage.googleapis.com/2.43/chromedriver_mac64.zip: Error: read ECONNRESET
at Request.<anonymous> (/Users/adsf/Desktop/test_scripts/webdriverio-test/node_modules/selenium-standalone/lib/install.js:552:8)
at Object.onceWrapper (events.js:286:20)
at Request.emit (events.js:198:13)
at Request.EventEmitter.emit (domain.js:448:20)
at Request.onRequestError (/Users/adsf/Desktop/test_scripts/webdriverio-test/node_modules/request/request.js:881:8)
at ClientRequest.emit (events.js:198:13)
at ClientRequest.EventEmitter.emit (domain.js:448:20)
at TLSSocket.socketErrorListener (_http_client.js:392:9)
at TLSSocket.emit (events.js:198:13)
at TLSSocket.EventEmitter.emit (domain.js:448:20)
Continue...
2019-09-06T15:21:36.096Z INFO @wdio/local-runner: Start worker 0-0 with arg: wdio.conf.js
[0-0] RUNNING in chrome - /test/specs/basic.js
[0-0] 2019-09-06T15:21:36.381Z INFO @wdio/local-runner: Run worker command: run
[0-0] 2019-09-06T15:21:36.434Z INFO webdriver: [POST] http://127.0.0.1:4444/wd/hub/session
[0-0] 2019-09-06T15:21:36.434Z INFO webdriver: DATA { capabilities:
{ alwaysMatch: { browserName: 'chrome' }, firstMatch: [ {} ] },
desiredCapabilities: { browserName: 'chrome' } }
[0-0] 2019-09-06T15:21:37.385Z INFO webdriver: COMMAND navigateTo("https://webdriver.io/")
[0-0] 2019-09-06T15:21:37.386Z INFO webdriver: [POST] http://127.0.0.1:4444/wd/hub/session/3e34d38c50817313e3bab65cf8af5e51/url
[0-0] 2019-09-06T15:21:37.386Z INFO webdriver: DATA { url: 'https://webdriver.io/' }
[0-0] 2019-09-06T15:21:38.901Z INFO webdriver: COMMAND getTitle()
[0-0] 2019-09-06T15:21:38.901Z INFO webdriver: [GET] http://127.0.0.1:4444/wd/hub/session/3e34d38c50817313e3bab65cf8af5e51/title
[0-0] 2019-09-06T15:21:38.908Z INFO webdriver: RESULT WebdriverIO · Next-gen WebDriver test framework for Node.js
[0-0] **********I am here*************
[0-0] FAILED in chrome - /test/specs/basic.js
2019-09-06T15:21:39.335Z INFO @wdio/cli:Launcher: Run onComplete hook
Spec Files: 0 passed, 1 failed, 1 total (100% completed) in 00:00:03
2019-09-06T15:21:39.336Z INFO @wdio/local-runner: Shutting down spawned worker
2019-09-06T15:21:39.590Z INFO @wdio/local-runner: Waiting for 0 to shut down gracefully
2019-09-06T15:21:39.590Z INFO @wdio/local-runner: shutting down
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! webdriverio-test@1.0.0 test: `wdio wdio.conf.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the webdriverio-test@1.0.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
我的问题是我可以使用wdio运行单元测试和功能测试,还是使用mocha和wdio运行这些测试对我来说是一个好主意?
当我只运行浏览器测试时,所有浏览器测试都可以正常工作
我相信在一个文件中运行不同类型的测试不是一个好主意(因为只有第一个描述将起作用-对于您的示例),日志将根据wdio设置写入。我在不同的文件中运行了您的示例并且可以正常工作-2通过最好将UI测试移动到具有Wdio的package.json设置的同一文件夹中,并将带有Mocha的单元测试移动到另一个单独的文件夹中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.