Skip to content

Commit 16095f6

Browse files
author
John Doherty
committed
added junit report output
1 parent 244842a commit 16095f6

File tree

5 files changed

+72
-11
lines changed

5 files changed

+72
-11
lines changed

README.MD

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ node ./node_modules/selenium-cucumber-js/index.js -s ./step-definitions
2525
-o, --sharedObjects [paths] path to shared objects (repeatable). defaults to ./shared-objects
2626
-b, --browser <path> name of browser to use. defaults to chrome
2727
-r, --reports <path> output path to save reports. defaults to ./reports
28+
-j, --junit <path> output path to save junit-report.xml defaults to ./reports
2829
-t, --tags <tagName> name of tag to run
2930
-f, --featureFile <path> a specific feature file to run
3031
```

index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ program
1818
.option('-o, --sharedObjects [paths]', 'path to shared objects (repeatable). defaults to ./shared-objects', collectPaths, ['./shared-objects'])
1919
.option('-b, --browser <path>', 'name of browser to use. defaults to chrome', /^(chrome|firefox|phantomjs)$/i, 'chrome')
2020
.option('-r, --reports <path>', 'output path to save reports. defaults to ./reports', './reports')
21+
.option('-j, --junit <path>', 'output path to save junit-report.xml defaults to ./reports', './reports')
2122
.option('-t, --tags <tagName>', 'name of tag to run')
2223
.option('-f, --featureFile <path>', 'a specific feature file to run')
2324
.parse(process.argv);
@@ -35,6 +36,9 @@ global.pageObjectPath = path.resolve(program.pageObjects);
3536
// used within world.js to output reports
3637
global.reportsPath = path.resolve(program.reports);
3738

39+
// used within world.js to output junit reports
40+
global.junitPath = path.resolve(program.junit || program.reports);
41+
3842
// used within world.js to import shared objects into the shared namespace
3943
global.sharedObjectPaths = program.sharedObjects.map(function(item){
4044
return path.resolve(item);
@@ -43,7 +47,7 @@ global.sharedObjectPaths = program.sharedObjects.map(function(item){
4347
// rewrite command line switches for cucumber
4448
process.argv.splice(2, 100);
4549

46-
// allow a specific feature file to be excuted
50+
// allow a specific feature file to be executed
4751
if (program.featureFile) {
4852
process.argv.push(program.featureFile);
4953
}

junit/junit-report.xml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<testsuites>
3+
<testsuite name="shop-for-workwear;view-product-detail" tests="4" failures="0" skipped="0">
4+
<properties>
5+
<property name="@workwear" value="true">
6+
</property>
7+
<property name="URI" value="/Users/JD/Projects/selenium-cucumber-js/features/buy-workwear.feature">
8+
</property>
9+
</properties>
10+
<testcase name="Given I am on the Mammoth Workwear home page" classname="shop-for-workwear;view-product-detail" time="2.167256987">
11+
</testcase>
12+
<testcase name="When I click navigation item &quot;Safety Boots&quot;" classname="shop-for-workwear;view-product-detail" time="0.906699449">
13+
</testcase>
14+
<testcase name="And I click product item &quot;Timberland Pro Euro Hiker 2G Safety Boots&quot;" classname="shop-for-workwear;view-product-detail" time="0.164338598">
15+
</testcase>
16+
<testcase name="Then I should see product detail with title &quot;Timberland Pro Euro Hiker 2G Safety Boots&quot;" classname="shop-for-workwear;view-product-detail" time="0.006059345">
17+
</testcase>
18+
</testsuite>
19+
<testsuite name="searching-for-vote-cards-app;google-search-for-vote-cards-app" tests="2" failures="0" skipped="0">
20+
<properties>
21+
<property name="@search" value="true">
22+
</property>
23+
<property name="URI" value="/Users/JD/Projects/selenium-cucumber-js/features/google-search.feature">
24+
</property>
25+
</properties>
26+
<testcase name="When I search Google for &quot;itunes vote cards app&quot;" classname="searching-for-vote-cards-app;google-search-for-vote-cards-app" time="1.990874784">
27+
</testcase>
28+
<testcase name="Then I should see some results" classname="searching-for-vote-cards-app;google-search-for-vote-cards-app" time="0.67219732">
29+
</testcase>
30+
</testsuite>
31+
<testsuite name="searching-for-vote-cards-app;google-search-for-course-of-life-app" tests="2" failures="0" skipped="0">
32+
<properties>
33+
<property name="@search" value="true">
34+
</property>
35+
<property name="URI" value="/Users/JD/Projects/selenium-cucumber-js/features/google-search.feature">
36+
</property>
37+
</properties>
38+
<testcase name="When I search Google for &quot;CourseOf.Life&quot;" classname="searching-for-vote-cards-app;google-search-for-course-of-life-app" time="2.617391326">
39+
</testcase>
40+
<testcase name="Then I should see some results" classname="searching-for-vote-cards-app;google-search-for-course-of-life-app" time="0.541283478">
41+
</testcase>
42+
</testsuite>
43+
</testsuites>

package.json

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
22
"name": "selenium-cucumber-js",
3-
"version": "1.3.2",
3+
"version": "1.3.3",
44
"description": "A debuggable JS BDD framework that uses the official selenium-webdriver for Node and cucumber-js",
55
"main": "index.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1"
88
},
9-
"author": {
10-
"name" : "John Doherty",
11-
"email" : "[email protected]",
12-
"url" : "https://courseof.life/johndoherty"
9+
"author": {
10+
"name": "John Doherty",
11+
"email": "[email protected]",
12+
"url": "https://courseof.life/johndoherty"
1313
},
1414
"license": "ISC",
1515
"keywords": [
@@ -22,6 +22,7 @@
2222
"chromedriver",
2323
"phantomjs",
2424
"testing",
25+
"junit",
2526
"bdd"
2627
],
2728
"repository": {
@@ -42,6 +43,7 @@
4243
"commander": "^2.9.0",
4344
"cucumber": "^1.2.2",
4445
"cucumber-html-reporter": "^0.2.8",
46+
"cucumber-junit": "^1.6.0",
4547
"fs-plus": "^2.9.1",
4648
"geckodriver": "^1.1.2",
4749
"merge": "^1.2.0",

runtime/world.js

+16-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
/**
4-
* world.js is loaded by the cucumber framework before loading the step definations and feature files
4+
* world.js is loaded by the cucumber framework before loading the step definitions and feature files
55
* it is responsible for setting up and exposing the driver/browser/expect/assert etc required within each step definition
66
*/
77

@@ -16,7 +16,8 @@ var fs = require('fs-plus'),
1616
firefox = require('geckodriver'),
1717
expect = require('chai').expect,
1818
assert = require("chai").assert,
19-
reporter = require('cucumber-html-reporter');
19+
reporter = require('cucumber-html-reporter'),
20+
cucumberJunit = require('cucumber-junit');
2021

2122
global.DEFAULT_TIMEOUT = 10 * 1000; // 10 second default
2223

@@ -93,7 +94,7 @@ function World() {
9394
// expose properties to step definition methods via global variables
9495
Object.keys(runtime).forEach(function (key) {
9596

96-
// make property/method avaiable as a global (no this. prefix required)
97+
// make property/method available as a global (no this. prefix required)
9798
global[key] = runtime[key];
9899
});
99100

@@ -135,7 +136,7 @@ function World() {
135136
global.helpers = require('../runtime/helpers.js');
136137
}
137138

138-
// export the "World" required by cucubmer to allow it to expose methods within step def's
139+
// export the "World" required by cucumber to allow it to expose methods within step def's
139140
module.exports = function () {
140141

141142
this.World = World;
@@ -155,18 +156,28 @@ module.exports = function () {
155156

156157
this.registerHandler('AfterFeatures', function (features, done) {
157158

159+
var cucumberReportPath = path.resolve(global.reportsPath, 'cucumber-report.json');
160+
158161
if (global.reportsPath && fs.existsSync(global.reportsPath)) {
159162

163+
// generate the HTML report
160164
var reportOptions = {
161165
theme: 'bootstrap',
162-
jsonFile: path.resolve(global.reportsPath, 'cucumber-report.json'),
166+
jsonFile: cucumberReportPath,
163167
output: path.resolve(global.reportsPath, 'cucumber-report.html'),
164168
reportSuiteAsScenarios: true,
165169
launchReport: true,
166170
ignoreBadJsonFile: true
167171
};
168172

169173
reporter.generate(reportOptions);
174+
175+
// grab the file data
176+
var reportRaw = fs.readFileSync(cucumberReportPath).toString().trim();
177+
var xmlReport = cucumberJunit(reportRaw);
178+
var junitOutputPath = path.resolve(global.junitPath, 'junit-report.xml');
179+
180+
fs.writeFileSync(junitOutputPath, xmlReport)
170181
}
171182

172183
done();

0 commit comments

Comments
 (0)