Skip to content

Commit

Permalink
[js]: Fix sendKeys command fail on FileDetector.handleFile error. (#1…
Browse files Browse the repository at this point in the history
…4663)

Fix sendKeys command failing on FileDetector handleFile error.

Co-authored-by: David Burns <[email protected]>
Co-authored-by: Sri Harsha <[email protected]>
  • Loading branch information
3 people authored Oct 28, 2024
1 parent b2702ca commit 68f82b3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions javascript/node/selenium-webdriver/lib/webdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -2752,6 +2752,7 @@ class WebElement {
keys = await this.driver_.fileDetector_.handleFile(this.driver_, keys.join(''))
} catch (ex) {
this.log_.severe('Error trying parse string as a file with file detector; sending keys instead' + ex)
keys = keys.join('')
}

return this.execute_(
Expand Down
26 changes: 26 additions & 0 deletions javascript/node/selenium-webdriver/test/lib/webdriver_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,32 @@ describe('WebDriver', function () {

return driver.findElement(By.id('foo')).sendKeys('original/', 'path')
})

it('sendKeysWithAFileDetector_handlerError', function () {
let executor = new FakeExecutor()
.expect(CName.FIND_ELEMENT, {
using: 'css selector',
value: '*[id="foo"]',
})
.andReturnSuccess(WebElement.buildId('one'))
.expect(CName.SEND_KEYS_TO_ELEMENT, {
id: WebElement.buildId('one'),
text: 'original/path',
value: 'original/path'.split(''),
})
.andReturnSuccess()
.end()

let driver = executor.createDriver()
let handleFile = function (d, path) {
assert.strictEqual(driver, d)
assert.strictEqual(path, 'original/path')
return Promise.reject('unhandled file error')
}
driver.setFileDetector({ handleFile })

return driver.findElement(By.id('foo')).sendKeys('original/', 'path')
})
})

describe('switchTo()', function () {
Expand Down

0 comments on commit 68f82b3

Please sign in to comment.