Skip to content

Commit 4fd77b2

Browse files
committed
WD tests with BrowserStack
0 parents  commit 4fd77b2

4 files changed

Lines changed: 142 additions & 0 deletions

File tree

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
- `npm install`
8+
9+
###Configuring the json
10+
- Open the test js files (`browserstack_async.js` or `browserstack_promises.js`)
11+
- Replace `BROWSERSTACK_USERNAME` and `BROWSERSTACK_ACCESS_KEY` with your BrowserStack credentials. Don't have one? Get one on BrowserStack [dashboard]
12+
- Add / customise more [capabilities] to `desired` object in the js files
13+
14+
###Sample test
15+
- To start a test run: `node browserstack_async.js` or `node browserstack_promises.js`
16+
17+
[capabilities]:http://www.browserstack.com/automate/capabilities
18+
[dashboard]:https://www.browserstack.com/automate

browserstack_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 async test",
30+
build: "WD BrowserStack Sample Test"
31+
};
32+
33+
browser.init(desired, function() {
34+
browser.get("http://admc.io/wd/test-pages/guinea-pig.html", function() {
35+
browser.title(function(err, title) {
36+
title.should.include('WD');
37+
browser.elementById('i am a link', function(err, el) {
38+
browser.clickElement(el, function() {
39+
/* jshint evil: true */
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: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 chaiAsPromised = require("chai-as-promised");
7+
8+
chai.use(chaiAsPromised);
9+
chai.should();
10+
11+
var wd = require('wd');
12+
13+
// enables chai assertion chaining
14+
chaiAsPromised.transferPromiseness = wd.transferPromiseness;
15+
16+
var browser = wd.promiseChainRemote("hub.browserstack.com", 80, username, accessKey);
17+
18+
// optional extra logging
19+
browser.on('status', function(info) {
20+
console.log(info.cyan);
21+
});
22+
browser.on('command', function(eventType, command, response) {
23+
console.log(' > ' + eventType.cyan, command, (response || '').grey);
24+
});
25+
browser.on('http', function(meth, path, data) {
26+
console.log(' > ' + meth.magenta, path, (data || '').grey);
27+
});
28+
29+
var desired = {
30+
os: 'Windows',
31+
os_version: '10',
32+
browser: 'firefox',
33+
project: "examples",
34+
name: "This is an example test with promises",
35+
build: "WD BrowserStack Sample Test"
36+
};
37+
38+
/* jshint evil: true */
39+
browser
40+
.init(desired)
41+
.get("http://admc.io/wd/test-pages/guinea-pig.html")
42+
.title()
43+
.should.become('WD Tests')
44+
.elementById('i am a link')
45+
.click()
46+
.eval("window.location.href")
47+
.should.eventually.include('guinea-pig2')
48+
.fin(function() { return browser.quit(); })
49+
.done();

package.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "wd-browserstack",
3+
"version": "1.0.0",
4+
"description": "Test github.com:admc/wd.git with browserstack",
5+
"repository": {
6+
"type": "git",
7+
"url": "git+https://github.com/browserstack/wd-browserstack.git"
8+
},
9+
"keywords": [
10+
"wd",
11+
"browserstack",
12+
"wd-browserstack",
13+
"webdriver",
14+
"selenium"
15+
],
16+
"author": "BrowserStack",
17+
"bugs": {
18+
"url": "https://github.com/browserstack/wd-browserstack/issues"
19+
},
20+
"homepage": "https://github.com/browserstack/wd-browserstack#readme",
21+
"dependencies": {
22+
"chai": "^3.5.0",
23+
"chai-as-promised": "^5.2.0",
24+
"colors": "^1.1.2",
25+
"wd": "^0.4.0"
26+
}
27+
}

0 commit comments

Comments
 (0)