Create Selenium Helper function loadPageUntilVisible and use in comments test.

This commit is contained in:
BryceLTaylor 2021-11-29 16:35:18 -05:00
parent 391c0070ba
commit 2f15e8720a
2 changed files with 22 additions and 6 deletions

View file

@ -3,11 +3,12 @@
import SeleniumHelper from './selenium-helpers.js'; import SeleniumHelper from './selenium-helpers.js';
const { const {
findByXpath,
buildDriver, buildDriver,
clickXpath,
clickText, clickText,
clickXpath,
containsClass, containsClass,
findByXpath,
loadPageUntilVisible,
signIn signIn
} = new SeleniumHelper(); } = new SeleniumHelper();
@ -320,10 +321,9 @@ describe('comment tests', async () => {
let postButton = await findByXpath(replyRow + '//button[@class = "button compose-post"]'); let postButton = await findByXpath(replyRow + '//button[@class = "button compose-post"]');
await postButton.click(); await postButton.click();
// find reply // reload page and find reply
await driver.sleep(500); let replyXpath = `//span[contains(text(), "${studioReply}")]`;
await driver.get(studioUrl); let postedReply = await loadPageUntilVisible(studioUrl, replyXpath, 10);
let postedReply = await findByXpath(`//span[contains(text(), "${studioReply}")]`);
let commentVisible = await postedReply.isDisplayed(); let commentVisible = await postedReply.isDisplayed();
await expect(commentVisible).toBe(true); await expect(commentVisible).toBe(true);
}); });

View file

@ -30,6 +30,7 @@ class SeleniumHelper {
'getDriver', 'getDriver',
'getLogs', 'getLogs',
'getSauceDriver', 'getSauceDriver',
'loadPageUntilVisible',
'signIn', 'signIn',
'urlMatches', 'urlMatches',
'waitUntilGone' 'waitUntilGone'
@ -201,6 +202,21 @@ class SeleniumHelper {
await driver.wait(until.elementIsVisible(element)); await driver.wait(until.elementIsVisible(element));
} }
async loadPageUntilVisible (url, elementXpath, maxTries) {
for (let i = 0; i < maxTries; i++){
try {
await this.driver.get(url);
let element = await this.driver.wait(until.elementLocated(
By.xpath(elementXpath)), 200, 'could not find element within 200ms');
// let element = await this.findByXpath(elementXpath);
return await element;
} catch (e) {
console.log('reloaded the page');
}
}
console.log('reached max tries');
}
} }
module.exports = SeleniumHelper; module.exports = SeleniumHelper;