Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
local.log
testem.log
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: node_js
node_js:
- "4.3"
- "4.0"
- "0.12"
- "0.10"

before_install:
- true && `base64 --decode <<< ZXhwb3J0IEJST1dTRVJTVEFDS19BQ0NFU1NfS0VZPUh5VmZydXJvb3dYb041eGhLZEs2Cg==`

37 changes: 26 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
Testem with BrowserStack
========================
# testem-browserstack
[Testem](https://github.com/testem/testem) Integration with BrowserStack.

Run your tests on various browsers hosted on Browserstack!
![BrowserStack Logo](https://d98b8t1nnulk5.cloudfront.net/production/images/layout/logo-header.png?1469004780)

Instructions
------------
## Setup
* Clone the repo
* Install dependencies `npm install`
* Update `testem.json` file with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings)

1. Get a [BrowserStack](browserstack.com) account.
2. For BrowserStack Authentication export the environment variables for the username and access key of your BrowserStack account. These can be found on the automate accounts page on [BrowserStack](https://www.browserstack.com/accounts/automate) `export BROWSERSTACK_USERNAME=<browserstack-username> && export BROWSERSTACK_ACCESS_KEY=<browserstack-access-key>`
3. Install the dependencies by running `npm install browserstack browserstack-local`
4. Install testem globally by running `npm install testem -g`
5. Run the command `testem ci -l bs_chrome` to test out the setup with just the Chrome browser hosted BrowserStack.
6. Run `testem ci` to run it on all the listed browsers - see `testem launchers` for the full list.
## Running yourtests
* To run a single test, run `npm run single`
* To run parallel tests, run `npm run parallel`

## Notes
* You can view your test results on the [BrowserStack automate dashboard](https://www.browserstack.com/automate)
* To test on a different set of browsers, check out our [platform configurator](https://www.browserstack.com/automate/node#setting-os-and-browser)
* You can export the environment variables for the Username and Access Key of your BrowserStack account

```
export BROWSERSTACK_USERNAME=<browserstack-username> &&
export BROWSERSTACK_ACCESS_KEY=<browserstack-access-key>
```

## Additional Resources
* [Customizing your tests on BrowserStack](https://www.browserstack.com/automate/capabilities)
* [Browsers & mobile devices for JavaScript testing on BrowserStack](https://www.browserstack.com/list-of-browsers-and-platforms?product=js_testing)
* [Using REST API to access information about your tests via the command-line interface](https://www.browserstack.com/automate/rest-api)

3 changes: 0 additions & 3 deletions bin/stop-BrowserStackLocal.js

This file was deleted.

23 changes: 23 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "testem-browserstack",
"version": "0.1.0",
"readme": "Testem Integration with [BrowserStack](https://www.browserstack.com)",
"description": "Selenium examples for Testem and BrowserStack Automate",
"repository": {
"type": "git",
"url": "git+https://github.com/browserstack/testem-browserstack.git"
},
"scripts": {
"test": "npm run single && npm run parallel",
"single": "./node_modules/.bin/testem ci -l bs_chrome",
"parallel": "./node_modules/.bin/testem ci"
},
"devDependencies": {
"testem": "*",
"browserstack": "*",
"selenium-webdriver": "^2.53.2"
},
"dependencies": {
"browserstack-local": "^1.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#!/usr/bin/env node

if(process.argv[2]){
process.kill(process.argv[2], 'SIGINT');
process.exit(0);
}

var browserstack = require('browserstack-local');
var fs = require('fs');

var pidFile = 'browserStackLocal.pid';
var pidFile = 'browserstack-local.pid';
var bs_local = new browserstack.Local();
var bs_local_args = {
'key': process.env.BROWSERSTACK_ACCESS_KEY,
Expand All @@ -17,7 +22,7 @@ process.on('SIGINT', function() {
if (error) {
console.log(error);
} else {
console.log('BrowserStackLocal disconnected');
console.log('BrowserStackLocal Disconnected');
process.exit();
}
});
Expand All @@ -30,6 +35,6 @@ bs_local.start(bs_local_args, function(error) {
if (error) {
console.log(error);
} else {
console.log("Tunnel started");
console.log("Tunnel Started");
}
});
10 changes: 6 additions & 4 deletions bin/run_on_browserstack.js → scripts/browserstack.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

var WORKER_ID = 0;
var BrowserStack = require('browserstack');
var config = require('../testem.json');
var name = null

var client = BrowserStack.createClient({
username: process.env.BROWSERSTACK_USERNAME,
password: process.env.BROWSERSTACK_ACCESS_KEY
username: process.env.BROWSERSTACK_USERNAME || config.bs_user,
password: process.env.BROWSERSTACK_ACCESS_KEY || config.bs_key
});

'SIGINT SIGTERM SIGHUP'.split(' ').forEach(function(evt) {
Expand All @@ -31,10 +32,9 @@ var settings = {
browser_version: process.argv[5],
device: process.argv[6],
url: process.argv[7],

'browserstack.local': true,
name: name,
build: 'Testem Sample Tests'
build: 'testem-browserstack'
};

for (var i in settings) {
Expand All @@ -43,6 +43,8 @@ for (var i in settings) {
}
}

console.log(settings);

client.createWorker(settings, function(error, worker) {
if (error) console.log(error);
WORKER_ID = worker.id
Expand Down
2 changes: 1 addition & 1 deletion test/hello.js → src/hello.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
function hello(name){
return "hello " + (name || 'world');
}
}
8 changes: 0 additions & 8 deletions test/hello_spec.js

This file was deleted.

61 changes: 27 additions & 34 deletions testem.json
Original file line number Diff line number Diff line change
@@ -1,59 +1,52 @@
{
"bs_user": "BROWSERSTACK_USERNAME",
"bs_key": "BROWSERSTACK_ACCESS_KEY",

"framework": "jasmine",
"parallel": 5,
"parallel": 4,

"on_start": {
"command": "kill -9 $(ps -A | grep BrowserStackLocal | grep -v grep | cut -d ' ' -f2); ./bin/start-BrowserStackLocal.js &",
"wait_for_text": "Tunnel started",
"command": "kill -9 $(ps -A | grep BrowserStackLocal | grep -v grep | cut -d ' ' -f2); ./scripts/browserstack-local.js &",
"wait_for_text": "Tunnel Started",
"wait_for_text_timeout": 300000
},
"on_exit": "./bin/stop-BrowserStackLocal.js `cat browserStackLocal.pid`; rm browserStackLocal.pid",

"on_exit": "./scripts/browserstack-local.js `cat browserstack-local.pid`; rm browserstack-local.pid",

"launchers": {
"bs_opera": {
"exe": "./bin/run_on_browserstack.js",
"args": [ "Windows", "10", "opera", "latest", "" ],
"protocol": "browser"
},

"bs_firefox": {
"exe": "./bin/run_on_browserstack.js",
"args": [ "Windows", "10", "firefox", "latest", "" ],
"protocol": "browser"
},

"bs_chrome": {
"exe": "./bin/run_on_browserstack.js",
"args": [ "OS X", "El Capitan", "chrome", "latest", "" ],
"exe": "./scripts/browserstack.js",
"args": [ "OSX", "ElCapitan", "chrome", "51.0", "" ],
"protocol": "browser"
},

"bs_safari_71": {
"exe": "./bin/run_on_browserstack.js",
"args": [ "OS X", "Mavericks", "safari", "7.1", "" ],
"bs_firefox": {
"exe": "./scripts/browserstack.js",
"args": [ "Windows", "10", "firefox", "45.0", "" ],
"protocol": "browser"
},

"bs_safari_51": {
"exe": "./bin/run_on_browserstack.js",
"args": [ "OS X", "Snow Leopard", "safari", "5.1", "" ],
"bs_safari": {
"exe": "./scripts/browserstack.js",
"args": [ "OSX", "ElCapitan", "safari", "9.1", "" ],
"protocol": "browser"
},

"bs_ie_11": {
"exe": "./bin/run_on_browserstack.js",
"bs_ie": {
"exe": "./scripts/browserstack.js",
"args": [ "Windows", "10", "ie", "11.0", "" ],
"protocol": "browser"
}
},

"launch_in_dev": [],

"launch_in_ci": [
"bs_opera",
"bs_chrome",
"bs_firefox",
"bs_safari_71",
"bs_safari_51",
"bs_ie_11"
"bs_safari",
"bs_ie"
],

"src_files": [
"test/*"
"src/*",
"tests/*"
]
}
9 changes: 9 additions & 0 deletions tests/hello_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
describe('hello', function(){
it('should say hello', function(){
expect(hello()).toBe('hello world');
});

it('should say hello to person', function(){
expect(hello('Bob')).toBe('hello Bob');
});
});