Skip to content

Commit

Permalink
Fixed #2294: ES6 async/awaits does not work with browser.elements()
Browse files Browse the repository at this point in the history
  • Loading branch information
beatfactor committed Jan 28, 2020
1 parent 80c0ed4 commit 2a63267
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/api/protocol/_base-action.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module.exports = class ProtocolAction {
*
* @return {Promise}
*/
findElements({element, parentElement, id, using, value, commandName, callback = function() {}}) {
findElements({element, parentElement, id, using, value, commandName, callback = (r) => (r)}) {
if (!(element instanceof Element)) {
try {
element = Element.createFromSelector(value, using);
Expand Down Expand Up @@ -85,7 +85,7 @@ module.exports = class ProtocolAction {
elementIdElements: 'locateMultipleElementsByElementId',
};

let transportAction = commandToActionMap[commandName];
const transportAction = commandToActionMap[commandName];

if (element.usingRecursion) {
return this.elementLocator.findElement({element, transportAction});
Expand Down
2 changes: 1 addition & 1 deletion lib/element/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class Element {
*/
static createFromSelector(value, using) {
if (!value) {
throw new Error('Invalid selector value specified');
throw new Error(`Invalid selector value specified "${value}"`);
}

if (value instanceof Element) {
Expand Down
5 changes: 4 additions & 1 deletion test/lib/mockserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,11 @@ module.exports = {
* @param {Object} item
* @param {boolean} once
*/
addMock(item, once) {
addMock(item, once, twice) {
server.addMock(item, once);
if (twice) {
server.addMock(item, once);
}
return this;
},

Expand Down
3 changes: 3 additions & 0 deletions test/sampletests/es6await/webdriver/getText/getTextES6.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ module.exports = {

const page = client.page.simplePageObj();

const result = await client.elements('css selector', '#element-selector');
assert.deepStrictEqual(result.value[0], {'element-6066-11e4-a52e-4f735466cecf': '5cc459b8-36a8-3042-8b4a-258883ea642b'});

const textResult = await page.getText('#element-selector');
assert.ok(!!textResult);
assert.ok('value' in textResult);
Expand Down
2 changes: 1 addition & 1 deletion test/src/runner/testRunnerEs6Async.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ describe('testRunner ES6 Async', function() {
'element-6066-11e4-a52e-4f735466cecf': '5cc459b8-36a8-3042-8b4a-258883ea642b'
}]
})
}, true);
}, true, true);

MockServer.addMock({
url: '/session/13521-10219-202/element/5cc459b8-36a8-3042-8b4a-258883ea642b/text',
Expand Down

0 comments on commit 2a63267

Please sign in to comment.