Skip to content
Snippets Groups Projects
Commit cc714ee1 authored by Alexey Korepov's avatar Alexey Korepov
Browse files

Merge branch '3514789-nightwatch-wait-for-rerender' into '1.5.x'

Issue #3514365: [Nightwatch] Add a command to wait for an element to be re-rendered

See merge request !144
parents 02fdee35 9aec36fe
No related branches found
No related tags found
No related merge requests found
Pipeline #454850 passed with warnings
/**
* @file
* Nightwatch command that executes an action and checks for an element to be re-rendered on the page.
*/
module.exports = class ThPerformAndWaitForReRenderthPer {
/**
* Executes an action and checks for an element to be re-rendered on the page.
*
* Useful to check the action elements on the frontend, which rerender the
* component without reloading the page.
*
* @param {function} action
* The action to perform.
* @param {object} checkElementSelector
* The selector to check the element for disappear and appear.
*/
command(action, checkElementSelector) {
let elId;
let isElReloaded = false;
this.api
.findElement(checkElementSelector, (result) => {
elId = result.value.getId();
})
.perform(action(this.api))
.perform(async () => {
for (let i = 0; i < 10; i++) {
// eslint-disable-next-line no-await-in-loop
await this.api.waitForElementVisible(checkElementSelector);
// eslint-disable-next-line no-await-in-loop
const elReloaded = await this.api.findElement(checkElementSelector);
if (elReloaded.getId() !== elId) {
isElReloaded = true;
break;
}
this.api.pause(100);
}
if (!isElReloaded) {
throw new Error(
`The element "${checkElementSelector}" was not rerendered.`,
);
}
return true;
});
}
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment