Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes/3574 fix end session on fail flag #3594

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/runner/test-runners/default.js
Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion lib/transport/selenium-webdriver/index.js
Expand Up @@ -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;

Expand Down Expand Up @@ -187,7 +188,7 @@ class Transport extends BaseTransport {

async sessionFinished(reason) {
this.emit('session:finished', reason);

CDP.resetConnection();
await this.closeDriver();
}

Expand Down
6 changes: 6 additions & 0 deletions 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');
});
});
6 changes: 6 additions & 0 deletions 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');
});
});
2 changes: 1 addition & 1 deletion test/lib/command-mocks.js
Expand Up @@ -448,7 +448,7 @@ module.exports = {
sessionId,
capabilities: {
acceptInsecureCerts: false,
browserName: 'firefox',
browserName,
browserVersion: '65.0.1'
}
}
Expand Down
81 changes: 81 additions & 0 deletions 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
}));
});


});