Skip to content

Commit

Permalink
renamed a few CDP commands and updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
beatfactor committed Jun 14, 2022
1 parent ae2ef2d commit 76f8f24
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const {Logger} = require('../../utils');
* @example
* this.demoTest = function (browser) {
* browser
* .captureConsoleLogs((event) => {
* .captureBrowserConsoleLogs((event) => {
* console.log(event.type, event.timestamp, event.args[0].value);
* })
* .navigateTo('https://www.google.com')
Expand All @@ -16,25 +16,27 @@ const {Logger} = require('../../utils');
* }, []);
* };
*
* @method captureConsoleLogs
* @syntax .captureConsoleLogs(callback)
* @method captureBrowserConsoleLogs
* @syntax .captureBrowserConsoleLogs(callback)
* @param {function} callback Callback function to be called when a new log is captured.
* @api protocol.sessions
* @api protocol.cdp
* @since 2.2.0
* @moreinfo nightwatchjs.org/guide/browser-drivers/geckodriver.html
*/
class StartCapturingLogs extends ClientCommand {

performAction(callback) {

if (!this.api.isChrome() && !this.api.isEdge()) {
const error = new Error('The command .captureConsoleLogs() is only supported in Chrome and Edge drivers');
const error = new Error('The command .captureBrowserConsoleLogs() is only supported in Chrome and Edge drivers');
Logger.error(error);

return callback(error);
}

const userCallback = this.userCallback;
if (userCallback === undefined) {
const error = new Error('Callback is missing from .captureConsoleLogs command.');
const error = new Error('Callback is missing from .captureBrowserConsoleLogs() command.');
Logger.error(error);

return callback(error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ const {Logger} = require('../../utils');
* Catch the JavaScript exceptions thrown in the browser.
*
* @example
* describe('catch errors', function() {
* describe('capture browser exceptions', function() {
* it('does', async function (browser) {
* await browser.catchJsExceptions((event) => {
* await browser.captureBrowserExceptions((event) => {
* console.log('>>> Exception:', event);
* });
*
Expand All @@ -22,25 +22,25 @@ const {Logger} = require('../../utils');
* });
* });
*
* @method catchJsExceptions
* @syntax .catchJsExceptions(callback)
* @param {function} callback Callback function to be called when a new expection has taken place.
* @method captureBrowserExceptions
* @syntax .captureBrowserExceptions(callback)
* @param {function} callback Callback function to be called when a new exception has taken place.
* @api protocol.sessions
*/
class CatchJsExceptions extends ClientCommand {

performAction(callback) {

if (!this.api.isChrome() && !this.api.isEdge()) {
const error = new Error('CatchJsExceptions is only supported in Chrome and Edge drivers');
if (!this.api.isChrome() && !this.api.isEdge()) {
const error = new Error('The command .captureBrowserExceptions() is only supported in Chrome and Edge drivers');
Logger.error(error);

return callback(error);
}

const userCallback = this.userCallback;
if (userCallback === undefined) {
const error = new Error('Callback is missing from .catchJsExceptions command.');
const error = new Error('Callback is missing from .captureBrowserExceptions() command.');
Logger.error(error);

return callback(error);
Expand Down
11 changes: 7 additions & 4 deletions lib/api/client-commands/enablePerformanceMetrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,20 @@ const {Logger} = require('../../utils');
* };
*
* @method enablePerformanceMetrics
* @syntax .enablePerformanceMetrics([enable, callback])
* @syntax .enablePerformanceMetrics([enable], [callback])
* @param {boolean} [enable] Optional Whether to enable or disable the performance metrics collection. Default: true
* @param {function} [callback] Optional callback function to be called when the command finishes.
* @api protocol.userprompts
* @api protocol.cdp
* @since 2.2.0
* @see https://chromedevtools.github.io/devtools-protocol/tot/Performance/
* @moreinfo www.selenium.dev/documentation/webdriver/bidirectional/chrome_devtools/#collect-performance-metrics
*/
class EnablePerformanceMetrics extends ClientCommand {

performAction(callback) {

if (!this.api.isChrome() && !this.api.isEdge()) {
const error = new Error('EnablePerformanceMetrics is only supported in Chrome and Edge drivers');
if (!this.api.isChrome() && !this.api.isEdge()) {
const error = new Error('.enablePerformanceMetrics() is only supported in Chrome and Edge drivers');
Logger.error(error);

return callback(error);
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
},
"peerDependencies": {
"@cucumber/cucumber": "*",
"chromedriver": "^102.0.0",
"chromedriver": "*",
"geckodriver": "*"
},
"peerDependenciesMeta": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const MockServer = require('../../../../lib/mockserver.js');
const Nightwatch = require('../../../../lib/nightwatch.js');
const cdp = require('../../../../../lib/transport/selenium-webdriver/cdp.js');

describe('.catchJsExceptions()', function () {
describe('.captureBrowserExceptions()', function () {
beforeEach(function (done) {
this.server = MockServer.init();

Expand All @@ -17,7 +17,7 @@ describe('.catchJsExceptions()', function () {
CommandGlobals.afterEach.call(this, done);
});

it('browser.catchJsExceptions(callback)', function (done) {
it('browser.captureBrowserExceptions(callback)', function (done) {

MockServer.addMock({
url: '/session',
Expand Down Expand Up @@ -57,7 +57,7 @@ describe('.catchJsExceptions()', function () {

//eslint-disable-next-line
const userCallback = (event) => {console.log(event)};
client.api.catchJsExceptions(userCallback, function () {
client.api.captureBrowserExceptions(userCallback, function () {
assert.strictEqual(expectedCdpConnection, undefined); // cdpConnection is mocked
assert.strictEqual(expectedUserCallback, userCallback);
});
Expand Down Expand Up @@ -91,16 +91,16 @@ describe('.catchJsExceptions()', function () {
output: process.env.VERBOSE === '1',
silent: false
}).then(client => {
client.api.catchJsExceptions(undefined, function (result){
client.api.captureBrowserExceptions(undefined, function (result){
assert.strictEqual(result.status, -1);
assert.strictEqual(result.error, 'Callback is missing from .catchJsExceptions command.');
assert.strictEqual(result.error, 'Callback is missing from .captureBrowserExceptions() command.');
});

client.start(done);
});
});

it('browser.catchJsExceptions - driver not supported', function(done){
it('browser.captureBrowserExceptions - driver not supported', function(done){
Nightwatch.initW3CClient({
desiredCapabilities: {
browserName: 'firefox'
Expand All @@ -111,9 +111,9 @@ describe('.catchJsExceptions()', function () {
//eslint-disable-next-line
const userCallback = (event) => {console.log(event)};

client.api.catchJsExceptions(userCallback, function(result){
client.api.captureBrowserExceptions(userCallback, function(result){
assert.strictEqual(result.status, -1);
assert.strictEqual(result.error, 'CatchJsExceptions is only supported in Chrome and Edge drivers');
assert.strictEqual(result.error, 'The command .captureBrowserExceptions() is only supported in Chrome and Edge drivers');
});
client.start(done);
});
Expand Down
16 changes: 8 additions & 8 deletions test/src/api/commands/client/testCaptureConsoleLogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const MockServer = require('../../../../lib/mockserver.js');
const Nightwatch = require('../../../../lib/nightwatch.js');
const cdp = require('../../../../../lib/transport/selenium-webdriver/cdp.js');

describe('.captureConsoleLogs()', function () {
describe('.captureBrowserConsoleLogs()', function () {
beforeEach(function (done) {
this.server = MockServer.init();

Expand All @@ -17,7 +17,7 @@ describe('.captureConsoleLogs()', function () {
CommandGlobals.afterEach.call(this, done);
});

it('browser.captureConsoleLogs()', function (done) {
it('browser.captureBrowserConsoleLogs()', function (done) {

MockServer.addMock({
url: '/session',
Expand Down Expand Up @@ -57,7 +57,7 @@ describe('.captureConsoleLogs()', function () {

//eslint-disable-next-line
const userCallback = (event) => {console.log(event)};
client.api.captureConsoleLogs(userCallback, function () {
client.api.captureBrowserConsoleLogs(userCallback, function () {
assert.strictEqual(expectedCdpConnection, undefined); // cdpConnection is mocked
assert.strictEqual(expectedUserCallback, userCallback);
});
Expand Down Expand Up @@ -91,16 +91,16 @@ describe('.captureConsoleLogs()', function () {
output: process.env.VERBOSE === '1',
silent: false
}).then(client => {
client.api.captureConsoleLogs(undefined, function (result){
client.api.captureBrowserConsoleLogs(undefined, function (result){
assert.strictEqual(result.status, -1);
assert.strictEqual(result.error, 'Callback is missing from .captureConsoleLogs command.');
assert.strictEqual(result.error, 'Callback is missing from .captureBrowserConsoleLogs() command.');
});

client.start(done);
});
});

it('browser.captureConsoleLogs - driver not supported', function(done){
it('browser.captureBrowserConsoleLogs - driver not supported', function(done){
Nightwatch.initW3CClient({
desiredCapabilities: {
browserName: 'firefox'
Expand All @@ -111,9 +111,9 @@ describe('.captureConsoleLogs()', function () {
//eslint-disable-next-line
const userCallback = (event) => {console.log(event)};

client.api.captureConsoleLogs(userCallback, function(result){
client.api.captureBrowserConsoleLogs(userCallback, function(result){
assert.strictEqual(result.status, -1);
assert.strictEqual(result.error, 'The command .captureConsoleLogs() is only supported in Chrome and Edge drivers');
assert.strictEqual(result.error, 'The command .captureBrowserConsoleLogs() is only supported in Chrome and Edge drivers');
});
client.start(done);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe('.enablePerformanceMetrics()', function () {
}).then(client => {
client.api.enablePerformanceMetrics(true, function(result){
assert.strictEqual(result.status, -1);
assert.strictEqual(result.error, 'EnablePerformanceMetrics is only supported in Chrome and Edge drivers');
assert.strictEqual(result.error, '.enablePerformanceMetrics() is only supported in Chrome and Edge drivers');
});
client.start(done);
});
Expand Down
2 changes: 1 addition & 1 deletion test/src/runner/testRunnerHtmlOutput.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const MockServer = require('../../lib/mockserver.js');

const {settings} = common;
const {runTests} = common.require('index.js');
const {readFilePromise, readDirPromise, rmFolder} = require('../../lib/utils.js');
const {readFilePromise, readDirPromise} = require('../../lib/utils.js');
const mkpath = require('mkpath');
const rimraf = require('rimraf');

Expand Down

0 comments on commit 76f8f24

Please sign in to comment.