diff --git a/apps/remix-ide-e2e/src/commands/waitForElementNotContainsText.ts b/apps/remix-ide-e2e/src/commands/waitForElementNotContainsText.ts new file mode 100644 index 0000000000..e482a627f1 --- /dev/null +++ b/apps/remix-ide-e2e/src/commands/waitForElementNotContainsText.ts @@ -0,0 +1,28 @@ +import { NightwatchBrowser } from 'nightwatch' +import EventEmitter from 'events' + +class WaitForElementNotContainsText extends EventEmitter { + command (this: NightwatchBrowser, id: string, value: string, timeout = 10000): NightwatchBrowser { + let waitId // eslint-disable-line + let currentValue + const runid = setInterval(() => { + this.api.getText(id, (result) => { + currentValue = result.value + if (typeof result.value === 'string' && result.value.indexOf(value) !== -1) { + clearInterval(runid) + clearTimeout(waitId) + this.api.assert.ok(false, `WaitForElementContainsText ${id} contains ${value} . It should not`) + this.emit('complete') + } + }) + }, 200) + + waitId = setTimeout(() => { + clearInterval(runid) + this.api.assert.fail(`TimeoutError: An error occurred while running .waitForElementContainsText() command on ${id} after ${timeout} milliseconds. expected: ${value} - got: ${currentValue}`) + }, timeout) + return this + } +} + +module.exports = WaitForElementNotContainsText diff --git a/apps/remix-ide-e2e/src/tests/terminal.test.ts b/apps/remix-ide-e2e/src/tests/terminal.test.ts index a611600e30..eb54b471f6 100644 --- a/apps/remix-ide-e2e/src/tests/terminal.test.ts +++ b/apps/remix-ide-e2e/src/tests/terminal.test.ts @@ -356,6 +356,8 @@ module.exports = { }) .useCss() .waitForElementContainsText('*[data-id="terminalJournal"]', 'test running free function', 120000) + .WaitForElementNotContainsText('*[data-id="terminalJournal"]', `test running free function + test running free function`) } } diff --git a/apps/remix-ide-e2e/src/types/index.d.ts b/apps/remix-ide-e2e/src/types/index.d.ts index 4c356ca76f..0a793a9b7a 100644 --- a/apps/remix-ide-e2e/src/types/index.d.ts +++ b/apps/remix-ide-e2e/src/types/index.d.ts @@ -69,6 +69,7 @@ declare module 'nightwatch' { switchWorkspace: (workspaceName: string) => NightwatchBrowser switchEnvironment: (provider: string) => NightwatchBrowser connectToExternalHttpProvider: (url: string, identifier: string) => NightwatchBrowser + WaitForElementNotContainsText: (id: string, value: string, timeout: number = 10000) => NightwatchBrowser } export interface NightwatchBrowser {