diff --git a/lib/runner/test-runners/default.js b/lib/runner/test-runners/default.js index 5d9289bc71..2b0f3f17bd 100644 --- a/lib/runner/test-runners/default.js +++ b/lib/runner/test-runners/default.js @@ -48,7 +48,9 @@ class DefaultRunner { if (this.client && this.client.sessionId && this.client.startSessionEnabled) { Logger.info(`Attempting to close session ${this.client.sessionId}...`); - return this.currentSuite.terminate(null, null, true); + const failures = !this.currentSuite.reporter.allTestsPassed; + + return this.currentSuite.terminate(failures ? 'FAILED' : '', null, true); } return Promise.resolve(); diff --git a/lib/transport/selenium-webdriver/index.js b/lib/transport/selenium-webdriver/index.js index a039c2e3fd..fac23ca2f1 100644 --- a/lib/transport/selenium-webdriver/index.js +++ b/lib/transport/selenium-webdriver/index.js @@ -7,6 +7,7 @@ const {Logger, isObject, IosSessionNotCreatedError, AndroidConnectionError} = re const httpClient = require('./httpclient.js'); const Session = require('./session.js'); const BaseTransport = require('../'); +const CDP = require('./cdp.js'); const {colors} = Logger; const {isErrorResponse, checkLegacyResponse, throwDecodedError, WebDriverError} = error; @@ -187,7 +188,7 @@ class Transport extends BaseTransport { async sessionFinished(reason) { this.emit('session:finished', reason); - + CDP.resetConnection(); await this.closeDriver(); } diff --git a/test/apidemos/cdp/registerAuth.js b/test/apidemos/cdp/registerAuth.js new file mode 100644 index 0000000000..b2d096ac4b --- /dev/null +++ b/test/apidemos/cdp/registerAuth.js @@ -0,0 +1,6 @@ +describe('cdp tests', function() { + it('register basic auth', function() { + browser.registerBasicAuth('admin', 'admin') + .navigateTo('http://localhost'); + }); +}); \ No newline at end of file diff --git a/test/apidemos/cdp/registerAuth2.js b/test/apidemos/cdp/registerAuth2.js new file mode 100644 index 0000000000..b2d096ac4b --- /dev/null +++ b/test/apidemos/cdp/registerAuth2.js @@ -0,0 +1,6 @@ +describe('cdp tests', function() { + it('register basic auth', function() { + browser.registerBasicAuth('admin', 'admin') + .navigateTo('http://localhost'); + }); +}); \ No newline at end of file diff --git a/test/lib/command-mocks.js b/test/lib/command-mocks.js index 6ec31edc30..57ba27081f 100644 --- a/test/lib/command-mocks.js +++ b/test/lib/command-mocks.js @@ -448,7 +448,7 @@ module.exports = { sessionId, capabilities: { acceptInsecureCerts: false, - browserName: 'firefox', + browserName, browserVersion: '65.0.1' } } diff --git a/test/src/apidemos/cdp/testCdpCommands.js b/test/src/apidemos/cdp/testCdpCommands.js new file mode 100644 index 0000000000..90e45ca6d1 --- /dev/null +++ b/test/src/apidemos/cdp/testCdpCommands.js @@ -0,0 +1,81 @@ +const path = require('path'); +const assert = require('assert'); +const MockServer = require('../../../lib/mockserver.js'); +const Mocks = require('../../../lib/command-mocks'); + +const mockery = require('mockery'); +const common = require('../../../common.js'); +const {settings} = common; +const NightwatchClient = common.require('index.js'); + +describe('cdp commands test', function() { + beforeEach(function(done) { + mockery.enable({useCleanCache: true, warnOnReplace: false, warnOnUnregistered: false}); + this.server = MockServer.init(); + this.server.on('listening', () => { + done(); + }); + }); + + afterEach(function(done) { + mockery.deregisterAll(); + mockery.resetCache(); + mockery.disable(); + this.server.close(function() { + done(); + }); + }); + + it('reset cdp connection after each session', function() { + const testsPath = [path.join(__dirname, '../../../apidemos/cdp')]; + let resetConnectionCalled = false; + + mockery.registerMock('./cdp.js', { + getConnection: function(...args) { + return Promise.resolve(); + }, + resetConnection: function() { + resetConnectionCalled = true; + } + }); + + Mocks + .createNewW3CSession({ + persist: true, + browserName: 'chrome', + postdata: { + capabilities: {firstMatch: [{}], alwaysMatch: {browserName: 'chrome', 'goog:chromeOptions': {}}} + } + }) + .navigateTo({url: 'http://localhost', persist: true}); + + + + const globals = { + calls: 0, + waitForConditionPollInterval: 50, + waitForConditionTimeout: 120, + retryAssertionTimeout: 1000, + + + reporter(results) { + assert.strictEqual(resetConnectionCalled, true); + if (results.lastError) { + throw results.lastError; + } + } + }; + + return NightwatchClient.runTests(testsPath, settings({ + desiredCapabilities: { + browserName: 'chrome' + }, + selenium_host: null, + output: false, + skip_testcases_on_fail: false, + globals + })); + }); + + +});