Skip to content

Commit

Permalink
[bidi][js] Add Input module JS command
Browse files Browse the repository at this point in the history
  • Loading branch information
pujagani committed Jan 10, 2024
1 parent 12a9967 commit d51c74a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 9 deletions.
10 changes: 10 additions & 0 deletions javascript/node/selenium-webdriver/bidi/input.js
Expand Up @@ -47,6 +47,16 @@ class Input {

return response
}

async release(browsingContextId) {
const command = {
method: 'input.releaseActions',
params: {
context: browsingContextId,
},
}
return await this.bidi.send(command)
}
}

async function updateActions(actions) {
Expand Down
1 change: 1 addition & 0 deletions javascript/node/selenium-webdriver/lib/test/fileserver.js
Expand Up @@ -115,6 +115,7 @@ const Pages = (function () {
addPage('emptyPage', 'bidi/emptyPage.html')
addPage('emptyText', 'bidi/emptyText.txt')
addPage('redirectedHttpEquiv', 'bidi/redirected_http_equiv.html')
addPage('releaseAction', 'bidi/release_action.html')

return pages
})()
Expand Down
46 changes: 37 additions & 9 deletions javascript/node/selenium-webdriver/test/bidi/input_test.js
Expand Up @@ -20,9 +20,9 @@
const assert = require('assert')
const fileServer = require('../../lib/test/fileserver')
const firefox = require('../../firefox')
const { ignore, Pages, suite } = require('../../lib/test')
const { Key, Origin } = require('../../lib/input')
const { Browser, By, until } = require('../..')
const {ignore, Pages, suite} = require('../../lib/test')
const {Key, Origin} = require('../../lib/input')
const {Browser, By, until} = require('../..')
const Input = require('../../bidi/input')

suite(
Expand Down Expand Up @@ -66,7 +66,7 @@ suite(

const div = await driver.findElement(By.css('div'))
const rect = await div.getRect()
assert.deepStrictEqual(rect, { width: 500, height: 500, x: 0, y: 0 })
assert.deepStrictEqual(rect, {width: 500, height: 500, x: 0, y: 0})

const actions = await driver.actions().click(div).getSequences()

Expand All @@ -91,11 +91,11 @@ suite(

const div = await driver.findElement(By.css('div'))
const rect = await div.getRect()
assert.deepStrictEqual(rect, { width: 500, height: 500, x: 0, y: 0 })
assert.deepStrictEqual(rect, {width: 500, height: 500, x: 0, y: 0})

const actions = await driver
.actions()
.move({ x: 10, y: 10, origin: div })
.move({x: 10, y: 10, origin: div})
.click()
.getSequences()

Expand Down Expand Up @@ -171,9 +171,9 @@ suite(

const actions = await driver
.actions()
.move({ origin: slide })
.move({origin: slide})
.press()
.move({ x: 100, y: 100, origin: Origin.POINTER })
.move({x: 100, y: 100, origin: Origin.POINTER})
.release()
.getSequences()

Expand Down Expand Up @@ -345,6 +345,34 @@ suite(
},
)

it('can execute release in browsing context', async function () {
const browsingContextId = await driver.getWindowHandle()
const input = await Input(driver)
await driver.get(Pages.releaseAction)

let inputTextBox = await driver.findElement(By.id('keys'))

await driver.executeScript('arguments[0].focus()', inputTextBox)


const actions = await driver
.actions()
.keyDown('a')
.keyDown('b')
.getSequences()

await input.perform(browsingContextId, actions)

await driver.executeScript('resetEvents()')

await input.release(browsingContextId)

const events = await driver.executeScript('return allEvents.events')

assert.strictEqual(events[0].code, 'KeyB')
assert.strictEqual(events[1].code, 'KeyA')
})

async function _getEvents(driver) {
await driver.wait(async () => {
const events = await driver.executeScript('return allEvents.events;')
Expand All @@ -354,5 +382,5 @@ suite(
}
})
},
{ browsers: [Browser.FIREFOX] },
{browsers: [Browser.FIREFOX]},
)

0 comments on commit d51c74a

Please sign in to comment.