Skip to content

Commit

Permalink
Merge pull request #2593 from ethereum/terminal-e2e-tests
Browse files Browse the repository at this point in the history
Terminal e2e tests
  • Loading branch information
yann300 authored Feb 21, 2020
2 parents 8beaf90 + 83c517e commit c94af82
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 26 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,9 @@
"nightwatch_local_specialFunctions": "nightwatch ./test-browser/tests/specialFunctions.js --config nightwatch.js --env chrome ",
"nightwatch_local_solidityUnittests": "nightwatch ./test-browser/tests/solidityUnittests.js --config nightwatch.js --env chrome ",
"nightwatch_local_remixd": "nightwatch ./test-browser/tests/remixd.js --config nightwatch.js --env chrome ",
"nightwatch_local_console": "nightwatch ./test-browser/tests/console.js --config nightwatch.js --env chrome ",
"nightwatch_local_terminal": "nightwatch ./test-browser/tests/terminal.js --config nightwatch.js --env chrome ",
"nightwatch_local_gist": "nightwatch ./test-browser/tests/gist.js --config nightwatch.js --env chrome ",
"nightwatch_local_importFromGist": "nightwatch ./test-browser/tests/importFromGist.js --config nightwatch.js --env chrome ",
"nightwatch_local_workspace": "nightwatch ./test-browser/tests/workspace.js --config nightwatch.js --env chrome ",
"nightwatch_local_defaultLayout": "nightwatch ./test-browser/tests/defaultLayout.js --config nightwatch.js --env chrome ",
"nightwatch_local_publishContract": "nightwatch ./test-browser/tests/publishContract.js --config nightwatch.js --env chrome ",
Expand Down
3 changes: 2 additions & 1 deletion src/app/panels/terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,14 @@ class Terminal extends Plugin {
render () {
var self = this
if (self._view.el) return self._view.el
self._view.journal = yo`<div id="journal" class=${css.journal}></div>`
self._view.journal = yo`<div id="journal" class=${css.journal} data-id="terminalJournal"></div>`
self._view.input = yo`
<span class=${css.input} onload=${() => { this.focus() }} onpaste=${paste} onkeydown=${change}></span>
`
self._view.input.setAttribute('spellcheck', 'false')
self._view.input.setAttribute('contenteditable', 'true')
self._view.input.setAttribute('id', 'terminalCliInput')
self._view.input.setAttribute('data-id', 'terminalCliInput')

self._view.input.innerText = '\n'
self._view.cli = yo`
Expand Down
2 changes: 1 addition & 1 deletion src/app/ui/auto-complete-popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class AutoCompletePopup {
<div>
${self.data._options.map((item, index) => {
return yo`
<div class="${css.autoCompleteItem} ${css.listHandlerHide} item ${self._selectedElement === index ? 'border border-primary' : ''}">
<div data-id="autoCompletePopUpAutoCompleteItem" class="${css.autoCompleteItem} ${css.listHandlerHide} item ${self._selectedElement === index ? 'border border-primary' : ''}">
<div value=${index} onclick=${(event) => { self.handleSelect(event.srcElement.innerText) }}>
${getKeyOf(item)}
</div>
Expand Down
3 changes: 2 additions & 1 deletion test-browser/commands/executeScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ const EventEmitter = require('events')
class ExecuteScript extends EventEmitter {
command (script) {
this.api
.click('#terminalCli')
.clearValue('span[data-id="terminalCliInput"]')
.click('div[data-id="terminalCli"]')
.keys(script)
.keys(this.api.Keys.ENTER)
.keys(this.api.Keys.ENTER) // that's a bug... sometimes we need to press 2 times to execute a command
Expand Down
30 changes: 30 additions & 0 deletions test-browser/commands/journalChildIncludes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const EventEmitter = require('events')

/*
Checks if any child elements of journal (console) contains a matching value.
*/
class JournalChildIncludes extends EventEmitter {
command (val) {
let isTextFound = false
const browser = this.api

this.api.elements('css selector', '*[data-id="terminalJournal"]', (res) => {
res.value.forEach(function (jsonWebElement) {
const jsonWebElementId = jsonWebElement.ELEMENT

browser.elementIdText(jsonWebElementId, (jsonElement) => {
const text = jsonElement.value

if (text.indexOf(val) !== -1) isTextFound = true
})
})
})
browser.perform(() => {
browser.assert.ok(isTextFound, isTextFound ? `<*[data-id="terminalJournal"]> contains ${val}.` : `${val} not found in <*[data-id="terminalJournal"]> div:last-child>`)
this.emit('complete')
})
return this
}
}

module.exports = JournalChildIncludes
4 changes: 2 additions & 2 deletions test-browser/commands/journalLastChild.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ const EventEmitter = require('events')
class JournalLastChild extends EventEmitter {
command (val) {
this.api
.waitForElementVisible('#journal > div:last-child', 10000)
.assert.containsText('#journal > div:last-child', val).perform(() => {
.waitForElementVisible('*[data-id="terminalJournal"] > div:last-child', 10000)
.assert.containsText('*[data-id="terminalJournal"] > div:last-child', val).perform(() => {
this.emit('complete')
})
return this
Expand Down
6 changes: 3 additions & 3 deletions test-browser/commands/journalLastChildIncludes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ const EventEmitter = require('events')
class JournalLastChildIncludes extends EventEmitter {
command (val) {
this.api
.waitForElementVisible('#journal > div:last-child', 10000)
.getText('#journal > div:last-child', (result) => {
.waitForElementVisible('*[data-id="terminalJournal"] > div:last-child', 10000)
.getText('*[data-id="terminalJournal"] > div:last-child', (result) => {
console.log('JournalLastChildIncludes', result.value)
if (result.value.indexOf(val) === -1) return this.api.assert.fail(`wait for ${val} in ${result.value}`)
else this.api.assert.ok(`<#journal > div:last-child> contains ${val}.`)
else this.api.assert.ok(`<*[data-id="terminalJournal"] > div:last-child> contains ${val}.`)
this.emit('complete')
})
return this
Expand Down
17 changes: 0 additions & 17 deletions test-browser/tests/console.js

This file was deleted.

1 change: 1 addition & 0 deletions test-browser/tests/gist.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ module.exports = {
})
.end()
},

tearDown: sauce
}
1 change: 1 addition & 0 deletions test-browser/tests/importFromGist.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = {
before: function (browser, done) {
init(browser, done)
},

'Load Gist Modal': function (browser) {
browser
.waitForElementVisible('#icon-panel', 10000)
Expand Down
59 changes: 59 additions & 0 deletions test-browser/tests/terminal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'use strict'
var init = require('../helpers/init')
var sauce = require('./sauce')

module.exports = {
before: function (browser, done) {
init(browser, done, 'http://127.0.0.1:8080?plugins=solidity,udapp', false)
},

'Should execution a simple console command': function (browser) {
browser
.waitForElementVisible('*[data-id="terminalCli"]', 10000)
.executeScript('1+1')
.journalLastChild('2')
},

'Should clear console': function (browser) {
browser
.waitForElementVisible('*[data-id="terminalCli"]')
.journalChildIncludes('Welcome to Remix')
.click('#clearConsole')
.assert.containsText('*[data-id="terminalJournal"]', '')
},

'Should display auto-complete menu': function (browser) {
browser
.waitForElementVisible('*[data-id="terminalCli"]')
.click('*[data-id="terminalCli"]')
.keys('remix.')
.assert.visible('*[data-id="autoCompletePopUpAutoCompleteItem"]')
},

'Should execute remix.help() command': function (browser) {
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) {
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')
.end()
},

tearDown: sauce
}

0 comments on commit c94af82

Please sign in to comment.