Skip to content

Commit

Permalink
Fix 'ballot' and 'compiling' browser tests under nightwatch_local
Browse files Browse the repository at this point in the history
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.<anonymous> (/home/scottt/work/remix-0.8/remix-ide/test-browser/helpers/contracts.js:50:5)
```
  • Loading branch information
scottt committed May 25, 2019
1 parent de4dfad commit 673dfa7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
27 changes: 26 additions & 1 deletion test-browser/helpers/contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ module.exports = {
getAddressAtPosition,
clickLaunchIcon,
scrollInto,
signMsg
signMsg,
waitForValue
}

function clickLaunchIcon (icon) {
Expand Down Expand Up @@ -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
}
3 changes: 2 additions & 1 deletion test-browser/tests/ballot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
11 changes: 7 additions & 4 deletions test-browser/tests/compiling.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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_";
Expand All @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit 673dfa7

Please sign in to comment.