From 170693cd8b96a7822ea7694bab9d56abd8838160 Mon Sep 17 00:00:00 2001 From: David Witherspoon Date: Wed, 13 Jan 2016 12:58:31 -0800 Subject: [PATCH] Add information in debugging in k3po.js, added some extra logging in the browser for when debugging was enabled --- Gruntfile.js | 2 ++ README.md | 16 ++++++++++++++++ lib/browser/BrowserRunner.js | 6 +++--- lib/browser/RemoteScriptRunner.js | 12 ++++++++++-- test/testFrameworks/mocha-k3po_spec.js | 2 +- 5 files changed, 32 insertions(+), 6 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 45c8267..3366125 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -75,7 +75,9 @@ module.exports = function (grunt) { ui: 'mocha-k3po', require: 'lib/testFrameworks/mocha-k3po.js', captureFile: "build/testMochaK3po.txt", + // timeout: 5000, browser: { + // debug: true, desiredCapabilities: { browserName: 'firefox' } diff --git a/README.md b/README.md index fe55d4d..22e4040 100644 --- a/README.md +++ b/README.md @@ -127,3 +127,19 @@ Configuration via Grunt 1. `npm install` 1. `grunt` + +### Debugging the browser + +By default the browser closes after the test, in case of test failures you can pass the debug flag to the browser +configuration as shown to keep it open. This allows access to the browser javascript console. + +```JavaScript +browser: { + desiredCapabilities: { + browserName: 'firefox' + }, + debug: true +} + +``` + diff --git a/lib/browser/BrowserRunner.js b/lib/browser/BrowserRunner.js index c509229..ad600f5 100644 --- a/lib/browser/BrowserRunner.js +++ b/lib/browser/BrowserRunner.js @@ -37,9 +37,9 @@ BrowserRunner.prototype.loadOrigin = function () { _this._browser.url(this._origin); } - return _this._browser.execute(RemoteScriptRunner).execute(function (resources) { - k3po = new RemoteScriptRunner(resources); - }, _this._resources).then(); + return _this._browser.execute(RemoteScriptRunner).execute(function (resources, debug) { + k3po = new RemoteScriptRunner(resources, debug); + }, _this._resources, _this._debug).then(); }; BrowserRunner.prototype.getExceptions = function () { diff --git a/lib/browser/RemoteScriptRunner.js b/lib/browser/RemoteScriptRunner.js index e3989ee..ac33490 100644 --- a/lib/browser/RemoteScriptRunner.js +++ b/lib/browser/RemoteScriptRunner.js @@ -13,11 +13,12 @@ var window; */ module.exports = function () { - RemoteScriptRunner = function RemoteScriptRunner(resources) { + RemoteScriptRunner = function RemoteScriptRunner(resources, debug) { this._state = "INITIAL"; this._cmdQueue = []; this._eventListenerMap = []; this._eventAlreadyFiredEventMap = []; + this._debug = debug; for (var i = 0; i < resources.length; i++) { this.loadScript(resources[i]); } @@ -138,7 +139,11 @@ module.exports = function () { RemoteScriptRunner.prototype.nextCommand = function () { if (this._cmdQueue.length > 0) { - return this._cmdQueue.shift(); + var command = this._cmdQueue.shift(); + if(this._debug) { + console.log("RemoteScriptRunner received command: " + command); + } + return command; } return null; }; @@ -153,6 +158,9 @@ module.exports = function () { var arg = null; var type = event.type; + if(this._debug) { + console.log("RemoteScriptRunner fired event: " + type); + } switch (type) { case "NOTIFIED": arg = event.barrier; diff --git a/test/testFrameworks/mocha-k3po_spec.js b/test/testFrameworks/mocha-k3po_spec.js index 2abbf43..42cd5f9 100644 --- a/test/testFrameworks/mocha-k3po_spec.js +++ b/test/testFrameworks/mocha-k3po_spec.js @@ -20,10 +20,10 @@ describe('WsClient', function () { ws.onmessage = function (event) { chai.assert.equal(event.data, echoText); ws.close(); + done(); }; ws.onclose = ws.onerror = function () { - done(); }; });