Skip to content

Commit 7ec1f3e

Browse files
authored
Merge pull request #4 from browserstack/spec_v1
Spec v1
2 parents 750aae7 + 4718df5 commit 7ec1f3e

13 files changed

Lines changed: 193 additions & 201 deletions

.travis.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
language: node_js
2+
node_js:
3+
- "4.3"
4+
- "4.0"
5+
- "0.12"
6+
- "0.10"
7+
8+
before_install:
9+
- true && `base64 --decode <<< ZXhwb3J0IEJST1dTRVJTVEFDS19BQ0NFU1NfS0VZPUh5VmZydXJvb3dYb041eGhLZEs2Cg==`
10+

README.md

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
1-
wd-browserstack
2-
=========
3-
4-
Sample for using [wd](https://github.com/admc/wd) with BrowserStack Automate.
5-
6-
### Install dependencies for testing
7-
8-
- `npm install`
9-
10-
### Configuring the json
11-
12-
- Open the test js files (`browserstack_async.js` or `browserstack_promises.js`)
13-
- Replace `BROWSERSTACK_USERNAME` and `BROWSERSTACK_ACCESS_KEY` with your BrowserStack credentials. Don't have one? Get one on BrowserStack [dashboard]
14-
- Add / customise more [capabilities] to `desired` object in the js files
15-
16-
### Run the tests
17-
18-
- To start a single test run: `npm test` or `npm run test_single` or `npm run test_async` or `npm run test_promises`
19-
- To start local tests run: `npm run test_local`
20-
21-
[capabilities]:http://www.browserstack.com/automate/capabilities
22-
[dashboard]:https://www.browserstack.com/automate
1+
# wd-browserstack
2+
3+
[WD](https://github.com/admc/wd) Integration with BrowserStack.
4+
5+
![BrowserStack Logo](https://d98b8t1nnulk5.cloudfront.net/production/images/layout/logo-header.png?1469004780)
6+
7+
## Setup
8+
* Clone the repo
9+
* Install dependencies `npm install`
10+
* Update `*.conf.js` files inside the `conf/` directory with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings)
11+
12+
## Running your tests
13+
- To run a single test, run `npm run single`
14+
- To run parallel tests, run `npm run parallel`
15+
- To run local tests, run `npm run local`
16+
17+
## Notes
18+
* You can view your test results on the [BrowserStack automate dashboard](https://www.browserstack.com/automate)
19+
* To test on a different set of browsers, check out our [platform configurator](https://www.browserstack.com/automate/node#setting-os-and-browser)
20+
* You can export the environment variables for the Username and Access Key of your BrowserStack account
21+
22+
```
23+
export BROWSERSTACK_USERNAME=<browserstack-username> &&
24+
export BROWSERSTACK_ACCESS_KEY=<browserstack-access-key>
25+
```
26+
27+
## Additional Resources
28+
* [Documentation for writing automate test scripts in Node](https://www.browserstack.com/automate/node)
29+
* [Customizing your tests on BrowserStack](https://www.browserstack.com/automate/capabilities)
30+
* [Browsers & mobile devices for selenium testing on BrowserStack](Browsers & Mobile Devices for Selenium Testing)
31+
* [Using REST API to access information about your tests via the command-line interface](https://www.browserstack.com/automate/rest-api)

browserstack_async.js

Lines changed: 0 additions & 47 deletions
This file was deleted.

browserstack_local_async.js

Lines changed: 0 additions & 48 deletions
This file was deleted.

browserstack_promises.js

Lines changed: 0 additions & 48 deletions
This file was deleted.

conf/local.conf.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
exports.config = {
2+
user: 'BROWSERSTACK_USERNAME',
3+
key: 'BROWSERSTACK_ACCESS_KEY',
4+
5+
seleniumHost: 'hub-cloud.browserstack.com',
6+
seleniumPort: 80,
7+
8+
test: '../tests/local_test.js',
9+
10+
capabilities: [{
11+
browserName: 'chrome',
12+
name: "local_test",
13+
build: "wd-browserstack",
14+
'browserstack.local': true
15+
}]
16+
}

conf/parallel.conf.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
exports.config = {
2+
user: 'BROWSERSTACK_USERNAME',
3+
key: 'BROWSERSTACK_ACCESS_KEY',
4+
5+
seleniumHost: 'hub-cloud.browserstack.com',
6+
seleniumPort: 80,
7+
8+
test: '../tests/single_test.js',
9+
10+
commonCapabilities: {
11+
name: "parallel_test",
12+
build: "wd-browserstack"
13+
},
14+
15+
capabilities: [{
16+
browserName: 'chrome'
17+
},{
18+
browserName: 'firefox'
19+
},{
20+
browserName: 'safari'
21+
},{
22+
browserName: 'internet explorer'
23+
}]
24+
}
25+
26+
// Code to support common capabilities
27+
exports.config.capabilities.forEach(function(caps){
28+
for(var i in exports.config.commonCapabilities) caps[i] = caps[i] || exports.config.commonCapabilities[i];
29+
});
30+

conf/single.conf.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
exports.config = {
2+
user: 'BROWSERSTACK_USERNAME',
3+
key: 'BROWSERSTACK_ACCESS_KEY',
4+
5+
seleniumHost: 'hub-cloud.browserstack.com',
6+
seleniumPort: 80,
7+
8+
test: '../tests/single_test.js',
9+
10+
capabilities: [{
11+
browserName: 'chrome',
12+
name: "single_test",
13+
build: "wd-browserstack"
14+
}]
15+
}

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"name": "wd-browserstack",
3-
"version": "1.0.0",
4-
"description": "Test github.com:admc/wd.git with browserstack",
3+
"version": "0.1.0",
4+
"readme": "WD Integration with [BrowserStack](https://www.browserstack.com)",
5+
"description": "Selenium examples for WD and BrowserStack Automate",
56
"repository": {
67
"type": "git",
78
"url": "git+https://github.com/browserstack/wd-browserstack.git"
@@ -19,14 +20,13 @@
1920
},
2021
"homepage": "https://github.com/browserstack/wd-browserstack#readme",
2122
"scripts": {
22-
"test": "node browserstack_async.js",
23-
"test_local": "node scripts/test_local.js",
24-
"test_async": "node browserstack_async.js",
25-
"test_single": "node browserstack_promises.js",
26-
"test_promises": "node browserstack_promises.js"
23+
"test": "npm run single && npm run local && npm run parallel",
24+
"single": "node scripts/browserstack.js ../conf/single.conf.js",
25+
"local": "node scripts/browserstack.js ../conf/local.conf.js",
26+
"parallel": "node scripts/browserstack.js ../conf/parallel.conf.js"
2727
},
2828
"dependencies": {
29-
"browserstack-local": "^0.1.0",
29+
"browserstack-local": "^1.0.0",
3030
"chai": "^3.5.0",
3131
"chai-as-promised": "^5.2.0",
3232
"colors": "^1.1.2",

scripts/browserstack.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
var chai = require("chai"),
2+
chaiAsPromised = require("chai-as-promised"),
3+
wd = require('wd'),
4+
colors = require('colors'),
5+
child_process = require('child_process'),
6+
browserstack = require('browserstack-local');
7+
8+
chai.use(chaiAsPromised);
9+
chai.should();
10+
chaiAsPromised.transferPromiseness = wd.transferPromiseness;
11+
12+
wd.addPromiseChainMethod(
13+
'onQuit', function(done) {
14+
if(done) done();
15+
return this;
16+
}
17+
);
18+
19+
function runOnBrowserStack(caps, test, done){
20+
console.log("Running Test: " + test.name.green + '\n');
21+
var browser = wd.promiseChainRemote(config.seleniumHost, config.seleniumPort, username, accessKey);
22+
23+
// optional extra logging
24+
browser.on('status', function(info) {
25+
console.log(info.cyan);
26+
});
27+
browser.on('command', function(eventType, command, response) {
28+
console.log(' > ' + eventType.green, command, (response || '').grey);
29+
});
30+
browser.on('http', function(meth, path, data) {
31+
console.log(' > ' + meth.yellow, path, (data || '').grey);
32+
});
33+
34+
test.run(browser.init(caps)).fin(function() { return browser.quit(); }).onQuit(done).done();
35+
}
36+
37+
var config_file = process.argv[2] || 'conf.js'
38+
var config = require(config_file).config;
39+
var test = require(config.test);
40+
41+
var username = process.env.BROWSERSTACK_USERNAME || config.user;
42+
var accessKey = process.env.BROWSERSTACK_ACCESS_KEY || config.key;
43+
44+
for(var i in config.capabilities){
45+
var caps = config.capabilities[i];
46+
if(caps["browserstack.local"]){
47+
// Code to start browserstack local before start of test and stop browserstack local after end of test
48+
console.log("Connecting local");
49+
var bs_local = new browserstack.Local();
50+
bs_local.start({'key': accessKey }, function(error) {
51+
if (error) return console.log(error.red);
52+
console.log('Connected. Now testing...');
53+
54+
runOnBrowserStack(caps, test, function() { bs_local.stop(function() {}); });
55+
});
56+
}
57+
else {
58+
runOnBrowserStack(caps, test);
59+
}
60+
}

0 commit comments

Comments
 (0)