diff --git a/core/tests/webdriverio_utils/ExplorationEditorMainTab.js b/core/tests/webdriverio_utils/ExplorationEditorMainTab.js index 3b33becfe3af..95effc766889 100644 --- a/core/tests/webdriverio_utils/ExplorationEditorMainTab.js +++ b/core/tests/webdriverio_utils/ExplorationEditorMainTab.js @@ -518,6 +518,8 @@ var ExplorationEditorMainTab = function() { this.expectContentToMatch = async function(richTextInstructions) { await waitFor.visibilityOf( stateContentDisplay, 'State content display not showing up'); + // Wait for any text to be present to reduce flakes. + await waitFor.nonEmptyText('State content display', stateContentDisplay); await forms.expectRichText(stateContentDisplay).toMatch( richTextInstructions); }; diff --git a/core/tests/webdriverio_utils/waitFor.js b/core/tests/webdriverio_utils/waitFor.js index f696ad0ce460..5744d8435b0d 100644 --- a/core/tests/webdriverio_utils/waitFor.js +++ b/core/tests/webdriverio_utils/waitFor.js @@ -280,6 +280,21 @@ var clientSideRedirection = async function( await waitForCallerSpecifiedConditions(); }; +var nonEmptyText = async function(elementName, element) { + await visibilityOf( + element, `${elementName} is not visible for getText()`); + await browser.waitUntil( + async function() { + return await element.getText(); + }, { + timeout: DEFAULT_WAIT_TIME_MSECS, + timeoutMsg: `Text in ${elementName} is empty!\n` + + new Error().stack + '\n' + } + ); +}; + + exports.DEFAULT_WAIT_TIME_MSECS = DEFAULT_WAIT_TIME_MSECS; exports.alertToBePresent = alertToBePresent; exports.urlToBe = urlToBe; @@ -302,3 +317,4 @@ exports.newTabToBeCreated = newTabToBeCreated; exports.urlRedirection = urlRedirection; exports.numberOfElementsToBe = numberOfElementsToBe; exports.clientSideRedirection = clientSideRedirection; +exports.nonEmptyText = nonEmptyText;