Skip to content

Commit

Permalink
[bidi][js] Fix log inspector test
Browse files Browse the repository at this point in the history
  • Loading branch information
pujagani committed Apr 10, 2024
1 parent 33c6b78 commit a0210e3
Showing 1 changed file with 51 additions and 72 deletions.
123 changes: 51 additions & 72 deletions javascript/node/selenium-webdriver/test/bidi/log_inspector_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})

Expand All @@ -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()
})

Expand All @@ -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()
})

Expand All @@ -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()
})

Expand All @@ -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()
})

Expand All @@ -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()
})

Expand All @@ -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()
})

Expand All @@ -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()
})

Expand All @@ -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()
})

Expand All @@ -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()
})

Expand All @@ -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] },
)

0 comments on commit a0210e3

Please sign in to comment.