mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-23 15:47:53 -05:00
Create Selenium Helper function loadPageUntilVisible and use in comments test.
This commit is contained in:
parent
391c0070ba
commit
2f15e8720a
2 changed files with 22 additions and 6 deletions
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue