From 673dfa75a44ef7438c3c3fa79c734ef385bc2a54 Mon Sep 17 00:00:00 2001 From: Scott Tsai Date: Sat, 25 May 2019 19:37:37 +0800 Subject: [PATCH] Fix 'ballot' and 'compiling' browser tests under nightwatch_local MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Running `npm rpn nightwatch_local`, a few tests would consistently fail due to the "Account" dropdown in the Run Tab (i.e. 'select#txorigin') being filled-in asynchronously and the tests were running without a valid account value. E.g. contract deployment would fail with: "creation of Ballot errored: Invalid account selected" This patch fixes it by adding a, admittedly weird looking, `waitForValue()` function which checks the `value` attribute for some DOM element is present. Browsing the nightwatch API, I expected: `browser.expect.element(selector).value` to provide equivalent functionality but empirically I couldn't get that to work. Tested with: ``` nightwatch 0.9.21 selenium-server-standalone 3.9.1 ChromeDriver 74.0.3729.6 Chrome 74.0.3729.169 ``` Error message on test failure: ``` - Ballot (13.92s) Timed out while waiting for element <.instance:nth-of-type(2)> to be present for 10000 milliseconds. - expected "found" but got: "not found" at runTests (/home/scottt/work/remix-0.8/remix-ide/test-browser/tests/ballot.js:40:8) at Object.Ballot (/home/scottt/work/remix-0.8/remix-ide/test-browser/tests/ballot.js:19:5) ✖ compiling - Compiling (13.389s) Timed out while waiting for element <.instance:nth-of-type(2)> to be present for 10000 milliseconds. - expected "found" but got: "not found" at /home/scottt/work/remix-0.8/remix-ide/test-browser/tests/compiling.js:43:8 at getCompiledContracts (/home/scottt/work/remix-0.8/remix-ide/test-browser/helpers/contracts.js:84:5) at Object. (/home/scottt/work/remix-0.8/remix-ide/test-browser/helpers/contracts.js:50:5) ``` --- test-browser/helpers/contracts.js | 27 ++++++++++++++++++++++++++- test-browser/tests/ballot.js | 3 ++- test-browser/tests/compiling.js | 11 +++++++---- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/test-browser/helpers/contracts.js b/test-browser/helpers/contracts.js index 949afb02173..cbbfb841237 100644 --- a/test-browser/helpers/contracts.js +++ b/test-browser/helpers/contracts.js @@ -26,7 +26,8 @@ module.exports = { getAddressAtPosition, clickLaunchIcon, scrollInto, - signMsg + signMsg, + waitForValue } function clickLaunchIcon (icon) { @@ -467,3 +468,27 @@ function goToVMtraceStep (browser, step, done, incr) { } }) } + +function waitForValue (selector, retryCount) { + function performFunc (browser, done) { + browser.getValue(selector, function (result) { + const value = result.value + if (value) { + done() + } else { + if (retryCount === 0) { + done() + } else { + retryCount-- + browser.pause(500).perform(function (browser, done2) { + performFunc(browser, function () { + done2() + done() + }) + }) + } + } + }) + } + return performFunc +} diff --git a/test-browser/tests/ballot.js b/test-browser/tests/ballot.js index 8460565673a..0e96a15cc85 100644 --- a/test-browser/tests/ballot.js +++ b/test-browser/tests/ballot.js @@ -36,7 +36,8 @@ function runTests (browser, testData) { }) }).clickLaunchIcon('run') .setValue('input[placeholder="uint8 _numProposals"]', '1') - .click('#runTabView button[class^="instanceButton"]') + .perform(contractHelper.waitForValue('#txorigin', 10)) // browser.expect.element('#txorigin').value somehow doesn't work + .click('#runTabView button[class^="instanceButton"]') // "creation of Ballot errored: Invalid account selected" .waitForElementPresent('.instance:nth-of-type(2)') .click('.instance:nth-of-type(2) > div > button') .testFunction('delegate - transact (not payable)', '0x0571a2439ea58bd349dd130afb8aff62a33af14c06de0dbc3928519bdf13ce2e', diff --git a/test-browser/tests/compiling.js b/test-browser/tests/compiling.js index e7c4e943471..bff2038de81 100644 --- a/test-browser/tests/compiling.js +++ b/test-browser/tests/compiling.js @@ -39,6 +39,7 @@ function runTests (browser) { function testSimpleContract (browser, callback) { contractHelper.testContracts(browser, 'Untitled.sol', sources[0]['browser/Untitled.sol'], ['TestContract'], function () { browser.clickLaunchIcon('run') + .perform(contractHelper.waitForValue('#txorigin', 10)) .click('#runTabView button[class^="instanceButton"]') .waitForElementPresent('.instance:nth-of-type(2)') .click('.instance:nth-of-type(2) > div > button') @@ -70,6 +71,7 @@ function testSimpleContract (browser, callback) { function testReturnValues (browser, callback) { contractHelper.testContracts(browser, 'returnValues.sol', sources[1]['browser/returnValues.sol'], ['testReturnValues'], function () { browser.clickLaunchIcon('run') + .perform(contractHelper.waitForValue('#txorigin', 10)) .click('#runTabView button[class^="instanceButton"]') .waitForElementPresent('.instance:nth-of-type(2)') .click('.instance:nth-of-type(2) > div > button') @@ -108,6 +110,7 @@ function testReturnValues (browser, callback) { function testInputValues (browser, callback) { contractHelper.testContracts(browser, 'inputValues.sol', sources[2]['browser/inputValues.sol'], ['test'], function () { browser.clickLaunchIcon('run') + .perform(contractHelper.waitForValue('#txorigin', 10)) .click('#runTabView button[class^="instanceButton"]') .waitForElementPresent('.instance:nth-of-type(2)') .click('.instance:nth-of-type(2) > div > button') @@ -160,8 +163,8 @@ function testInputValues (browser, callback) { var sources = [ {'browser/Untitled.sol': {content: ` - contract TestContract { function f() public returns (uint) { return 8; } - function g() public returns (uint, string memory, bool, uint) { + contract TestContract { function f() public returns (uint) { return 8; } + function g() public returns (uint, string memory, bool, uint) { uint payment = 345; bool payed = true; string memory comment = "comment_comment_"; @@ -176,7 +179,7 @@ var sources = [ _i = -345; _a = msg.sender; } - + function retunValues2 () public returns (byte _b, bytes2 _b2, bytes3 _b3, bytes memory _blit, bytes5 _b5, bytes6 _b6, string memory _str, bytes7 _b7, bytes22 _b22, bytes32 _b32) { _b = 0x12; _b2 = 0x1223; @@ -188,7 +191,7 @@ var sources = [ _blit = hex"123498"; _str = "this is a long string _ this is a long string _ this is a long string _ this is a long string _ this is a long string _ this is a long string _ this is a long string _ this is a long string _ this is a long string _ this is a long string _ this is a long string _ this is a long string _ this is a long string _ this is a long string _ this is a long string"; } - + function retunValues3 () public returns (ActionChoices _en, int[5][] memory _a1) { _en = ActionChoices.GoStraight; int[5][] memory a = new int[5][](3);