簡體   English   中英

webdriverio 5用於單元測試和功能測試

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM