जूनिट रिपोर्टर
एक WebdriverIO रिपोर्टर जो Jenkins के अनुकूल XML आधारित JUnit रिपोर्ट बनाता है
इंस्टालेशन
सबसे आसान तरीका है अपने package.json में @wdio/junit-reporter को devDependency के रूप में रखना, इस प्रकार:
npm install @wdio/junit-reporter --save-dev
WebdriverIO कैसे इंस्टॉल करें, इस पर निर्देश यहां मिल सकते हैं।
आउटपुट
यह रिपोर्टर प्रत्येक रनर के लिए एक रिपोर्ट आउटपुट करेगा, इसलिए आप प्रत्येक स्पेक फ़ाइल के लिए एक xml रिपोर् ट प्राप्त करेंगे। नीचे स्पेक फ़ाइल में विभिन्न परिदृश्यों को दिए गए XML आउटपुट के उदाहरण हैं।
सिंगल डिस्क्राइब ब्लॉक
describe('a test suite', () => {
it('a test case', function () {
// do something
// assert something
});
});
बन जाता है
<testsuites>
<testsuite name="a test suite" timestamp="2019-04-18T13:45:21" time="11.735" tests="0" failures="0" errors="0" skipped="0">
<properties>
<property name="specId" value="0"/>
<property name="suiteName" value="a test suite"/>
<property name="capabilities" value="chrome"/>
<property name="file" value=".\test\specs\asuite.spec.js"/>
</properties>
<testcase classname="chrome.a_test_case" name="a_test_suite_a_test_case" time="11.706"/>
</testsuite>
</testsuites>
नेस्टेड डिस्क्राइब ब्लॉक
describe('a test suite', () => {
describe('a nested test suite', function() {
it('a test case', function () {
// do something
// assert something
});
});
});
बन जाता है
<testsuites>
<testsuite name="a test suite" timestamp="2019-04-18T13:45:21" time="11.735" tests="0" failures="0" errors="0" skipped="0">
<properties>
<property name="specId" value="0"/>
<property name="suiteName" value="a test suite"/>
<property name="capabilities" value="chrome"/>
<property name="file" value=".\test\specs\asuite.spec.js"/>
</properties>
</testsuite>
<testsuite name="a nested test suite" timestamp="2019-04-18T13:45:21" time="11.735" tests="0" failures="0" errors="0" skipped="0">
<properties>
<property name="specId" value="0"/>
<property name="suiteName" value="a nested test suite"/>
<property name="capabilities" value="chrome"/>
<property name="file" value=".\test\specs\asuite.spec.js"/>
</properties>
<testcase classname="chrome.a_test_case" name="a nested test suite a test case" time="11.706"/>
</testsuite>
</testsuites>
मल्टीपल डिस्क्राइब ब्लॉक
describe('a test suite', () => {
it('a test case', function () {
// do something
// assert something
});
});
describe('a second test suite', () => {
it('a second test case', function () {
// do something
// assert something
});
});
बन जाता है
<testsuites>
<testsuite name="a test suite" timestamp="2019-04-18T13:45:21" time="11.735" tests="0" failures="0" errors="0" skipped="0">
<properties>
<property name="specId" value="0"/>
<property name="suiteName" value="a test suite"/>
<property name="capabilities" value="chrome"/>
<property name="file" value=".\test\specs\asuite.spec.js"/>
<testcase classname="chrome.a_test_case" name="a nested test suite a test case" time="11.706"/>
</properties>
</testsuite>
<testsuite name="a second test suite" timestamp="2019-04-18T13:45:21" time="11.735" tests="0" failures="0" errors="0" skipped="0">
<properties>
<property name="specId" value="0"/>
<property name="suiteName" value="a second test suite"/>
<property name="capabilities" value="chrome"/>
<property name="file" value=".\test\specs\asuite.spec.js"/>
</properties>
<testcase classname="chrome.a_second_test_case" name="a_second_test_suite_a_second_test_case" time="11.706"/>
</testsuite>
</testsuites>
असफलताएं और त्रुटियां
सभी टेस्ट केस की असफलताओं को JUnit टेस्ट केस त्रुटियों के रूप में मैप किया जाता है। एक विफल परीक्षण केस ऐसा दिखेगा:
<testcase classname="chrome.a_test_case" name="a_test_suite_a_test_case" time="0.372">
<failure message="Error: some error"/>
<system-err>
<![CDATA[
Error: some assertion failure
at UserContext.<anonymous> (C:\repo\webdriver-example\test\specs/a_test_suite.spec.js:22:17)
]]>
</system-err>
</testcase>
कॉन्फिगरेशन
निम्नलिखित कोड डिफ़ॉल्ट wdio टेस्ट रनर कॉन्फिगरेशन दिखाता है। बस एरे में रिपोर्टर के रूप में 'junit' जोड़ें। परीक्षण के दौरान कुछ आउटपुट प्राप्त करने के लिए आप WDIO Dot Reporter और WDIO JUnit Reporter को एक साथ चला सकते हैं:
// wdio.conf.js
module.exports = {
// ...
reporters: [
'dot',
['junit', {
outputDir: './',
outputFileFormat: function(options) { // optional
return `results-${options.cid}.${options.capabilities}.xml`
}
}]
],
// ...
};
निम्नलिखित विकल्प समर्थित हैं:
outputDir
एक डायरेक्टरी परिभाषित करें जहां आपकी xml फ़ाइलें स्टोर की जानी चाहिए।
प्रकार: String
आवश्यक