Skip to content

Commit 77f452d

Browse files
committed
init
0 parents  commit 77f452d

File tree

4 files changed

+132
-0
lines changed

4 files changed

+132
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

index.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
var path = require('path'),
2+
fs = require('fs'),
3+
mkdirp = require('mkdirp');
4+
var BrowserStackReporter = {
5+
name: "browserstack-protractor-plugin",
6+
7+
teardown: function(){
8+
9+
function onSingleFileOutput (sessionID) {
10+
const xml = prepareXml(sessionID)
11+
let filename = `WDIO.xunit.all.xml` // default
12+
write(filename, xml)
13+
}
14+
15+
function prepareName(name = 'Skipped test') {
16+
return name.split(/[^a-zA-Z0-9]+/).filter(
17+
(item) => item && item.length
18+
).join('_')
19+
}
20+
21+
function prepareXml(sessionID){
22+
var xmlbuilder = require('xmlbuilder');
23+
const builder = xmlbuilder.create('testsuites', {encoding: 'UTF-8', allowSurrogateChars: true})
24+
const packageName = "packageName"
25+
// TODO suitname
26+
const suiteName = prepareName("suitetitle")
27+
const testSuite = builder.ele("testsuite", {name: suiteName})
28+
// TODO testname
29+
const testName = prepareName("testname")
30+
const testCase = testSuite.ele("testcase",{className: `${packageName}.${suiteName}`, name: testName });
31+
testCase.ele("session", {}, sessionID);
32+
return builder.end({ pretty: true});
33+
}
34+
35+
function write(filename, xml) {
36+
var outputDir = "target/browserstack-reports"
37+
try {
38+
const dir = path.resolve(outputDir)
39+
const filepath = path.join(dir, filename)
40+
mkdirp.sync(dir)
41+
fs.writeFileSync(filepath, xml)
42+
console.log(`Wrote xunit report "${filename}" to [${outputDir}].`)
43+
} catch (e) {
44+
console.log(`Failed to write xunit report "${filename}"
45+
to [${outputDir}]. Error: ${e}`)
46+
}
47+
}
48+
49+
function format (val) {
50+
return JSON.stringify(baseReporter.limit(val))
51+
}
52+
53+
console.log("wowowow teardown")
54+
browser.getSession().then(function(session) {
55+
onSingleFileOutput(session.getId())
56+
});
57+
}
58+
59+
}
60+
61+
module.exports = BrowserStackReporter

package-lock.json

Lines changed: 47 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "browserstack-protractor-reporter",
3+
"version": "1.0.0",
4+
"description": "A Protractor plugin which enables BrowserStack reports on CI",
5+
"main": "index.js",
6+
"keywords": [
7+
"protractor",
8+
"browserstack",
9+
"ci",
10+
"selenium",
11+
"report"
12+
],
13+
"repository": {
14+
"type": "git",
15+
"url": "git+https://github.com/browserstack/browserstack-protractor-reporter.git"
16+
},
17+
"author": "BrowserStack",
18+
"license": "ISC",
19+
"dependencies": {
20+
"junit-report-builder": "^1.3.1",
21+
"xmlbuilder": "^10.0.0"
22+
}
23+
}

0 commit comments

Comments
 (0)