From 14291aff1756018dab21964e1d900e95a899f719 Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Fri, 27 Feb 2015 16:58:27 -0800 Subject: [PATCH 1/2] Fix phantomjs timeout issue when there is already a phantomjs process on the same port --- lib/uac/GhostDriverUac.js | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/uac/GhostDriverUac.js b/lib/uac/GhostDriverUac.js index 8658dbd..daae63e 100644 --- a/lib/uac/GhostDriverUac.js +++ b/lib/uac/GhostDriverUac.js @@ -21,6 +21,7 @@ var webdriver = require('selenium-webdriver'), log = require('../util/logger'), + portscanner = require('portscanner'), deferred = require('deferred'), fsHelper = require('../util/fsHelper'), spawn = require('child_process').spawn, @@ -31,21 +32,11 @@ var webdriver = require('selenium-webdriver'), * @param {Object} options */ function GhostDriverUac(options) { - this.host = options.host || 'http://localhast'; + this.host = options.host || 'localhost'; this.port = options.port || 8910; - this.server = [ - this.host || 'http://localhost', - ':', - this.port - ].join(''); - this.startAttempts = 0; - if (this.server.indexOf('http://') !== 0) { - this.server = 'http://' + this.server; - } - if (options && options.binaryPath) { this.binaryPath = fsHelper.getFirstValidPath(options.binaryPath); } @@ -67,11 +58,19 @@ GhostDriverUac.prototype.start = function () { // First, try to kill other phantomjs processes spawn('killall', ['-9', 'phantomjs']).on('exit', function () { // Now, go ahead and start a new phantomjs process - spawnPhantom.call(this); + portscanner.findAPortNotInUse(this.port, + this.port + 2000, + this.host, + function(err, port) { + this.port = port; + this.server = 'http://' + this.host + ':' + this.port; + log.debug('Trying to create PhontamJS Selenium server at', this.server); + spawnPhantom.call(this); + }.bind(this)); }.bind(this)); function spawnPhantom () { - this.process = spawn(binary, ['--webdriver=' + this.options.port]); + this.process = spawn(binary, ['--webdriver=' + this.port]); this.process.on('exit', function (code) { // Invalid phantomjs path From 2b7824eaf083ca281d4fc308e5886a74c62802a9 Mon Sep 17 00:00:00 2001 From: Geoff Berger Date: Wed, 4 Mar 2015 11:08:14 -0800 Subject: [PATCH 2/2] allowed for VenusTestList to be referenced in the proper window context tightened up logic to make sure VenusClientLibrary.js is really working adding venus related mocks added mocks to default includes added simple and silly fixture for VenusClientLibrary added test to make sure VenusTestList.postTestReults is actually being called --- js/runner_client/VenusClientLibrary.js | 10 ++++--- test/unit/client/.venus/config | 8 ++++++ test/unit/client/.venus/mocks/venus.js | 3 +++ .../unit/client/.venus/mocks/venusTestList.js | 3 +++ .../VenusClientLibrary.fixture.html | 1 + .../runner_client/VenusClientLibrary.spec.js | 26 +++++++++++++++---- 6 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 test/unit/client/.venus/mocks/venus.js create mode 100644 test/unit/client/.venus/mocks/venusTestList.js create mode 100644 test/unit/client/runner_client/VenusClientLibrary.fixture.html diff --git a/js/runner_client/VenusClientLibrary.js b/js/runner_client/VenusClientLibrary.js index ea98a20..1577624 100644 --- a/js/runner_client/VenusClientLibrary.js +++ b/js/runner_client/VenusClientLibrary.js @@ -56,10 +56,12 @@ VenusClientLibrary.prototype.done = function(results) { // decorate the test results with metadata results.userAgent = window.navigator.userAgent; - results.codeCoverageData = sandbox.contentWindow.__coverage__; + results.codeCoverageData = sandbox.contentWindow && sandbox.contentWindow.__coverage__; results.testId = window.venus.testId; - this.socket.emit('results', results); + if (this.socket) { + this.socket.emit('results', results); + } // append the test results to the document doneEl.id = 'test-done-marker'; @@ -67,8 +69,8 @@ VenusClientLibrary.prototype.done = function(results) { $(document).trigger('results', results); - if (window.VenusTestList) { - VenusTestList.postTestResults(results); + if (window.parent && window.parent.VenusTestList && window.parent.VenusTestList.postTestResults) { + window.parent.VenusTestList.postTestResults(results); } }; diff --git a/test/unit/client/.venus/config b/test/unit/client/.venus/config index 107274d..ba82988 100644 --- a/test/unit/client/.venus/config +++ b/test/unit/client/.venus/config @@ -1,5 +1,13 @@ { basePaths: { 'runnerClient': '../../../../js/runner_client' + }, + + includes: { + default: [ + '../../../../js/jquery/jquery-1.10.0.min.js', + 'mocks/venusTestList.js', + 'mocks/venus.js' + ] } } diff --git a/test/unit/client/.venus/mocks/venus.js b/test/unit/client/.venus/mocks/venus.js new file mode 100644 index 0000000..e36dc57 --- /dev/null +++ b/test/unit/client/.venus/mocks/venus.js @@ -0,0 +1,3 @@ +window.venus = window.venus || { + testId: 1 +}; diff --git a/test/unit/client/.venus/mocks/venusTestList.js b/test/unit/client/.venus/mocks/venusTestList.js new file mode 100644 index 0000000..d0df45b --- /dev/null +++ b/test/unit/client/.venus/mocks/venusTestList.js @@ -0,0 +1,3 @@ +window.parent.VenusTestList = window.parent.VenusTestList || { + postTestResults: function() {} +}; diff --git a/test/unit/client/runner_client/VenusClientLibrary.fixture.html b/test/unit/client/runner_client/VenusClientLibrary.fixture.html new file mode 100644 index 0000000..f20447e --- /dev/null +++ b/test/unit/client/runner_client/VenusClientLibrary.fixture.html @@ -0,0 +1 @@ +
diff --git a/test/unit/client/runner_client/VenusClientLibrary.spec.js b/test/unit/client/runner_client/VenusClientLibrary.spec.js index aa70021..5353c7b 100644 --- a/test/unit/client/runner_client/VenusClientLibrary.spec.js +++ b/test/unit/client/runner_client/VenusClientLibrary.spec.js @@ -1,17 +1,33 @@ /** + * @venus-fixture VenusClientLibrary.fixture.html * @venus-code runnerClient/VenusClientLibrary.js */ describe('VenusClientLibrary', function() { + function createInstance() { + return new VenusClientLibrary({ + host: 'www.example.com', + port: 1234 + }); + } + it('should expect on the window as VenusClientLibrary', function() { expect(window.VenusClientLibrary).to.be.ok(); }); it('should instantiate a new VenusClientLibrary object', function() { - var venusClientLibrary = new VenusClientLibrary({ - host: 'www.example.com', - port: 1234 - }); + expect(createInstance()).to.be.a(VenusClientLibrary); + }); + + describe('.done()', function() { + it('should execute VenusTestList.postTestReults from the parent context', sinon.test(function() { + var instance = createInstance(), + resultsStub = this.stub(window.parent.VenusTestList, 'postTestResults'), + results = { + band: 'Godspeed You! Black Emperor' + }; - expect(venusClientLibrary).to.be.a(VenusClientLibrary); + instance.done(results); + sinon.assert.calledWith(resultsStub, sinon.match(results)); + })); }); });