diff --git a/apps/remix-ide-e2e/src/commands/journalChildIncludes.ts b/apps/remix-ide-e2e/src/commands/journalChildIncludes.ts index f781c8be2b..a831edc843 100644 --- a/apps/remix-ide-e2e/src/commands/journalChildIncludes.ts +++ b/apps/remix-ide-e2e/src/commands/journalChildIncludes.ts @@ -1,6 +1,5 @@ -import { NightwatchBrowser } from "nightwatch" - -const EventEmitter = require('events') +import { NightwatchBrowser } from 'nightwatch' +import EventEmitter from "events" /* Checks if any child elements of journal (console) contains a matching value. diff --git a/apps/remix-ide-e2e/src/commands/journalLastChild.ts b/apps/remix-ide-e2e/src/commands/journalLastChild.ts new file mode 100644 index 0000000000..6837988b8f --- /dev/null +++ b/apps/remix-ide-e2e/src/commands/journalLastChild.ts @@ -0,0 +1,15 @@ +import { NightwatchBrowser } from 'nightwatch' +import EventEmitter from "events" + +class JournalLastChild extends EventEmitter { + command (this: NightwatchBrowser, val: string): NightwatchBrowser { + this.api + .waitForElementVisible('*[data-id="terminalJournal"] > div:last-child', 10000) + .assert.containsText('*[data-id="terminalJournal"] > div:last-child', val).perform(() => { + this.emit('complete') + }) + return this + } +} + +module.exports = JournalLastChild diff --git a/apps/remix-ide-e2e/src/tests/terminal.test.ts b/apps/remix-ide-e2e/src/tests/terminal.test.ts new file mode 100644 index 0000000000..363b0538c9 --- /dev/null +++ b/apps/remix-ide-e2e/src/tests/terminal.test.ts @@ -0,0 +1,117 @@ +'use strict' +import { NightwatchBrowser } from "nightwatch" +import init from '../helpers/init' +import sauce from './sauce' + +module.exports = { + before: function (browser: NightwatchBrowser, done: VoidFunction) { + init(browser, done, 'http://127.0.0.1:8080?plugins=solidity,udapp', false) + }, + + 'Should execution a simple console command': function (browser: NightwatchBrowser) { + browser + .waitForElementVisible('*[data-id="terminalCli"]', 10000) + .executeScript('console.log(1 + 1)') + .journalLastChild('2') + }, + + 'Should clear console': function (browser: NightwatchBrowser) { + browser + .waitForElementVisible('*[data-id="terminalCli"]') + .journalChildIncludes('Welcome to Remix') + .click('#clearConsole') + .assert.containsText('*[data-id="terminalJournal"]', '') + }, + + 'Should display auto-complete menu': function (browser: NightwatchBrowser) { + browser + .waitForElementVisible('*[data-id="terminalCli"]') + .click('*[data-id="terminalCli"]') + .sendKeys('*[data-id="terminalCliInput"]', 'remix.') + .assert.visible('*[data-id="autoCompletePopUpAutoCompleteItem"]') + }, + + 'Should execute remix.help() command': function (browser: NightwatchBrowser) { + browser + .waitForElementVisible('*[data-id="terminalCli"]') + .executeScript('remix.help()') + .journalChildIncludes('remix.call(message: {name, key, payload})') + .journalChildIncludes('remix.getFile(path)') + .journalChildIncludes('remix.debug(hash)') + .journalChildIncludes('remix.loadgist(id)') + .journalChildIncludes('remix.loadurl(url)') + .journalChildIncludes('remix.setproviderurl(url)') + .journalChildIncludes('remix.execute(filepath)') + .journalChildIncludes('remix.exeCurrent()') + .journalChildIncludes('remix.help()') + .journalChildIncludes('remix.debugHelp()') + }, + + 'Should execute remix.debugHelp() command': function (browser: NightwatchBrowser) { + browser + .waitForElementVisible('*[data-id="terminalCli"]') + .executeScript('remix.debugHelp()') + .journalChildIncludes('Here are some examples of scripts that can be run (using remix.exeCurrent() or directly from the console)') + .journalChildIncludes('Please see https://www.npmjs.com/package/remix-debug for more informations') + }, + + 'Async/Await Script': function (browser: NightwatchBrowser) { + browser + .addFile('asyncAwait.js', { content: asyncAwait }) + .openFile('browser/asyncAwait.js') + .executeScript(`remix.execute('browser/asyncAwait.js')`) + .journalLastChild('Waiting Promise') + .pause(5500) + .journalLastChild('result - Promise Resolved') + }, + + 'Call Remix File Manager from a script': function (browser: NightwatchBrowser) { + browser + .addFile('asyncAwaitWithFileManagerAccess.js', { content: asyncAwaitWithFileManagerAccess }) + .openFile('browser/asyncAwaitWithFileManagerAccess.js') + .pause(5000) + .executeScript(`remix.execute('browser/asyncAwaitWithFileManagerAccess.js')`) + .pause(6000) + .journalLastChildIncludes('contract Ballot {') + .end() + }, + + tearDown: sauce +} + +const asyncAwait = ` + var p = function () { + return new Promise(function (resolve, reject) { + setTimeout(function () { + resolve("Promise Resolved") + }, 5000) + }) + } + + var run = async () => { + console.log('Waiting Promise') + var result = await p() + console.log('result - ', result) + } + + run() +` + +const asyncAwaitWithFileManagerAccess = ` + var p = function () { + return new Promise(function (resolve, reject) { + setTimeout(function () { + resolve("Promise Resolved") + }, 0) + }) + } + + var run = async () => { + console.log('Waiting Promise') + var result = await p() + let text = await remix.call('fileManager', 'readFile', 'browser/3_Ballot.sol') + console.log('result - ', text) + } + + run() +` diff --git a/apps/remix-ide-e2e/src/types/index.d.ts b/apps/remix-ide-e2e/src/types/index.d.ts index f156b57a93..00d79fef18 100644 --- a/apps/remix-ide-e2e/src/types/index.d.ts +++ b/apps/remix-ide-e2e/src/types/index.d.ts @@ -48,14 +48,16 @@ declare module "nightwatch" { setSolidityCompilerVersion(version: string): NightwatchBrowser, clickElementAtPosition(cssSelector: string, index: number): NightwatchBrowser, notContainsText(cssSelector: string, text: string): NightwatchBrowser, - sendLowLevelTx(address: string, value: string, callData: string): NightwatchBrowser + sendLowLevelTx(address: string, value: string, callData: string): NightwatchBrowser, + journalLastChild(val: string): NightwatchBrowser } export interface NightwatchBrowser { api: this, emit: (status: string) => void, fullscreenWindow: (result?: any) => this, - keys(keysToSend: string, callback?: (this: NightwatchAPI, result: NightwatchCallbackResult) => void): NightwatchBrowser + keys(keysToSend: string, callback?: (this: NightwatchAPI, result: NightwatchCallbackResult) => void): NightwatchBrowser, + sendKeys: (selector: string, inputValue: string | string[], callback?: (this: NightwatchAPI, result: NightwatchCallbackResult) => void) => NightwatchBrowser } export interface NightwatchContractContent {