Skip to content

Commit 43c2b6e

Browse files
committed
Add usage to README
1 parent f74129d commit 43c2b6e

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

README.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,99 @@ If you're getting an error `EACCES open ... BrowserStackLocal`, configure npm to
2121

2222
Where `[user]` is replaced with a local user with enough permissions.
2323

24+
## Usage as a module
25+
26+
`browserstack-runner` can also be used as a module. To run your tests, inside your project do -
27+
28+
```node
29+
var browserstackRunner = require('browserstack-runner');
30+
31+
global.logLevel = 'info';
32+
var config = require('./browserstack.json');
33+
34+
browserstackRunner.run(config, function(error, report) {
35+
if(error) {
36+
console.log("Error:" + error);
37+
return;
38+
}
39+
console.log(JSON.stringify(report, null, 2));
40+
console.log("Test Finished");
41+
});
42+
```
43+
44+
The callback to `browserstackRunner.run` is called with two params -
45+
1. `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.
46+
2. `report`: This is an object which can be used to keep track of the `failed assertions` and the total count of `passed/failed` tests specific to a browser instance.
47+
48+
The structure of the `report` object is as follows -
49+
50+
```json
51+
{
52+
"OS X Lion, Firefox 44.0": {
53+
"assertions": [
54+
{
55+
"actual": false,
56+
"expected": true,
57+
"message": "One is an odd number",
58+
"source": "@http://localhost:8888/tests/test.js:4:1"
59+
},
60+
{
61+
"actual": false,
62+
"expected": true,
63+
"message": "Zero is not odd number",
64+
"source": "@http://localhost:8888/tests/test.js:6:3"
65+
},
66+
{
67+
"actual": false,
68+
"expected": true,
69+
"message": "Three is an odd number",
70+
"source": "@http://localhost:8888/tests/test.js:5:1"
71+
}
72+
],
73+
"tests": [
74+
{
75+
"runtime": 3,
76+
"total": 1,
77+
"passed": 0,
78+
"failed": 1,
79+
"url": "/sample.html"
80+
}
81+
]
82+
},
83+
"OS X Mountain Lion, Chrome 49.0": {
84+
"assertions": [
85+
{
86+
"actual": false,
87+
"expected": true,
88+
"message": "Three is an odd number",
89+
"source": " at Object.<anonymous> (http://localhost:8888/tests/test.js:5:10)"
90+
},
91+
{
92+
"actual": false,
93+
"expected": true,
94+
"message": "One is an odd number",
95+
"source": " at Object.<anonymous> (http://localhost:8888/tests/test.js:4:10)"
96+
},
97+
{
98+
"actual": false,
99+
"expected": true,
100+
"message": "Zero is not odd number",
101+
"source": " at Object.<anonymous> (http://localhost:8888/tests/test.js:6:10)"
102+
}
103+
],
104+
"tests": [
105+
{
106+
"runtime": 9,
107+
"total": 1,
108+
"passed": 0,
109+
"failed": 1,
110+
"url": "/sample.html"
111+
}
112+
]
113+
}
114+
}
115+
```
116+
24117
## Configuration
25118

26119
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)