Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bidi][js] Add high-level script pinning APIs #14250

Merged
merged 1 commit into from
Jul 11, 2024
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
Loading