-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathlogInspector.spec.js
100 lines (79 loc) · 3.01 KB
/
logInspector.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
const assert = require("assert");
const firefox = require('selenium-webdriver/firefox');
const LogInspector = require('selenium-webdriver/bidi/logInspector');
const {Builder} = require("selenium-webdriver");
describe('Log Inspector', function () {
let driver
beforeEach(async function () {
driver = new Builder()
.forBrowser('firefox')
.setFirefoxOptions(new firefox.Options().enableBidi())
.build()
})
afterEach(async function () {
await driver.quit()
})
it('test listen to console log', async function () {
let logEntry = null
const inspector = await LogInspector(driver)
await inspector.onConsoleEntry(function (log) {
logEntry = log
})
await driver.get('https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html')
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('test listen to javascript error log', async function () {
let logEntry = null
const inspector = await LogInspector(driver)
await inspector.onJavascriptException(function (log) {
logEntry = log
})
await driver.get('https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html')
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()
})
it('test retrieve stack trace for a log', async function () {
let logEntry = null
const inspector = await LogInspector(driver)
await inspector.onJavascriptException(function (log) {
logEntry = log
})
await driver.get('https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html')
await driver.findElement({id: 'jsException'}).click()
const stackTrace = logEntry.stackTrace
assert.notEqual(stackTrace, null)
assert.equal(stackTrace.callFrames.length, 3)
await inspector.close()
})
it('test listen to logs with multiple consumers', async function () {
let logEntry1 = null
let logEntry2 = null
const inspector = await LogInspector(driver)
await inspector.onJavascriptException(function (log) {
logEntry1 = log
})
await inspector.onJavascriptException(function (log) {
logEntry2 = log
})
await driver.get('https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html')
await driver.findElement({id: 'jsException'}).click()
assert.equal(logEntry1.text, 'Error: Not working')
assert.equal(logEntry1.type, 'javascript')
assert.equal(logEntry1.level, 'error')
assert.equal(logEntry2.text, 'Error: Not working')
assert.equal(logEntry2.type, 'javascript')
assert.equal(logEntry2.level, 'error')
await inspector.close()
})
})