diff --git a/apps/remix-ide-e2e/.eslintrc b/apps/remix-ide-e2e/.eslintrc index 8e19d96e54..0868946880 100644 --- a/apps/remix-ide-e2e/.eslintrc +++ b/apps/remix-ide-e2e/.eslintrc @@ -2,14 +2,13 @@ "rules": {}, "overrides": [ { - "files": ["src/plugins/index.js"], + "files": ["**/*.ts"], "rules": { - "@typescript-eslint/no-var-requires": "off", - "no-undef": "off" + "no-undef": "off", + "@typescript-eslint/no-var-requires": 0 } } ], "extends": ["../../.eslintrc"], "ignorePatterns": ["!**/*"] -} - \ No newline at end of file +} \ No newline at end of file diff --git a/apps/remix-ide-e2e/src/commands/clickLaunchIcon.ts b/apps/remix-ide-e2e/src/commands/clickLaunchIcon.ts new file mode 100644 index 0000000000..9c8eccadf3 --- /dev/null +++ b/apps/remix-ide-e2e/src/commands/clickLaunchIcon.ts @@ -0,0 +1,15 @@ +import { NightwatchBrowser } from "nightwatch" + +const EventEmitter = require('events') + +class ClickLaunchIcon extends EventEmitter { + command (this: NightwatchBrowser, icon: string) { + this.api.waitForElementVisible('#icon-panel div[plugin="' + icon + '"]').click('#icon-panel div[plugin="' + icon + '"]').perform((done: CallableFunction) => { + done() + this.emit('complete') + }) + return this + } +} + +module.exports = ClickLaunchIcon diff --git a/apps/remix-ide-e2e/src/helpers/init.ts b/apps/remix-ide-e2e/src/helpers/init.ts new file mode 100644 index 0000000000..43a67717c1 --- /dev/null +++ b/apps/remix-ide-e2e/src/helpers/init.ts @@ -0,0 +1,38 @@ +import { NightwatchBrowser } from "nightwatch" + +require('dotenv').config() + +module.exports = function (browser: NightwatchBrowser, callback: CallableFunction, url: string, preloadPlugins = true) { + browser + .url(url || 'http://127.0.0.1:8080') + .pause(5000) + .switchBrowserTab(0) + .injectScript('test-browser/helpers/applytestmode.js', function () { + browser.fullscreenWindow(() => { + if (preloadPlugins) { + console.log('preloadPlugins: ', preloadPlugins) + initModules(browser, () => { + browser.clickLaunchIcon('solidity') + .waitForElementPresent('[for="autoCompile"]') + .click('[for="autoCompile"]') + }) + } + }) + }) + .perform(() => { + callback() + }) +} + +function initModules (browser, callback) { + browser.pause(5000) + .click('[data-id="verticalIconsKindpluginManager"]') + .scrollAndClick('[data-id="pluginManagerComponentActivateButtonsolidityStaticAnalysis"]') + .scrollAndClick('[data-id="pluginManagerComponentActivateButtondebugger"]') + .scrollAndClick('[data-id="verticalIconsKindfileExplorers"]') + .clickLaunchIcon('settings') + .setValue('[data-id="settingsTabGistAccessToken"]', process.env.gist_token) + .click('[data-id="settingsTabSaveGistToken"]') + .click('[data-id="settingsTabThemeFlatly"]') // e2e tests were initially developed with Flatly. Some tests are failing with the default one (Dark), because the dark theme put uppercase everywhere. + .perform(() => { callback() }) +} diff --git a/apps/remix-ide-e2e/src/tests/ballot.test.ts b/apps/remix-ide-e2e/src/tests/ballot.test.ts index 1b73083b90..1cb42dd7a4 100644 --- a/apps/remix-ide-e2e/src/tests/ballot.test.ts +++ b/apps/remix-ide-e2e/src/tests/ballot.test.ts @@ -1,20 +1,23 @@ 'use strict' -var examples = require('../../src/app/editor/example-contracts') -var init = require('../helpers/init') -var sauce = require('./sauce') -var sources = [ - {'browser/Untitled.sol': {content: examples.ballot.content}} +import { NightwatchBrowser, NightwatchCallbackResult } from 'nightwatch' +import * as init from '../helpers/init' + +const examples = require('../../../../../apps/remix-ide/src/app/editor/example-contracts') // reference example-contracts from inside dist directory +const sauce = require('./sauce') + +const sources = [ + {'browser/Untitled.sol': { content: examples.ballot.content }} ] module.exports = { - before: function (browser, done) { + before: function (browser: NightwatchBrowser, done: NightwatchCallbackResult) { init(browser, done) }, '@sources': function () { return sources }, - 'Deploy Ballot': function (browser) { + 'Deploy Ballot': function (browser: NightwatchBrowser) { browser .waitForElementVisible('*[data-id="remixIdeIconPanel"]', 10000) .clickLaunchIcon('solidity') @@ -34,7 +37,7 @@ module.exports = { }) }, - 'Debug Ballot / delegate': function (browser) { + 'Debug Ballot / delegate': function (browser: NightwatchBrowser) { browser.pause(500) .click('*[data-id="txLoggerDebugButton0x41fab8ea5b1d9fba5e0a6545ca1a2d62fff518578802c033c2b9a031a01c31b3"]') .pause(2000) @@ -47,7 +50,7 @@ module.exports = { .checkVariableDebug('soliditylocals', localsCheck) }, - 'Access Ballot via at address': function (browser) { + 'Access Ballot via at address': function (browser: NightwatchBrowser) { browser.clickLaunchIcon('udapp') .click('*[data-id="universalDappUiUdappClose"]') .addFile('ballot.abi', { content: ballotABI }) @@ -66,7 +69,7 @@ module.exports = { }) }, - 'Deploy and use Ballot using external web3': function (browser) { + 'Deploy and use Ballot using external web3': function (browser: NightwatchBrowser) { browser .click('*[data-id="settingsWeb3Mode"]') .modalFooterOKClick() @@ -86,14 +89,14 @@ module.exports = { tearDown: sauce } -var localsCheck = { +const localsCheck = { 'to': { 'value': '0x4B0897B0513FDC7C541B6D9D7E929C4E5364D2DB', 'type': 'address' } } -var stateCheck = { +const stateCheck = { 'chairperson': { 'value': '0xCA35B7D915458EF540ADE6068DFE2F44E8FA733C', 'type': 'address', @@ -148,7 +151,7 @@ var stateCheck = { } } -var ballotABI = `[ +const ballotABI = `[ { "inputs": [ { diff --git a/apps/remix-ide-e2e/src/types/index.d.ts b/apps/remix-ide-e2e/src/types/index.d.ts new file mode 100644 index 0000000000..6a991f6d59 --- /dev/null +++ b/apps/remix-ide-e2e/src/types/index.d.ts @@ -0,0 +1,15 @@ +// Merge custom command types with nightwatch types + +import { NightwatchBrowser, NightwatchAPI, NightwatchBrowser, NightwatchBrowser } from "nightwatch"; + +declare module "nightwatch" { + export interface NightwatchCustomCommands { + clickLaunchIcon(this: NightwatchBrowser, icon: string), + switchBrowserTab(this: NightwatchBrowser, index: number) + } + + export interface NightwatchBrowser { + api: NightwatchAPI, + emit: (status: string) => void + } +} \ No newline at end of file diff --git a/apps/remix-ide-e2e/tsconfig.json b/apps/remix-ide-e2e/tsconfig.json index 6be416ea65..a99835019c 100644 --- a/apps/remix-ide-e2e/tsconfig.json +++ b/apps/remix-ide-e2e/tsconfig.json @@ -1,7 +1,7 @@ { "extends": "../../tsconfig.json", "compilerOptions": { - "types": ["node"] + "types": ["node", "nightwatch"] }, "include": ["**/*.ts", "**/*.js"] } diff --git a/package-lock.json b/package-lock.json index 6c954fe3db..8bcfd029c1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6824,6 +6824,12 @@ "integrity": "sha512-ZvO2tAcjmMi8V/5Z3JsyofMe3hasRcaw88cto5etSVMwVQfeivGAlEYmaQgceUSVYFofVjT+ioHsATjdWcFt1w==", "dev": true }, + "@types/nightwatch": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/@types/nightwatch/-/nightwatch-1.1.6.tgz", + "integrity": "sha512-QFreK7brv9R6gc0J1sqm2kYzMaQtDSMRyK1btna+GrqvrqVypWsY2XwuYn3x/45kMcdHKnhZQDQfqts3yK/cEw==", + "dev": true + }, "@types/node": { "version": "8.9.5", "resolved": "https://registry.npmjs.org/@types/node/-/node-8.9.5.tgz", diff --git a/package.json b/package.json index f6f95f4d4b..e9091f5581 100644 --- a/package.json +++ b/package.json @@ -165,6 +165,7 @@ "@resolver-engine/imports": "^0.3.0", "@types/chai": "^4.2.11", "@types/mocha": "^7.0.2", + "@types/nightwatch": "^1.1.6", "@types/node": "~8.9.4", "@types/react": "16.9.17", "@types/react-dom": "16.9.4",