I am wishing to conditionally execute some commands/assertions depending on whether previous assertions succeeded or not.
I can't seem to find a way to nest then
calls or conditionally execute things using the chaining syntax of leadfoot.
Here is my test (the returns at the end of each function is due to this being compiled coffeescript):
tdd.test(tableUrl, function() {
this.timeout = 60000;
return this.remote.get(require.toUrl("tests/pages/" + tableUrl))
.setPageLoadTimeout(60000)
.setFindTimeout(20000)
.findByCssSelector('.dataTables_wrapper table.dataTable')
.then(null, function(err) {
return assert.fail('', '', 'Table should exist');
}).then(pollUntil(function() {
var table;
table = document.querySelector('.dataTables_wrapper table.dataTable');
if (table.querySelectorAll('tbody td').length > 1) {
return true;
} else {
return null;
}
}, null, 20000, 500)).then(function() {
console.log('Assertion succeeded: Table should have data');
return assert.ok(true, 'Table should have data');
}, function(err) {
return assert.fail('', '', 'Table should have data');
});
});
When a table does not exist, both 'Table should exist' and 'Table should have data' assertions should be reported as failing. However, only the last assertion is failing. When I comment out the 'Table should have data' error callback, the 'Table should exist' assertion is reported as failing correctly.
What I would like to do is
test if a
table
exists (via findByCssSelector).a) If it exists, report that it exists and test to see that it has more than one
td
element. This is currently done viapollUntil
to ensure that the command is complete/promise is resolved as soon as more than onetd
is found instead of waiting for the whole implicit wait time.b) If it does not exist, report that it does not exist.
I can't seem to find a way of not executing the error callback of the second 'Table should have data' poll if the first findByCssSelector
fails, due to lack of conditionals and only the last assertion failure being reported in a test.