diff --git a/test/helpers/selenium-helper.js b/test/helpers/selenium-helper.js index 12549e93301389f4efedf47ff01791996868a69c..99320f577083bfaaaca08c425c0dda9ab921cd43 100644 --- a/test/helpers/selenium-helper.js +++ b/test/helpers/selenium-helper.js @@ -21,7 +21,8 @@ class SeleniumHelper { 'getSauceDriver', 'getLogs', 'loadUri', - 'rightClickText' + 'rightClickText', + 'waitUntilGone' ]); } @@ -119,6 +120,10 @@ class SeleniumHelper { return this.clickXpath(`//button//*[contains(text(), '${text}')]`); } + waitUntilGone (element) { + return this.driver.wait(until.stalenessOf(element)); + } + getLogs (whitelist) { if (!whitelist) { // Default whitelist diff --git a/test/integration/project-loading.test.js b/test/integration/project-loading.test.js index 384463062a49adb3e9f05ac94c8a3aefa5d6495c..aeadfa436dcebe101778929adcd9e7f6d83e2e7f 100644 --- a/test/integration/project-loading.test.js +++ b/test/integration/project-loading.test.js @@ -4,11 +4,13 @@ import SeleniumHelper from '../helpers/selenium-helper'; const { clickText, clickXpath, + findByText, findByXpath, getDriver, getLogs, loadUri, - scope + scope, + waitUntilGone } = new SeleniumHelper(); const uri = path.resolve(__dirname, '../../build/index.html'); @@ -40,7 +42,7 @@ describe('Loading scratch gui', () => { const projectId = '96708228'; await el.sendKeys(`scratch.mit.edu/projects/${projectId}`); await clickXpath('//button[@title="View Project"]'); - await new Promise(resolve => setTimeout(resolve, 2000)); + await waitUntilGone(findByText('Loading')); await clickXpath('//img[@title="Go"]'); await new Promise(resolve => setTimeout(resolve, 2000)); await clickXpath('//img[@title="Stop"]'); @@ -63,7 +65,7 @@ describe('Loading scratch gui', () => { await el.clear(); await el.sendKeys('scratch.mit.edu/projects/96708228'); await clickXpath('//button[@title="View Project"]'); - await new Promise(resolve => setTimeout(resolve, 2000)); + await waitUntilGone(findByText('Loading')); await clickXpath('//img[@title="Go"]'); await new Promise(resolve => setTimeout(resolve, 2000)); await clickXpath('//img[@title="Stop"]'); @@ -77,7 +79,7 @@ describe('Loading scratch gui', () => { const projectId = '96708228'; await loadUri(`${uri}#${projectId}`); - await new Promise(resolve => setTimeout(resolve, 3000)); + await waitUntilGone(findByText('Loading')); await clickXpath('//img[@title="Go"]'); await new Promise(resolve => setTimeout(resolve, 2000)); await clickXpath('//img[@title="Stop"]'); @@ -98,7 +100,7 @@ describe('Loading scratch gui', () => { .setSize(1920, 1080); const projectId = '96708228'; await loadUri(`${uri}#${projectId}`); - await new Promise(resolve => setTimeout(resolve, 2000)); + await waitUntilGone(findByText('Loading')); await clickXpath('//img[@title="Full Screen Control"]'); await clickXpath('//img[@title="Go"]'); await new Promise(resolve => setTimeout(resolve, 2000)); @@ -119,7 +121,7 @@ describe('Loading scratch gui', () => { const projectId = '96708228'; await inputElement.sendKeys(`scratch.mit.edu/projects/${projectId}`); await clickXpath('//button[@title="View Project"]'); - await new Promise(resolve => setTimeout(resolve, 2000)); + await waitUntilGone(findByText('Loading')); await findByXpath('//*[span[text()="Costumes"]]'); await clickText('Costumes'); await clickXpath( @@ -138,7 +140,7 @@ describe('Loading scratch gui', () => { const projectId = '96708228'; await inputElement.sendKeys(`scratch.mit.edu/projects/${projectId}`); await clickXpath('//button[@title="View Project"]'); - await new Promise(resolve => setTimeout(resolve, 2000)); + await waitUntilGone(findByText('Loading')); await clickXpath( '//div[contains(@class, "menu-bar_menu-bar-item") and ' + 'contains(@class, "menu-bar_hoverable")][span[text()="File"]]' @@ -155,7 +157,7 @@ describe('Loading scratch gui', () => { const projectId = '96708228'; await inputElement.sendKeys(`scratch.mit.edu/projects/${projectId}`); await clickXpath('//button[@title="View Project"]'); - await new Promise(resolve => setTimeout(resolve, 2000)); + await waitUntilGone(findByText('Loading')); await clickText('Sounds'); await clickXpath('//button[@aria-label="Choose a Sound"]'); await clickText('A Bass', scope.modal); // Should close the modal