Skip to content

Commit 750f683

Browse files
authored
[js] Fix failing javascript tests (#17293)
* fix failing test "can unpin script" in "webdriver_script_test.js" it seems that FireFox can call pinned JS script two or three times. In this test, the exact count is not important - it's enough to verify that the script was called at least once. * remove unneeded delays in "webdriver_script_test.js" it seems that we don't need to wait: the usual "await driver.get(...)" already does it.
1 parent 45db0c0 commit 750f683

1 file changed

Lines changed: 9 additions & 15 deletions

File tree

‎javascript/selenium-webdriver/test/lib/webdriver_script_test.js‎

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ suite(
3535
await driver.quit()
3636
})
3737

38-
function delay(ms) {
39-
return new Promise((resolve) => setTimeout(resolve, ms))
40-
}
41-
4238
describe('script()', function () {
4339
it('can listen to console log', async function () {
4440
let log = null
@@ -49,8 +45,6 @@ suite(
4945
await driver.get(Pages.logEntryAdded)
5046
await driver.findElement({ id: 'consoleLog' }).click()
5147

52-
await delay(3000)
53-
5448
assert.equal(log.text, 'Hello, world!')
5549
assert.equal(log.realm, null)
5650
assert.equal(log.type, 'console')
@@ -69,8 +63,6 @@ suite(
6963
await driver.get(Pages.logEntryAdded)
7064
await driver.findElement({ id: 'jsException' }).click()
7165

72-
await delay(3000)
73-
7466
assert.equal(log.text, 'Error: Not working')
7567
assert.equal(log.type, 'javascript')
7668
assert.equal(log.level, 'error')
@@ -133,26 +125,28 @@ suite(
133125

134126
await driver.get(Pages.logEntryAdded)
135127

136-
await delay(3000)
137-
138128
assert.equal(log.text, 'Hello!')
139129
})
140130

141131
it('can unpin script', async function () {
142-
const id = await driver.script().pin("() => { console.log('Hello!'); }")
132+
const id = await driver.script().pin("() => { console.log('Hello'); }")
133+
await driver.script().pin("() => { console.log('World'); }")
143134

144-
let count = 0
135+
const logs = []
145136
await driver.script().addConsoleMessageHandler((logEntry) => {
146-
count++
137+
logs.push(logEntry.text)
147138
})
148139

149140
await driver.get(Pages.logEntryAdded)
141+
assert.ok(logs.includes('Hello'), `[${logs}] should contain "Hello"`)
142+
assert.ok(logs.includes('World'), `[${logs}] should contain "World"`)
150143

151144
await driver.script().unpin(id)
152145

146+
logs.length = 0
153147
await driver.get(Pages.logEntryAdded)
154-
155-
assert.equal(count, 1)
148+
assert.ok(logs.includes('World'), `[${logs}] should contain "World"`)
149+
assert.ok(!logs.includes('Hello'), `[${logs}] should not contain "Hello"`)
156150
})
157151
})
158152
},

0 commit comments

Comments
 (0)