From 2f15e8720a805a7187083131463bce3596ed3f29 Mon Sep 17 00:00:00 2001 From: BryceLTaylor Date: Mon, 29 Nov 2021 16:35:18 -0500 Subject: [PATCH] Create Selenium Helper function loadPageUntilVisible and use in comments test. --- test/integration/comments.test.js | 12 ++++++------ test/integration/selenium-helpers.js | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) 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;