Light 報告器
靈感來自 HTML 和 Mochawesome 報告器
!哲學
此報告器不支援 cucumber 報告重新產生,開發時考慮了 bdd 和 mocha 框架。在此,
describe()
區段被視為測試情境,而it()
則為測試情境內的測試案例。
功能
- 簡易設定
- 強化 UI
- 螢幕截圖嵌入 HTML 報告
- addLabel() 加入步驟情境或名稱
發布版本
V 0.1.9 - 初版發布 V 0.2.6 - (最新)
- 包含多個環境執行,並根據環境區隔。
- 修正錯誤
- 效能提升。
範例
安裝
NPM
npm install wdio-light-reporter --save-dev
設定
reporters: ['dot', ['light',{
outputDir: './Results',
outputFile:`demo${new Date()}`, // html report file will be name this
addScreenshots: false, // to add screenshots in report make it as true. Default is false
}]
],
螢幕截圖
此報告器沒有自動設定螢幕截圖的功能,但如果手動設定,它會監聽事件並將螢幕截圖附加到 HTML 報告中。若要在報告中加入螢幕截圖,請在 wdio conf 檔案的 afterTest() 掛勾中加入以下程式碼。
afterTest: async function (test,context,{ error, result, duration, passed, retries }) {
if (!passed) {await browser.takeScreenshot()}
},
結果檔案
每次執行都會為每個規格檔案重新產生 JSON 報告,若要產生合併的 JSON 和 HTML 報告,請在 wdio conf 檔案的 onComplete() 掛勾中加入以下程式碼
onComplete: function (exitCode, config, capabilities, results) {
const mergeResults = require("wdio-light-reporter/src/mergeResults"); //you can add this on top of the file
mergeResults("./Results");
},
如果執行測試時沒有任何 --suite 選項,則會將預設值視為套件,如果執行時給予多個參數作為套件,則報告器無法運作。wdio run
wdio.conf.js --suite firstSuite
- (運作正常):)
wdio runwdio.conf.js --suite firstSuite --suite secondSuite
(無法運作):(
加入情境
您可以使用
useLabel()
將情境加入任何步驟,或加入作為步驟。
const { addLabel } = require("wdio-light-reporter").default;
describe("Show how to use addLabel ", () => {
it("report will added this a steps/context in report", async () => {
addLabel("Log Example 1 as step 1")
console.log("Log Example 1 )
addLabel("Log Example 2 as step 2")
console.log("Log Example 2 )
})
})
更新
reporters: ['dot', ['light',{
outputDir: './Results',
outputFile:"demo", // html report file will be name this
addScreenshots: false, // to add screenshots in report make it as true. Default is false
//autoClean:false // removed autoClean and include the same functionality as default in mergeResult function
}]
],
授權條款
MIT 免費,太棒了!