var page = require('webpage').create();
var url = 'src/index.html';
+var testMaxTime = 5000;
page.onResourceError = function(e) {
console.log("Error loading " + e.url);
phantom.exit();
}
+function waitForGenerate(fn, maxTime) {
+ if (!maxTime) {
+ maxTime = testMaxTime;
+ }
+ var start = new Date().getTime();
+ var prevAddressCount = -1;
+ var wait = function keepWaiting() {
+ var now = new Date().getTime();
+ var hasTimedOut = now - start > maxTime;
+ var addressCount = page.evaluate(function() {
+ return $(".address").length;
+ });
+ var hasFinished = addressCount > 0 && addressCount == prevAddressCount;
+ prevAddressCount = addressCount;
+ if (hasFinished) {
+ fn();
+ }
+ else if (hasTimedOut) {
+ console.log("Test timed out");
+ fn();
+ }
+ else {
+ setTimeout(keepWaiting, 100);
+ }
+ }
+ wait();
+}
+
function next() {
if (tests.length > 0) {
var testsStr = tests.length == 1 ? "test" : "tests";
$(".phrase").val("abandon abandon ability").trigger("input");
});
// get the address
- setTimeout(function() {
+ waitForGenerate(function() {
var actual = page.evaluate(function() {
return $(".address:first").text();
});
fail();
}
next();
- }, 1000);
+ });
});
},
$(".generate").click();
});
// get the new phrase
- setTimeout(function() {
+ waitForGenerate(function() {
var phrase = page.evaluate(function() {
return $(".phrase").val();
});
fail();
}
next();
- }, 1000);
+ });
});
},
$(".generate").click();
});
// check the new phrase is six words long
- setTimeout(function() {
+ waitForGenerate(function() {
var actualLength = page.evaluate(function() {
var words = $(".phrase").val().split(" ");
return words.length;
fail();
}
next();
- }, 1000);
+ });
});
},
$(".passphrase").val("secure_passphrase").trigger("input");
});
// check the address is generated correctly
- setTimeout(function() {
+ waitForGenerate(function() {
var actual = page.evaluate(function() {
return $(".address:first").text();
});
fail();
}
next();
- }, 1000);
+ });
});
},
$(".network").trigger("change");
});
// check the address is generated correctly
- setTimeout(function() {
+ waitForGenerate(function() {
var actual = page.evaluate(function() {
return $(".address:first").text();
});
fail();
}
next();
- }, 1000);
+ });
});
},
$(".network").trigger("change");
});
// check the address is generated correctly
- setTimeout(function() {
+ waitForGenerate(function() {
var actual = page.evaluate(function() {
return $(".address:first").text();
});
fail();
}
next();
- }, 1000);
+ });
});
},
$(".network").trigger("change");
});
// check the address is generated correctly
- setTimeout(function() {
+ waitForGenerate(function() {
var actual = page.evaluate(function() {
return $(".address:first").text();
});
fail();
}
next();
- }, 1000);
+ });
});
},
$(".network").trigger("change");
});
// check the address is generated correctly
- setTimeout(function() {
+ waitForGenerate(function() {
var actual = page.evaluate(function() {
return $(".address:first").text();
});
fail();
}
next();
- }, 1000);
+ });
});
},
$(".network").trigger("change");
});
// check the address is generated correctly
- setTimeout(function() {
+ waitForGenerate(function() {
var actual = page.evaluate(function() {
return $(".address:first").text();
});
fail();
}
next();
- }, 1000);
+ });
});
},
$(".network").trigger("change");
});
// check the address is generated correctly
- setTimeout(function() {
+ waitForGenerate(function() {
var actual = page.evaluate(function() {
return $(".address:first").text();
});
fail();
}
next();
- }, 1000);
+ });
});
},
$(".network").trigger("change");
});
// check the address is generated correctly
- setTimeout(function() {
+ waitForGenerate(function() {
var actual = page.evaluate(function() {
return $(".address:first").text();
});
fail();
}
next();
- }, 1000);
+ });
});
},
$(".network").trigger("change");
});
// check the address is generated correctly
- setTimeout(function() {
+ waitForGenerate(function() {
var actual = page.evaluate(function() {
return $(".address:first").text();
});
fail();
}
next();
- }, 1000);
+ });
});
},
$(".network").trigger("change");
});
// check the address is generated correctly
- setTimeout(function() {
+ waitForGenerate(function() {
var actual = page.evaluate(function() {
return $(".address:first").text();
});
fail();
}
next();
- }, 1000);
+ });
});
},
$(".phrase").trigger("input");
});
// check the address is generated correctly
- setTimeout(function() {
+ waitForGenerate(function() {
var actual = page.evaluate(function() {
return $(".seed").val();
});
fail();
}
next();
- }, 1000);
+ });
});
},
$(".phrase").trigger("input");
});
// check the address is generated correctly
- setTimeout(function() {
+ waitForGenerate(function() {
var actual = page.evaluate(function() {
return $(".root-key").val();
});
fail();
}
next();
- }, 1000);
+ });
});
},