Skip to content

Commit 039564b

Browse files
authored
Merge pull request #165 from browserstack/module
feature(module): Use browserstack-runner as module as well as cli
2 parents f780784 + c86c561 commit 039564b

20 files changed

+718
-365
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ node_modules
33
browserstack.json
44
browserstack-runner.pid
55
lib/BrowserStackLocal
6+
tests/jasmine
7+
tests/jasmine2
8+
tests/mocha
9+
tests/qunit

README.md

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# BrowserStack Runner
2+
3+
[![Build Status](https://travis-ci.org/browserstack/browserstack-runner.svg?branch=master)](https://travis-ci.org/browserstack/browserstack-runner)
4+
15
A command line interface to run browser tests over BrowserStack.
26

37
## Usage
@@ -21,6 +25,137 @@ If you're getting an error `EACCES open ... BrowserStackLocal`, configure npm to
2125

2226
Where `[user]` is replaced with a local user with enough permissions.
2327

28+
## Usage as a module
29+
30+
`browserstack-runner` can also be used as a module. To run your tests, inside your project do -
31+
32+
```node
33+
var browserstackRunner = require('browserstack-runner');
34+
35+
var config = require('./browserstack.json');
36+
37+
browserstackRunner.run(config, function(error, report) {
38+
if(error) {
39+
console.log("Error:" + error);
40+
return;
41+
}
42+
console.log(JSON.stringify(report, null, 2));
43+
console.log("Test Finished");
44+
});
45+
```
46+
47+
The callback to `browserstackRunner.run` is called with two params -
48+
- `error`: This parameter is either `null` or an `Error` object (if test execution failed) with message as the reason of why executing the tests on `BrowserStack` failed.
49+
- `report`: This is an array which can be used to keep track of the executed tests and suites in a run. Each object in the array has the following keys -
50+
- `browser`: The name of the browser the test executed on.
51+
- `tests`: An array of `Test` objects. The `Test` Objects are described [here](https://github.com/js-reporters/js-reporters#event-data)
52+
- `suites`: A global Suite Object as described [here](https://github.com/js-reporters/js-reporters#event-data)
53+
54+
The structure of the `report` object is as follows -
55+
56+
```json
57+
[
58+
{
59+
"browser": "Windows 7, Firefox 47.0",
60+
"tests": [
61+
{
62+
"name": "isOdd()",
63+
"suiteName": "Odd Tests",
64+
"fullName": [
65+
"Odd Tests",
66+
"isOdd()"
67+
],
68+
"status": "passed",
69+
"runtime": 2,
70+
"errors": [],
71+
"assertions": [
72+
{
73+
"passed": true,
74+
"actual": true,
75+
"expected": true,
76+
"message": "One is an odd number"
77+
},
78+
{
79+
"passed": true,
80+
"actual": true,
81+
"expected": true,
82+
"message": "Three is an odd number"
83+
},
84+
{
85+
"passed": true,
86+
"actual": true,
87+
"expected": true,
88+
"message": "Zero is not odd number"
89+
}
90+
]
91+
}
92+
],
93+
"suites": {
94+
"fullName": [],
95+
"childSuites": [
96+
{
97+
"name": "Odd Tests",
98+
"fullName": [
99+
"Odd Tests"
100+
],
101+
"childSuites": [],
102+
"tests": [
103+
{
104+
"name": "isOdd()",
105+
"suiteName": "Odd Tests",
106+
"fullName": [
107+
"Odd Tests",
108+
"isOdd()"
109+
],
110+
"status": "passed",
111+
"runtime": 2,
112+
"errors": [],
113+
"assertions": [
114+
{
115+
"passed": true,
116+
"actual": true,
117+
"expected": true,
118+
"message": "One is an odd number"
119+
},
120+
{
121+
"passed": true,
122+
"actual": true,
123+
"expected": true,
124+
"message": "Three is an odd number"
125+
},
126+
{
127+
"passed": true,
128+
"actual": true,
129+
"expected": true,
130+
"message": "Zero is not odd number"
131+
}
132+
]
133+
}
134+
],
135+
"status": "passed",
136+
"testCounts": {
137+
"passed": 1,
138+
"failed": 0,
139+
"skipped": 0,
140+
"total": 1
141+
},
142+
"runtime": 2
143+
}
144+
],
145+
"tests": [],
146+
"status": "passed",
147+
"testCounts": {
148+
"passed": 1,
149+
"failed": 0,
150+
"skipped": 0,
151+
"total": 1
152+
},
153+
"runtime": 2
154+
}
155+
}
156+
]
157+
```
158+
24159
## Configuration
25160

26161
To run browser tests on BrowserStack infrastructure, you need to create a `browserstack.json` file in project's root directory (the directory from which tests are run), by running this command:

0 commit comments

Comments
 (0)