Skip to content

Commit 750aae7

Browse files
committed
Merge pull request #1 from browserstack/restructure
restructure
2 parents 4fd77b2 + e4ec935 commit 750aae7

7 files changed

Lines changed: 94 additions & 6 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
local.log

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@ wd-browserstack
33

44
Sample for using [wd](https://github.com/admc/wd) with BrowserStack Automate.
55

6-
###Install dependencies for testing
6+
### Install dependencies for testing
7+
78
- `npm install`
89

9-
###Configuring the json
10+
### Configuring the json
11+
1012
- Open the test js files (`browserstack_async.js` or `browserstack_promises.js`)
1113
- Replace `BROWSERSTACK_USERNAME` and `BROWSERSTACK_ACCESS_KEY` with your BrowserStack credentials. Don't have one? Get one on BrowserStack [dashboard]
1214
- Add / customise more [capabilities] to `desired` object in the js files
1315

14-
###Sample test
15-
- To start a test run: `node browserstack_async.js` or `node browserstack_promises.js`
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`
1620

1721
[capabilities]:http://www.browserstack.com/automate/capabilities
1822
[dashboard]:https://www.browserstack.com/automate

browserstack_async.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ browser.init(desired, function() {
3636
title.should.include('WD');
3737
browser.elementById('i am a link', function(err, el) {
3838
browser.clickElement(el, function() {
39-
/* jshint evil: true */
4039
browser.eval("window.location.href", function(err, href) {
4140
href.should.include('guinea-pig2');
4241
browser.quit();

browserstack_local_async.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
var username = process.env.BROWSERSTACK_USERNAME || "BROWSERSTACK_USERNAME";
2+
var accessKey = process.env.BROWSERSTACK_ACCESS_KEY || "BROWSERSTACK_ACCESS_KEY";
3+
4+
require('colors');
5+
var chai = require('chai');
6+
var wd = require('wd');
7+
8+
chai.should();
9+
10+
var browser = wd.remote("hub.browserstack.com", 80, username, accessKey);
11+
12+
// optional extra logging
13+
browser.on('status', function(info) {
14+
console.log(info.cyan);
15+
});
16+
browser.on('command', function(eventType, command, response) {
17+
console.log(' > ' + eventType.cyan, command, (response || '').grey);
18+
});
19+
browser.on('http', function(meth, path, data) {
20+
console.log(' > ' + meth.magenta, path, (data || '').grey);
21+
});
22+
23+
var desired = {
24+
os: 'OS X',
25+
os_version: 'El Capitan',
26+
browser: 'chrome',
27+
browser_version: '',
28+
project: "examples",
29+
name: "This is an example local test",
30+
build: "WD BrowserStack Sample Test",
31+
"browserstack.local": true
32+
};
33+
34+
browser.init(desired, function() {
35+
browser.get("http://admc.io/wd/test-pages/guinea-pig.html", function() {
36+
browser.title(function(err, title) {
37+
title.should.include('WD');
38+
browser.elementById('i am a link', function(err, el) {
39+
browser.clickElement(el, function() {
40+
browser.eval("window.location.href", function(err, href) {
41+
href.should.include('guinea-pig2');
42+
browser.quit();
43+
});
44+
});
45+
});
46+
});
47+
});
48+
});

browserstack_promises.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ var desired = {
3535
build: "WD BrowserStack Sample Test"
3636
};
3737

38-
/* jshint evil: true */
3938
browser
4039
.init(desired)
4140
.get("http://admc.io/wd/test-pages/guinea-pig.html")

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,15 @@
1818
"url": "https://github.com/browserstack/wd-browserstack/issues"
1919
},
2020
"homepage": "https://github.com/browserstack/wd-browserstack#readme",
21+
"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"
27+
},
2128
"dependencies": {
29+
"browserstack-local": "^0.1.0",
2230
"chai": "^3.5.0",
2331
"chai-as-promised": "^5.2.0",
2432
"colors": "^1.1.2",

scripts/test_local.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
var child_process = require('child_process');
2+
var browserstack = require('browserstack-local');
3+
4+
var bs_local = new browserstack.Local();
5+
var bs_local_args = { 'key': process.env.BROWSERSTACK_ACCESS_KEY, 'forcelocal': true };
6+
7+
bs_local.start(bs_local_args, function(error) {
8+
if (error) {
9+
console.log(error);
10+
} else {
11+
console.log('Connected. Now testing...');
12+
13+
child = child_process.execSync('node browserstack_local_async.js', { stdio: [ 0, 0, 0 ] });
14+
15+
if(child) {
16+
child.on('exit', function() {
17+
if(bs_local) {
18+
bs_local.stop(function() {});
19+
}
20+
21+
exit(0);
22+
});
23+
}
24+
}
25+
if(bs_local) {
26+
bs_local.stop(function() {});
27+
}
28+
});

0 commit comments

Comments
 (0)