Skip to content

Commit

Permalink
[Javascript] Split String on grapheme pairs in sendKeys command (Sele…
Browse files Browse the repository at this point in the history
…niumHQ#10519)

* split string on grapheme pairs in sendKeys

* added test for using emoji representated by pair of code points as sendKeys argument

Co-authored-by: Diego Molina <diemol@users.noreply.github.com>
Co-authored-by: Puja Jagani <puja.jagani93@gmail.com>
  • Loading branch information
3 people authored and elgatov committed Jun 27, 2022
1 parent d829b52 commit c7396de
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion javascript/node/selenium-webdriver/lib/webdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -2530,7 +2530,7 @@ class WebElement {

// The W3C protocol requires keys to be specified as an array where
// each element is a single key.
keys.push(...key.split(''))
keys.push(...key)
})

if (!this.driver_.fileDetector_) {
Expand Down
36 changes: 26 additions & 10 deletions javascript/node/selenium-webdriver/test/lib/webdriver_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,9 @@ describe('WebDriver', function () {
.andReturnError(new StubError())
.end()

const driver = WebDriver.createSession(executor,
{ browserName: 'firefox' })
const driver = WebDriver.createSession(executor, {
browserName: 'firefox',
})
return driver.getSession().then(fail, assertIsStubError)
})

Expand Down Expand Up @@ -334,7 +335,7 @@ describe('WebDriver', function () {
let verifyError = expectedError(
error.NoSuchSessionError,
'This driver instance does not have a valid session ID ' +
'(did you call WebDriver.quit()?) and may no longer be used.'
'(did you call WebDriver.quit()?) and may no longer be used.'
)

let driver = executor.createDriver()
Expand Down Expand Up @@ -522,14 +523,14 @@ describe('WebDriver', function () {
let executor = new FakeExecutor()
.expect(CName.EXECUTE_SCRIPT)
.withParameters({
script: 'return (' + function () { } + ').apply(null, arguments);',
script: 'return (' + function () {} + ').apply(null, arguments);',
args: [],
})
.andReturnSuccess(null)
.end()

const driver = executor.createDriver()
return driver.executeScript(function () { })
return driver.executeScript(function () {})
})

it('simpleArgumentConversion', function () {
Expand Down Expand Up @@ -629,23 +630,23 @@ describe('WebDriver', function () {
let executor = new FakeExecutor()

const arg = Promise.reject(new StubError())
arg.catch(function () { }) // Suppress default handler.
arg.catch(function () {}) // Suppress default handler.

const driver = executor.createDriver()
return driver
.executeScript(function () { }, arg)
.executeScript(function () {}, arg)
.then(fail, assertIsStubError)
})
})

describe('executeAsyncScript', function () {
it('failsIfArgumentIsARejectedPromise', function () {
const arg = Promise.reject(new StubError())
arg.catch(function () { }) // Suppress default handler.
arg.catch(function () {}) // Suppress default handler.

const driver = new FakeExecutor().createDriver()
return driver
.executeAsyncScript(function () { }, arg)
.executeAsyncScript(function () {}, arg)
.then(fail, assertIsStubError)
})
})
Expand Down Expand Up @@ -939,6 +940,21 @@ describe('WebDriver', function () {
return element.sendKeys(1, 2, 'abc', 3)
})

it('sendKeysWithEmojiRepresentedByPairOfCodePoints', function () {
let executor = new FakeExecutor()
.expect(CName.SEND_KEYS_TO_ELEMENT, {
id: WebElement.buildId('one'),
text: '\uD83D\uDE00',
value: ['\uD83D\uDE00'],
})
.andReturnSuccess()
.end()

const driver = executor.createDriver()
const element = new WebElement(driver, 'one')
return element.sendKeys('\uD83D\uDE00')
})

it('convertsVarArgsIntoStrings_promisedArgs', function () {
let executor = new FakeExecutor()
.expect(CName.FIND_ELEMENT, {
Expand Down Expand Up @@ -1927,7 +1943,7 @@ describe('WebDriver', function () {
})

it('passes through function properties', function () {
function bar() { }
function bar() {}
return runDeserializeTest(
[{ foo: { bar: 123 }, func: bar }],
[{ foo: { bar: 123 }, func: bar }]
Expand Down

0 comments on commit c7396de

Please sign in to comment.