diff --git a/.gitignore b/.gitignore index ae4a8b1..9860632 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules local.log +testem.log diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..088dad1 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,10 @@ +language: node_js +node_js: + - "4.3" + - "4.0" + - "0.12" + - "0.10" + +before_install: + - true && `base64 --decode <<< ZXhwb3J0IEJST1dTRVJTVEFDS19BQ0NFU1NfS0VZPUh5VmZydXJvb3dYb041eGhLZEs2Cg==` + diff --git a/README.md b/README.md index 8d87229..d2fed07 100644 --- a/README.md +++ b/README.md @@ -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= && export 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= && + export 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) + diff --git a/bin/stop-BrowserStackLocal.js b/bin/stop-BrowserStackLocal.js deleted file mode 100755 index 3464971..0000000 --- a/bin/stop-BrowserStackLocal.js +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env node - -process.kill(process.argv[2], 'SIGINT'); diff --git a/package.json b/package.json new file mode 100644 index 0000000..5df6ebb --- /dev/null +++ b/package.json @@ -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" + } +} diff --git a/bin/start-BrowserStackLocal.js b/scripts/browserstack-local.js similarity index 73% rename from bin/start-BrowserStackLocal.js rename to scripts/browserstack-local.js index 4b9cbd6..81fff3a 100755 --- a/bin/start-BrowserStackLocal.js +++ b/scripts/browserstack-local.js @@ -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, @@ -17,7 +22,7 @@ process.on('SIGINT', function() { if (error) { console.log(error); } else { - console.log('BrowserStackLocal disconnected'); + console.log('BrowserStackLocal Disconnected'); process.exit(); } }); @@ -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"); } }); diff --git a/bin/run_on_browserstack.js b/scripts/browserstack.js similarity index 82% rename from bin/run_on_browserstack.js rename to scripts/browserstack.js index 4f399f3..e3b3b84 100755 --- a/bin/run_on_browserstack.js +++ b/scripts/browserstack.js @@ -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) { @@ -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) { @@ -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 diff --git a/test/hello.js b/src/hello.js similarity index 96% rename from test/hello.js rename to src/hello.js index cf43c76..e223592 100644 --- a/test/hello.js +++ b/src/hello.js @@ -1,3 +1,3 @@ function hello(name){ return "hello " + (name || 'world'); -} \ No newline at end of file +} diff --git a/test/hello_spec.js b/test/hello_spec.js deleted file mode 100644 index 75cfa8e..0000000 --- a/test/hello_spec.js +++ /dev/null @@ -1,8 +0,0 @@ -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'); - }); -}); \ No newline at end of file diff --git a/testem.json b/testem.json index 8ebda58..fb5efd3 100644 --- a/testem.json +++ b/testem.json @@ -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/*" ] } diff --git a/tests/hello_spec.js b/tests/hello_spec.js new file mode 100644 index 0000000..31e9361 --- /dev/null +++ b/tests/hello_spec.js @@ -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'); + }); +});