Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions javascript/node/selenium-webdriver/lib/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ class Script {

await this.#script.removeCallback(id)
}

async pin(script) {
await this.#initScript()
return await this.#script.addPreloadScript(script)
}

async unpin(id) {
await this.#initScript()
await this.#script.removePreloadScript(id)
}
}

module.exports = Script
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,38 @@ suite(

assert.strictEqual(message, null)
})

it('can pin script', async function () {
await driver.script().pin("() => { console.log('Hello!'); }")
let log

await driver.script().addConsoleMessageHandler((logEntry) => {
log = logEntry
})

await driver.get(Pages.logEntryAdded)

await delay(3000)

assert.equal(log.text, 'Hello!')
})

it('can unpin script', async function () {
const id = await driver.script().pin("() => { console.log('Hello!'); }")

let count = 0
await driver.script().addConsoleMessageHandler((logEntry) => {
count++
})

await driver.get(Pages.logEntryAdded)

await driver.script().unpin(id)

await driver.get(Pages.logEntryAdded)

assert.equal(count, 1)
})
})
},
{ browsers: [Browser.FIREFOX, Browser.CHROME, Browser.EDGE] },
Expand Down