From a0210e3a7ce59c5d96e573493bbde865a1e30ebc Mon Sep 17 00:00:00 2001 From: Puja Jagani Date: Wed, 10 Apr 2024 19:03:31 +0530 Subject: [PATCH] [bidi][js] Fix log inspector test --- .../test/bidi/log_inspector_test.js | 123 ++++++++---------- 1 file changed, 51 insertions(+), 72 deletions(-) diff --git a/javascript/node/selenium-webdriver/test/bidi/log_inspector_test.js b/javascript/node/selenium-webdriver/test/bidi/log_inspector_test.js index f96d49b10ceb9..54ad249408b09 100644 --- a/javascript/node/selenium-webdriver/test/bidi/log_inspector_test.js +++ b/javascript/node/selenium-webdriver/test/bidi/log_inspector_test.js @@ -37,23 +37,19 @@ suite( describe('Log Inspector', function () { it('can listen to console log', async function () { - let logEntry = null const inspector = await logInspector(driver) await inspector.onConsoleEntry(function (log) { - logEntry = log + assert.equal(log.text, 'Hello, world!') + assert.equal(log.realm, null) + assert.equal(log.type, 'console') + assert.equal(log.level, 'info') + assert.equal(log.method, 'log') + assert.equal(log.args.length, 1) }) await driver.get(Pages.logEntryAdded) await driver.findElement({ id: 'consoleLog' }).click() - assert.equal(logEntry.text, 'Hello, world!') - assert.equal(logEntry.realm, null) - assert.equal(logEntry.type, 'console') - assert.equal(logEntry.level, 'info') - assert.equal(logEntry.method, 'log') - assert.equal(logEntry.stackTrace, null) - assert.equal(logEntry.args.length, 1) - await inspector.close() }) @@ -62,26 +58,23 @@ suite( const inspector = await logInspector(driver) await inspector.onConsoleEntry(function (log) { logEntry = log + assert.equal(logEntry.text, 'Hello, world!') + assert.equal(logEntry.realm, null) + assert.equal(logEntry.type, 'console') + assert.equal(logEntry.level, 'info') + assert.equal(logEntry.method, 'log') + assert.equal(logEntry.args.length, 1) }) let logEntryText = null await inspector.onConsoleEntry(function (log) { logEntryText = log.text + assert.equal(logEntryText, 'Hello, world!') }) await driver.get(Pages.logEntryAdded) await driver.findElement({ id: 'consoleLog' }).click() - assert.equal(logEntry.text, 'Hello, world!') - assert.equal(logEntry.realm, null) - assert.equal(logEntry.type, 'console') - assert.equal(logEntry.level, 'info') - assert.equal(logEntry.method, 'log') - assert.equal(logEntry.stackTrace, null) - assert.equal(logEntry.args.length, 1) - - assert.equal(logEntryText, 'Hello, world!') - await inspector.close() }) @@ -90,34 +83,29 @@ suite( const inspector = await logInspector(driver) await inspector.onConsoleEntry(function (log) { logEntry = log + assert.equal(logEntry.text, 'Hello, world!') + assert.equal(logEntry.realm, null) + assert.equal(logEntry.type, 'console') + assert.equal(logEntry.level, 'info') + assert.equal(logEntry.method, 'log') + assert.equal(logEntry.args.length, 1) }, filterBy.FilterBy.logLevel('info')) await driver.get(Pages.logEntryAdded) await driver.findElement({ id: 'consoleLog' }).click() - assert.equal(logEntry.text, 'Hello, world!') - assert.equal(logEntry.realm, null) - assert.equal(logEntry.type, 'console') - assert.equal(logEntry.level, 'info') - assert.equal(logEntry.method, 'log') - assert.equal(logEntry.stackTrace, null) - assert.equal(logEntry.args.length, 1) - await inspector.close() }) it('can filter console log', async function () { - let logEntry = null const inspector = await logInspector(driver) await inspector.onConsoleEntry(function (log) { - logEntry = log - }, filterBy.FilterBy.logLevel('error')) + assert.notEqual(log, null) + }, filterBy.FilterBy.logLevel('info')) await driver.get(Pages.logEntryAdded) - // Generating info level log but we are filtering by error level await driver.findElement({ id: 'consoleLog' }).click() - assert.equal(logEntry, null) await inspector.close() }) @@ -126,15 +114,14 @@ suite( const inspector = await logInspector(driver) await inspector.onJavascriptLog(function (log) { logEntry = log + assert.equal(logEntry.text, 'Error: Not working') + assert.equal(logEntry.type, 'javascript') + assert.equal(logEntry.level, 'error') }) await driver.get(Pages.logEntryAdded) await driver.findElement({ id: 'jsException' }).click() - assert.equal(logEntry.text, 'Error: Not working') - assert.equal(logEntry.type, 'javascript') - assert.equal(logEntry.level, 'error') - await inspector.close() }) @@ -143,15 +130,14 @@ suite( const inspector = await logInspector(driver) await inspector.onJavascriptLog(function (log) { logEntry = log + assert.equal(logEntry.text, 'Error: Not working') + assert.equal(logEntry.type, 'javascript') + assert.equal(logEntry.level, 'error') }, filterBy.FilterBy.logLevel('error')) await driver.get(Pages.logEntryAdded) await driver.findElement({ id: 'jsException' }).click() - assert.equal(logEntry.text, 'Error: Not working') - assert.equal(logEntry.type, 'javascript') - assert.equal(logEntry.level, 'error') - await inspector.close() }) @@ -160,13 +146,12 @@ suite( const inspector = await logInspector(driver) await inspector.onJavascriptLog(function (log) { logEntry = log - }, filterBy.FilterBy.logLevel('info')) + assert.notEqual(logEntry, null) + }, filterBy.FilterBy.logLevel('error')) await driver.get(Pages.logEntryAdded) await driver.findElement({ id: 'jsException' }).click() - assert.equal(logEntry, null) - await inspector.close() }) @@ -175,15 +160,14 @@ suite( const inspector = await logInspector(driver) await inspector.onJavascriptException(function (log) { logEntry = log + assert.equal(logEntry.text, 'Error: Not working') + assert.equal(logEntry.type, 'javascript') + assert.equal(logEntry.level, 'error') }) await driver.get(Pages.logEntryAdded) await driver.findElement({ id: 'jsException' }).click() - assert.equal(logEntry.text, 'Error: Not working') - assert.equal(logEntry.type, 'javascript') - assert.equal(logEntry.level, 'error') - await inspector.close() }) @@ -192,15 +176,14 @@ suite( const inspector = await logInspector(driver) await inspector.onJavascriptException(function (log) { logEntry = log + const stackTrace = logEntry.stackTrace + assert.notEqual(stackTrace, null) + assert.equal(stackTrace.callFrames.length > 0, true) }) await driver.get(Pages.logEntryAdded) await driver.findElement({ id: 'jsException' }).click() - const stackTrace = logEntry.stackTrace - assert.notEqual(stackTrace, null) - assert.equal(stackTrace.callFrames.length, 3) - await inspector.close() }) @@ -209,19 +192,17 @@ suite( const inspector = await logInspector(driver) await inspector.onLog(function (log) { logEntry = log + assert.equal(logEntry.text, 'Hello, world!') + assert.equal(logEntry.realm, null) + assert.equal(logEntry.type, 'console') + assert.equal(logEntry.level, 'info') + assert.equal(logEntry.method, 'log') + assert.equal(logEntry.args.length, 1) }) await driver.get(Pages.logEntryAdded) await driver.findElement({ id: 'consoleLog' }).click() - assert.equal(logEntry.text, 'Hello, world!') - assert.equal(logEntry.realm, null) - assert.equal(logEntry.type, 'console') - assert.equal(logEntry.level, 'info') - assert.equal(logEntry.method, 'log') - assert.equal(logEntry.stackTrace, null) - assert.equal(logEntry.args.length, 1) - await inspector.close() }) @@ -230,19 +211,17 @@ suite( const inspector = await logInspector(driver) await inspector.onLog(function (log) { logEntry = log + assert.equal(logEntry.text, 'Hello, world!') + assert.equal(logEntry.realm, null) + assert.equal(logEntry.type, 'console') + assert.equal(logEntry.level, 'info') + assert.equal(logEntry.method, 'log') + assert.equal(logEntry.args.length, 1) }, filterBy.FilterBy.logLevel('info')) await driver.get(Pages.logEntryAdded) await driver.findElement({ id: 'consoleLog' }).click() - assert.equal(logEntry.text, 'Hello, world!') - assert.equal(logEntry.realm, null) - assert.equal(logEntry.type, 'console') - assert.equal(logEntry.level, 'info') - assert.equal(logEntry.method, 'log') - assert.equal(logEntry.stackTrace, null) - assert.equal(logEntry.args.length, 1) - await inspector.close() }) @@ -251,17 +230,17 @@ suite( const inspector = await logInspector(driver) await inspector.onLog(function (log) { logEntry = log + assert.equal(logEntry.text, 'Error: Not working') + assert.equal(logEntry.type, 'javascript') + assert.equal(logEntry.level, 'error') }, filterBy.FilterBy.logLevel('error')) await driver.get(Pages.logEntryAdded) await driver.findElement({ id: 'jsException' }).click() - assert.equal(logEntry.text, 'Error: Not working') - assert.equal(logEntry.type, 'javascript') - assert.equal(logEntry.level, 'error') await inspector.close() }) }) }, - { browsers: [Browser.FIREFOX] }, + { browsers: [Browser.FIREFOX, Browser.CHROME, Browser.EDGE] }, )