From 112cd0fdb000c4a299ce387f6a243688e6ee47d9 Mon Sep 17 00:00:00 2001 From: Tim Watkins Date: Wed, 18 Jan 2017 14:10:11 -0700 Subject: [PATCH] Include example on how to use this with Mocha/Se Included an example on how to do this with Mocha/Se WebDriver JS. This can save someone much time, as it showcases the need for a done() callback in the test.before hook. This is necessary to work with the async nature of this browserstack-local module, otherwise a race condition is present between the local binary being run and the webdriver attempting to connect to it. --- mocha-se-example.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 mocha-se-example.js diff --git a/mocha-se-example.js b/mocha-se-example.js new file mode 100644 index 0000000..aac1bc5 --- /dev/null +++ b/mocha-se-example.js @@ -0,0 +1,33 @@ +import assert from 'assert'; +import test from 'selenium-webdriver/testing'; +var browserstack = require('browserstack-local'); +var local = new browserstack.Local(); +let localOptions = { + 'key': 'BrowserStack Access Key Goes Here!' +}; + +test.before(function(done) { + this.timeout(30000); + console.log('Starting BrowserStack-Local...'); + local.start(localOptions, ()=>{ + console.log("Started BrowserStack-Local."); + // ...Code to start WebDriver goes here... + done(); + }); +}); + +test.after(function() { + this.timeout(30000); + // ...Code to stop WebDriver goes here... + console.log('Stopping BrowserStack-Local...'); + local.stop(()=>{ + console.log("Stopped BrowserStack-Local"); + }); +}); + +test.describe('Example Test Suite 1', function() { + this.timeout(30000); + test.it('Example Test Case 1', function() { + // ...Test Case Code goes here... + }); +});