From f1e617e311a56a9cbf3d90e5d5e11094835c97c1 Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Fri, 26 Mar 2021 16:08:29 +0100 Subject: [PATCH] Wait for content timeout --- apps/remix-ide-e2e/src/commands/addFile.ts | 4 ++-- .../commands/waitForElementContainsText.ts | 19 ++++++++++--------- .../{compiler_api => compiler_api.test.ts} | 12 ++++-------- apps/remix-ide-e2e/src/types/index.d.ts | 2 +- 4 files changed, 17 insertions(+), 20 deletions(-) rename apps/remix-ide-e2e/src/tests/{compiler_api => compiler_api.test.ts} (91%) diff --git a/apps/remix-ide-e2e/src/commands/addFile.ts b/apps/remix-ide-e2e/src/commands/addFile.ts index 46df6972a0..9f33147573 100644 --- a/apps/remix-ide-e2e/src/commands/addFile.ts +++ b/apps/remix-ide-e2e/src/commands/addFile.ts @@ -18,11 +18,11 @@ function addFile (browser: NightwatchBrowser, name: string, content: NightwatchC .clickLaunchIcon('fileExplorers') .click('li[data-id="treeViewLitreeViewItemREADME.txt"]') // focus on root directory .click('.newFile') - .waitForElementVisible('*[data-id="treeViewLitreeViewItem/blank"]') + .waitForElementVisible('*[data-id="treeViewLitreeViewItem/blank"]', 60000) .sendKeys('*[data-id="treeViewLitreeViewItem/blank"] .remixui_items', name) .sendKeys('*[data-id="treeViewLitreeViewItem/blank"] .remixui_items', browser.Keys.ENTER) .pause(2000) - .waitForElementVisible(`li[data-id="treeViewLitreeViewItem${name}"]`) + .waitForElementVisible(`li[data-id="treeViewLitreeViewItem${name}"]`, 60000) .setEditorValue(content.content) .pause(1000) .perform(function () { diff --git a/apps/remix-ide-e2e/src/commands/waitForElementContainsText.ts b/apps/remix-ide-e2e/src/commands/waitForElementContainsText.ts index b60fb39e2e..c41bf09b69 100644 --- a/apps/remix-ide-e2e/src/commands/waitForElementContainsText.ts +++ b/apps/remix-ide-e2e/src/commands/waitForElementContainsText.ts @@ -2,22 +2,23 @@ import { NightwatchBrowser } from 'nightwatch' import EventEmitter from 'events' class WaitForElementContainsText extends EventEmitter { - command (this: NightwatchBrowser, id: string, value: string): NightwatchBrowser { - let incr = 0 + command (this: NightwatchBrowser, id: string, value: string, timeout = 10000): NightwatchBrowser { + let waitId // eslint-disable-line const runid = setInterval(() => { this.api.getText(id, (result) => { - if (typeof result.value === 'string' && value.indexOf(result.value || '') !== -1) { + if (typeof result.value === 'string' && result.value.indexOf(value) !== -1) { clearInterval(runid) - this.api.assert.ok(true, `WaitForElementContainsText ${id} contains ${value}`) + clearTimeout(waitId) + this.api.assert.ok(true, `WaitForElementContainsText ${id} contains ${value} after ${timeout}`) this.emit('complete') - } else incr++ - if (incr > 50) { - clearInterval(runid) - this.api.assert.fail(`WaitForElementContainsText - expected ${value} but got ${result.value}`) - // throw new Error(`WaitForElementContainsText ${id} ${value}`) } }) }, 200) + + waitId = setTimeout(() => { + clearInterval(runid) + this.api.assert.fail(`TimeoutError: An error occurred while running .waitForElementContainsText() command on ${id}`) + }, timeout) return this } } diff --git a/apps/remix-ide-e2e/src/tests/compiler_api b/apps/remix-ide-e2e/src/tests/compiler_api.test.ts similarity index 91% rename from apps/remix-ide-e2e/src/tests/compiler_api rename to apps/remix-ide-e2e/src/tests/compiler_api.test.ts index 3da83f59c6..8281b1fbde 100644 --- a/apps/remix-ide-e2e/src/tests/compiler_api +++ b/apps/remix-ide-e2e/src/tests/compiler_api.test.ts @@ -22,8 +22,7 @@ module.exports = { browser .addFile('test_jsCompile.js', { content: jsCompile }) .executeScript('remix.exeCurrent()') - .pause(5000) - .journalChildIncludes('"languageversion": "0.6.8+commit.0bbfe453"') + .waitForElementContainsText('*[data-id="terminalJournal"]', '"languageversion": "0.6.8+commit.0bbfe453"', 60000) .click('*[data-id="terminalClearConsole"]') }, @@ -31,8 +30,7 @@ module.exports = { browser .addFile('test_jsCompileWithOptimization.js', { content: jsCompileWithOptimization }) .executeScript('remix.exeCurrent()') - .pause(10000) - .journalChildIncludes('\\"optimizer\\":{\\"enabled\\":true,\\"runs\\":300}') + .waitForElementContainsText('*[data-id="terminalJournal"]', '\\"optimizer\\":{\\"enabled\\":true,\\"runs\\":300}', 60000) .click('*[data-id="terminalClearConsole"]') }, @@ -40,8 +38,7 @@ module.exports = { browser .addFile('test_jsCompileWithOptimizationDefault.js', { content: jsCompileWithOptimizationDefault }) .executeScript('remix.exeCurrent()') - .pause(10000) - .journalChildIncludes('\\"optimizer\\":{\\"enabled\\":false,\\"runs\\":200}') + .waitForElementContainsText('*[data-id="terminalJournal"]', '\\"optimizer\\":{\\"enabled\\":false,\\"runs\\":200}', 60000) .click('*[data-id="terminalClearConsole"]') }, @@ -60,8 +57,7 @@ module.exports = { .click('li[data-id="treeViewLitreeViewItemREADME.txt"') .addFile('ContractStackLimit.sol', { content: contractStackLimit }) .clickLaunchIcon('solidity') - .pause(10000) - .waitForElementContainsText('*[data-id="compiledErrors"]', 'CompilerError: Stack too deep when compiling inline assembly: Variable headStart is 1 slot(s) too deep inside the stack.') + .waitForElementContainsText('*[data-id="compiledErrors"]', 'CompilerError: Stack too deep when compiling inline assembly: Variable headStart is 1 slot(s) too deep inside the stack.', 60000) .end() }, diff --git a/apps/remix-ide-e2e/src/types/index.d.ts b/apps/remix-ide-e2e/src/types/index.d.ts index a2423ab159..140b3ee089 100644 --- a/apps/remix-ide-e2e/src/types/index.d.ts +++ b/apps/remix-ide-e2e/src/types/index.d.ts @@ -30,7 +30,7 @@ declare module "nightwatch" { editorScroll(direction: 'up' | 'down', numberOfTimes: number): NightwatchBrowser, renamePath(path: string, newFileName: string, renamedPath: string): NightwatchBrowser, rightClick(cssSelector: string): NightwatchBrowser, - waitForElementContainsText(id: string, value: string): NightwatchBrowser, + waitForElementContainsText(id: string, value: string, timeout?: number): NightwatchBrowser, getModalBody(callback: (value: string, cb: VoidFunction) => void): NightwatchBrowser, modalFooterCancelClick(): NightwatchBrowser, selectContract(contractName: string): NightwatchBrowser,