Skip to content

Commit

Permalink
[bidi][js] Add high-level script pinning APIs (#14250)
Browse files Browse the repository at this point in the history
  • Loading branch information
pujagani authored Jul 11, 2024
1 parent 0f68841 commit 7334bfc
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
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

0 comments on commit 7334bfc

Please sign in to comment.