From e321e7c31b6d9d23d4477820e4be236c3760bfa8 Mon Sep 17 00:00:00 2001 From: Puja Jagani Date: Wed, 7 Aug 2024 17:28:18 +0530 Subject: [PATCH] [bidi] Separate examples module wise --- .../test/bidirectional/w3c/log.spec.js | 68 -------------- .../test/bidirectional/w3c/script.spec.js | 93 +++++++++++++++++++ 2 files changed, 93 insertions(+), 68 deletions(-) create mode 100644 examples/javascript/test/bidirectional/w3c/script.spec.js diff --git a/examples/javascript/test/bidirectional/w3c/log.spec.js b/examples/javascript/test/bidirectional/w3c/log.spec.js index e83be359c846..41ca36fb8040 100644 --- a/examples/javascript/test/bidirectional/w3c/log.spec.js +++ b/examples/javascript/test/bidirectional/w3c/log.spec.js @@ -84,74 +84,6 @@ describe('BiDi Logging', function () { assert.equal(log, null) }) - - it('can listen to dom mutations', async function () { - let message = null - await driver.script().addDomMutationHandler((m) => { - message = m - }) - - await driver.get('https://www.selenium.dev/selenium/web/dynamic') - - let element = driver.findElement({ id: 'reveal' }) - await element.click() - let revealed = driver.findElement({ id: 'revealed' }) - await driver.wait(until.elementIsVisible(revealed), 5000) - - assert.strictEqual(message['attribute_name'], 'style') - assert.strictEqual(message['current_value'], '') - assert.strictEqual(message['old_value'], 'display:none;') - }) - - it('can remove to dom mutation handler', async function () { - let message = null - let id = await driver.script().addDomMutationHandler((m) => { - message = m - }) - - await driver.script().removeDomMutationHandler(id) - - await driver.get('https://www.selenium.dev/selenium/web/dynamic') - - let element = driver.findElement({ id: 'reveal' }) - await element.click() - let revealed = driver.findElement({ id: 'revealed' }) - await driver.wait(until.elementIsVisible(revealed), 5000) - - 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('https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html') - - 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('https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html') - - await driver.script().unpin(id) - - await driver.get('https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html') - - assert.equal(count, 1) - }) }) diff --git a/examples/javascript/test/bidirectional/w3c/script.spec.js b/examples/javascript/test/bidirectional/w3c/script.spec.js new file mode 100644 index 000000000000..7b29ba4a65be --- /dev/null +++ b/examples/javascript/test/bidirectional/w3c/script.spec.js @@ -0,0 +1,93 @@ + +const assert = require("assert"); +const firefox = require('selenium-webdriver/firefox'); +const {until, Builder} = require("selenium-webdriver"); + +let driver + +beforeEach(async function () { + driver = new Builder() + .setFirefoxOptions(new firefox.Options().enableBidi()) + .build() +}) + +afterEach(async function () { + await driver.quit() +}) + +function delay(ms) { + return new Promise((resolve) => setTimeout(resolve, ms)) +} + +describe('BiDi Script', function () { + + it('can listen to dom mutations', async function () { + let message = null + await driver.script().addDomMutationHandler((m) => { + message = m + }) + + await driver.get('https://www.selenium.dev/selenium/web/dynamic') + + let element = driver.findElement({ id: 'reveal' }) + await element.click() + let revealed = driver.findElement({ id: 'revealed' }) + await driver.wait(until.elementIsVisible(revealed), 5000) + + assert.strictEqual(message['attribute_name'], 'style') + assert.strictEqual(message['current_value'], '') + assert.strictEqual(message['old_value'], 'display:none;') + }) + + it('can remove to dom mutation handler', async function () { + let message = null + let id = await driver.script().addDomMutationHandler((m) => { + message = m + }) + + await driver.script().removeDomMutationHandler(id) + + await driver.get('https://www.selenium.dev/selenium/web/dynamic') + + let element = driver.findElement({ id: 'reveal' }) + await element.click() + let revealed = driver.findElement({ id: 'revealed' }) + await driver.wait(until.elementIsVisible(revealed), 5000) + + 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('https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html') + + 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('https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html') + + await driver.script().unpin(id) + + await driver.get('https://www.selenium.dev/selenium/web/bidi/logEntryAdded.html') + + assert.equal(count, 1) + }) +}) + +