简体   繁体   中英

webdriverio 5 for unit testing and functional testing

I have a project that is written using node and webpack.

I am writing tests for the application and as the output of my application is a visualization, I went with webdriverio 5 and it is running great(functional testing). However when I add unit tests, it is just failing although in the test reporter it shows that it is false, the logs tell that it FAILED.

Here is how my package.json file looks like

{
  "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"
     }
    }

Here is how my test file looks like

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); 
    }); 
}); 

When I run this code using webdriverio command I get the following stack trace

> 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:

My question is can I run unit tests and functional tests with wdio or will it be a good idea for me to use mocha and wdio to run these tests?

When I just run browser tests, all the browser tests work great

我相信在一个文件中运行不同类型的测试不是一个好主意(因为只有第一个描述将起作用-对于您的示例),日志将根据wdio设置写入。我在不同的文件中运行了您的示例并且可以正常工作-2通过最好将UI测试移动到具有Wdio的package.json设置的同一文件夹中,并将带有Mocha的单元测试移动到另一个单独的文件夹中。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM