Skip to content

Commit ec9d774

Browse files
authored
Merge pull request #1 from browserstack/develop
Initial release
2 parents 87a907e + c0a6239 commit ec9d774

File tree

7 files changed

+212
-1
lines changed

7 files changed

+212
-1
lines changed

.gitignore

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

README.md

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,55 @@
1-
# protractor-browserstack-reporter
1+
# protractor-browserstack-reporter
2+
3+
A Protractor plugin which enables BrowserStack reports on CI servers
4+
5+
![Browserstack reports on Jenkins](screenshots/jenkins_report.png)
6+
7+
## Installation
8+
9+
Add `protractor-browserstack-reporter` as a dependency in your `package.json`.
10+
11+
```json
12+
{
13+
"dependencies": {
14+
"protractor-browserstack-reporter": "~0.1.0"
15+
}
16+
}
17+
```
18+
19+
## Configuration
20+
21+
Add `browserstack` as a plugin in your conf file.
22+
23+
```js
24+
// conf.js
25+
'plugins': [{
26+
'package': "browserstack-protractor-reporter"
27+
}]
28+
```
29+
30+
The following options are supported(optional):
31+
32+
### outputDir
33+
Define a directory where your browserstack report files should get stored.
34+
35+
Type: `String`<br>
36+
37+
## Jenkins Setup
38+
39+
You will have to configure your Jenkins CI server to embed all the BrowserStack Selenium reports and logs in Jenkins.
40+
1. Click on Add post-build action in Post-build Actions.
41+
2. Click on Publish JUnit test result report
42+
3. In the Test report XMLs, enter */*browserstack-reports/REPORT-\*.xml
43+
4. In the Additional test report features section, add Embed BrowserStack Report.
44+
45+
This is how your configuration should look like
46+
![Jenkins Setup](screenshots/jenkins_setup.png)
47+
48+
## Related links
49+
50+
[Guide to running Selenium Webdriver tests with Protractor on BrowserStack](https://www.browserstack.com/automate/protractor)
51+
52+
[Browserstack Jenkins page](https://www.browserstack.com/automate/jenkins)
53+
54+
[Protractor](https://www.protractortest.org).
55+

index.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
var path = require('path'),
2+
fs = require('fs'),
3+
mkdirp = require('mkdirp');
4+
5+
var suites = {};
6+
var specs = {};
7+
var myReporter = {
8+
9+
suiteStarted: function(suite){
10+
currentSuite = suite;
11+
currentSuite.specs = []
12+
},
13+
14+
suiteDone: function(suite) {
15+
suites[suite.id] = suite
16+
},
17+
18+
jasmineDone: function(){
19+
this.onSingleFileOutput(suites)
20+
},
21+
22+
specDone: function(spec) {
23+
browser.getSession().then(function(session) {
24+
spec.sessionID = session.getId();
25+
currentSuite.specs.push(spec)
26+
specs[spec.id] = spec
27+
});
28+
},
29+
30+
onSingleFileOutput: function (suites) {
31+
const xml = this.prepareXml(suites)
32+
let filename = `REPORT-browserstack.all.xml`
33+
this.write(filename, xml)
34+
},
35+
36+
prepareName: function(name = 'Skipped test') {
37+
return name.split(/[^a-zA-Z0-9]+/).filter(
38+
(item) => item && item.length
39+
).join('_')
40+
},
41+
42+
prepareXml: function(suites){
43+
var xmlbuilder = require('xmlbuilder');
44+
const builder = xmlbuilder.create('testsuites', {encoding: 'UTF-8', allowSurrogateChars: true})
45+
for (let suiteIndex in suites) {
46+
const suite = suites[suiteIndex]
47+
const suiteName = this.prepareName(suite.description)
48+
const testSuite = builder.ele("testsuite", {name: suiteName})
49+
for (let specIndex in suite.specs) {
50+
const test = suite.specs[specIndex]
51+
const testName = this.prepareName(test.description)
52+
const testCase = testSuite.ele("testcase",{name: testName, id: `${suiteName}.${testName}{0}`, index: 0 });
53+
testCase.ele("session", {}, test.sessionID);
54+
}
55+
}
56+
return builder.end({ pretty: true});
57+
},
58+
59+
write: function(filename, xml) {
60+
var outputDir = "./browserstack-reports"
61+
try {
62+
const dir = path.resolve(outputDir)
63+
const filepath = path.join(dir, filename)
64+
mkdirp.sync(dir)
65+
fs.writeFileSync(filepath, xml)
66+
console.log(`Wrote xunit report "${filename}" to [${outputDir}].`)
67+
} catch (e) {
68+
console.log(`Failed to write xunit report "${filename}"
69+
to [${outputDir}]. Error: ${e}`)
70+
}
71+
},
72+
73+
format: function(val) {
74+
return JSON.stringify(baseReporter.limit(val))
75+
}
76+
}
77+
78+
var BrowserStackReporter = {
79+
name: "browserstack-protractor-plugin",
80+
81+
onPrepare: function() {
82+
jasmine.getEnv().addReporter(myReporter);
83+
},
84+
}
85+
86+
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": "0.1.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+
}

screenshots/jenkins_report.png

702 KB
Loading

screenshots/jenkins_setup.png

163 KB
Loading

0 commit comments

Comments
 (0)