Commit 3b6018f4 3b6018f4de9005894e6d911567b82efe76f4094e by Nathan Black

Update tester to output tailored messages for waitFor.timeouts

1 parent 9bad6047
......@@ -164,15 +164,6 @@ var Tester = function Tester(casper, options) {
}
});
// casper events
this.casper.on('error', function onCasperError(msg, backtrace) {
self.processPhantomError(msg, backtrace);
});
this.casper.on('waitFor.timeout', function onWaitForTimeout(timeout) {
this.warn(f('wait timeout of %dms reached', timeout));
});
function errorHandler(error, backtrace) {
self.casper.unwait();
if (error instanceof Error) {
......@@ -196,6 +187,40 @@ var Tester = function Tester(casper, options) {
self.done();
}
// casper events
this.casper.on('error', function onCasperError(msg, backtrace) {
self.processPhantomError(msg, backtrace);
});
this.casper.on('waitFor.timeout', function onWaitForTimeout(timeout, details) {
var message = f("Wait timeout occured (%dms)", timeout);
details = details || {};
if (details.selector) {
message = f(details.waitWhile ? '"%s" never went away in %dms' : '"%s" still did not exist in %dms', details.selector, timeout);
}
else if (details.visible) {
message = f(details.waitWhile ? '"%s" never disappeared in %dms' : '"%s" never appeared in %dms', details.visible, timeout);
}
else if (details.url || details.resource) {
message = f('%s did not load in %dms', details.url || details.resource, timeout);
}
else if (details.popup) {
message = f('%s did not pop up in %dms', details.popup, timeout);
}
else if (details.text) {
message = f('"%s" did not appear in the page in %dms', details.text, timeout);
}
else if (details.selectorTextChange) {
message = f('"%s" did not have a text change in %dms', details.selectorTextChange, timeout);
}
else if (utils.isFunction(details.testFx)) {
message = f('"%s" did not evaluate to something truthy in %dms', details.testFx.toString(), timeout);
}
errorHandlerAndDone(new TimedOutError(message));
});
[
'wait.error',
'waitFor.timeout.error',
......@@ -227,9 +252,7 @@ var Tester = function Tester(casper, options) {
throw new TimedOutError(f("Timeout occured (%dms)", timeout));
};
this.casper.options.onWaitTimeout = function test_onWaitTimeout(timeout) {
throw new TimedOutError(f("Wait timeout occured (%dms)", timeout));
};
this.casper.options.onWaitTimeout = function () {};
};
// Tester class is an EventEmitter
......
......@@ -287,6 +287,21 @@ class TestCommandOutputTest(CasperExecTestBase):
], failing=True)
@timeout(20)
def test_waitFor_timeout(self):
# using begin()
script_path = os.path.join(TEST_ROOT, 'tester', 'waitFor_timeout.js')
self.assertCommandOutputContains('test ' + script_path, [
'"p.nonexistent" still did not exist in',
'"#encoded" did not have a text change in',
'"p[style]" never appeared in',
'/github\.com/ did not load in',
'/foobar/ did not pop up in',
'"Lorem ipsum" did not appear in the page in',
'return false',
'did not evaluate to something truthy in'
], failing=True)
@timeout(20)
def test_dubious_test(self):
script_path = os.path.join(TEST_ROOT, 'tester', 'dubious.js')
self.assertCommandOutputContains('test ' + script_path, [
......
/*global casper*/
/*jshint strict:false*/
casper.options.waitTimeout = 500;
casper.test.begin('waitForSelector fails with expected message', 1, function(test) {
casper.start('../site/waitFor.html');
casper.waitForSelector('p.nonexistent', function() {
throw new Error('waitForSelector found something it should not have');
});
casper.run(function() {
test.done();
});
});
casper.test.begin('waitWhileSelector fails with expected message', 1, function(test) {
casper.start('../site/waitFor.html');
casper.waitForSelector('#encoded');
casper.waitWhileSelector('#encoded', function() {
throw new Error('waitWhileSelector thought something got removed when it did not');
});
casper.run(function() {
test.done();
});
});
casper.test.begin('waitForSelectorTextChange fails with expected message', 1, function(test) {
casper.start('../site/waitFor.html');
casper.waitForSelectorTextChange('#encoded', function() {
throw new Error('waitForSelectorTextChange thought text changed when it did not');
});
casper.run(function() {
test.done();
});
});
casper.test.begin('waitUntilVisible fails with expected message', 1, function(test) {
casper.start('../site/waitFor.html');
casper.waitUntilVisible('p[style]', function() {
throw new Error('waitUntilVisible falsely identified a hidden paragraph');
});
casper.run(function() {
test.done();
});
});
casper.test.begin('waitWhileVisible fails with expected message', 1, function(test) {
casper.start('../site/waitFor.html');
casper.waitWhileVisible('img', function() {
throw new Error('waitWhileVisible thought something disappeared when it did not');
});
casper.run(function() {
test.done();
});
});
casper.test.begin('waitForUrl fails with expected message', 1, function(test) {
casper.start('../site/waitFor.html');
casper.waitForUrl(/github\.com/, function() {
throw new Error('waitForUrl thought we actually navigated to GitHub');
});
casper.run(function() {
test.done();
});
});
casper.test.begin('waitForPopup fails with expected message', 1, function(test) {
casper.start('../site/waitFor.html');
casper.waitForPopup(/foobar/, function() {
throw new Error('waitForPopup found something it should not have');
});
casper.run(function() {
test.done();
});
});
casper.test.begin('waitForText fails with expected message', 1, function(test) {
casper.start('../site/waitFor.html');
casper.waitForText("Lorem ipsum", function() {
throw new Error('waitForText found something it should not have');
});
casper.run(function() {
test.done();
});
});
casper.test.begin('waitFor fails with expected message', 1, function(test) {
casper.start('../site/waitFor.html');
casper.waitFor(function() {
return false
}, function() {
throw new Error('waitFor fasely succeeded');
});
casper.run(function() {
test.done();
});
});
\ No newline at end of file