Skip to content

Commit 03b5ae0

Browse files
committed
waitForLabelText
1 parent a45168f commit 03b5ae0

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

tests/e2e/portal/3D_EM.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ async function runTutorial () {
3434

3535
await tutorial.waitFor(10000, 'Some time for starting the service');
3636
await utils.takeScreenshot(page, screenshotPrefix + 'service_started');
37+
38+
const entitiesListed = [
39+
"Vein.vtk",
40+
"Artery.vtk",
41+
"Bones.e",
42+
];
43+
for (const text of entitiesListed) {
44+
const found = await utils.waitForLabelText(page, text);
45+
if (!found) {
46+
throw new Error(`Text "${text}" not visible on the page within timeout.`);
47+
}
48+
}
3749
}
3850
catch(err) {
3951
await tutorial.setTutorialFailed();

tests/e2e/utils/utils.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,25 @@ async function getButtonsWithText(page, text) {
634634
return buttons;
635635
}
636636

637+
async function waitForLabelText(page, text, timeout = 10000) {
638+
try {
639+
await page.waitForFunction(
640+
(text) => {
641+
return [...document.body.querySelectorAll('*')].some(el =>
642+
el.innerText.includes(text) &&
643+
!!(el.offsetWidth || el.offsetHeight || el.getClientRects().length) // check if element is visible
644+
);
645+
},
646+
{ timeout },
647+
text
648+
);
649+
return true;
650+
} catch (err) {
651+
// WaitForFunction throws if timeout is reached
652+
return false;
653+
}
654+
}
655+
637656

638657
module.exports = {
639658
makeRequest,
@@ -671,4 +690,5 @@ module.exports = {
671690
isElementVisible,
672691
clickLoggerTitle,
673692
getButtonsWithText,
693+
waitForLabelText,
674694
}

0 commit comments

Comments
 (0)