-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathscript_events.spec.js
92 lines (70 loc) · 2.66 KB
/
script_events.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
const assert = require("assert")
const firefox = require('selenium-webdriver/firefox')
const {ScriptManager, BrowsingContext, Builder} = require("selenium-webdriver")
const {ArgumentValue} = require("selenium-webdriver/bidi/argumentValue")
const {RealmType} = require("selenium-webdriver/bidi/realmInfo")
const {LocalValue, ChannelValue} = require("selenium-webdriver/bidi/protocolValue")
const {EvaluateResultType} = require("selenium-webdriver/bidi/evaluateResult");
describe('Script events', function () {
let driver
beforeEach(async function () {
driver = new Builder()
.forBrowser('firefox')
.setFirefoxOptions(new firefox.Options().enableBidi())
.build()
})
afterEach(async function () {
await driver.quit()
})
it('can listen to channel message', async function () {
const manager = await ScriptManager(undefined, driver)
let message = null
await manager.onMessage((m) => {
message = m
})
let argumentValues = []
let value = new ArgumentValue(LocalValue.createChannelValue(new ChannelValue('channel_name')))
argumentValues.push(value)
const result = await manager.callFunctionInBrowsingContext(
await driver.getWindowHandle(),
'(channel) => channel("foo")',
false,
argumentValues,
)
assert.equal(result.resultType, EvaluateResultType.SUCCESS)
assert.notEqual(message, null)
assert.equal(message.channel, 'channel_name')
assert.equal(message.data.type, 'string')
assert.equal(message.data.value, 'foo')
})
it('can listen to realm created message', async function () {
const manager = await ScriptManager(undefined, driver)
let realmInfo = null
await manager.onRealmCreated((result) => {
realmInfo = result
})
const id = await driver.getWindowHandle()
const browsingContext = await BrowsingContext(driver, {
browsingContextId: id,
})
await browsingContext.navigate('https://www.selenium.dev/selenium/web/blank', 'complete')
assert.notEqual(realmInfo, null)
assert.notEqual(realmInfo.realmId, null)
assert.equal(realmInfo.realmType, RealmType.WINDOW)
})
xit('can listen to realm destroyed message', async function () {
const manager = await ScriptManager(undefined, driver)
let realmInfo = null
await manager.onRealmDestroyed((result) => {
realmInfo = result
})
const id = await driver.getWindowHandle()
const browsingContext = await BrowsingContext(driver, {
browsingContextId: id,
})
await browsingContext.close()
assert.notEqual(realmInfo, null)
assert.notEqual(realmInfo.realmId, null)
assert.equal(realmInfo.realmType, RealmType.WINDOW)
})
})