Skip to content

Commit

Permalink
Fix waitFor commands not retrying for stale elements. (#3978)
Browse files Browse the repository at this point in the history
  • Loading branch information
garg3133 authored Dec 14, 2023
1 parent ebb5df3 commit 8dbcbb3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
6 changes: 5 additions & 1 deletion lib/api/element-commands/_waitForDisplayed.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ class WaitForDisplayed extends WaitForElement {
}

setupActions() {
const isResultStale = (result) => this.transport.staleElementReference(result);
const isResultStale = (result) => {
const errorResponse = this.transport.getErrorResponse(result);

return this.transport.staleElementReference(errorResponse);
};
const validate = (result) => this.isResultSuccess(result);
const successHandler = (result) => this.protocolActionHandler(result);

Expand Down
27 changes: 13 additions & 14 deletions test/src/api/commands/element/testWaitForElementVisible.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,41 +160,40 @@ describe('waitForElementVisible', function () {
postdata: '{"using":"css selector","value":"#stale-element"}',
method: 'POST',
response: JSON.stringify({
status: 0,
state: 'success',
value: [{'element-6066-11e4-a52e-4f735466cecf': '99'}]
})
})
}, true)
.addMock({
url: '/wd/hub/session/1352110219202/execute/sync',
method: 'POST',
response: JSON.stringify({
sessionId: '1352110219202',
state: 'stale element reference',
status: 10
value: {
error: 'stale element reference'
}
})
}, true)
.addMock({
url: '/wd/hub/session/1352110219202/elements',
postdata: '{"using":"css selector","value":"#stale-element"}',
method: 'POST',
response: JSON.stringify({
value: [{'element-6066-11e4-a52e-4f735466cecf': '88'}]
})
}, true)
.addMock({
url: '/wd/hub/session/1352110219202/execute/sync',
method: 'POST',
response: JSON.stringify({
state: 'success',
status: 0,
value: true
})
}, true);

this.client.api.waitForElementVisible('#stale-element', 110, 10, function callback(result, instance) {
assert.strictEqual(instance.elementId, '99');
assert.strictEqual(instance.elementId, '88'); // element id refreshed
assert.strictEqual(result.value, true);
});

return this.client.start(function (err) {
MockServer.removeMock({
url: '/wd/hub/session/1352110219202/elements',
method: 'POST'
});

if (err) {
throw err;
}
Expand Down

0 comments on commit 8dbcbb3

Please sign in to comment.