diff --git a/test/integration/comments.test.js b/test/integration/comments.test.js index 03f35f71c..c1d9d6347 100644 --- a/test/integration/comments.test.js +++ b/test/integration/comments.test.js @@ -3,11 +3,12 @@ import SeleniumHelper from './selenium-helpers.js'; const { - findByXpath, buildDriver, - clickXpath, clickText, + clickXpath, containsClass, + findByXpath, + loadPageUntilVisible, signIn } = new SeleniumHelper(); @@ -320,10 +321,9 @@ describe('comment tests', async () => { let postButton = await findByXpath(replyRow + '//button[@class = "button compose-post"]'); await postButton.click(); - // find reply - await driver.sleep(500); - await driver.get(studioUrl); - let postedReply = await findByXpath(`//span[contains(text(), "${studioReply}")]`); + // reload page and find reply + let replyXpath = `//span[contains(text(), "${studioReply}")]`; + let postedReply = await loadPageUntilVisible(studioUrl, replyXpath, 10); let commentVisible = await postedReply.isDisplayed(); await expect(commentVisible).toBe(true); }); diff --git a/test/integration/selenium-helpers.js b/test/integration/selenium-helpers.js index 9d94f8698..cd82a4667 100644 --- a/test/integration/selenium-helpers.js +++ b/test/integration/selenium-helpers.js @@ -30,6 +30,7 @@ class SeleniumHelper { 'getDriver', 'getLogs', 'getSauceDriver', + 'loadPageUntilVisible', 'signIn', 'urlMatches', 'waitUntilGone' @@ -201,6 +202,21 @@ class SeleniumHelper { 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;