Commit 4beba8b5 authored by Colin Eberhardt's avatar Colin Eberhardt

improved test failure reporting

parent 1127b0a3
...@@ -194,8 +194,8 @@ module.exports.todoMVCTest = function (frameworkName, baseUrl, speedMode, laxMod ...@@ -194,8 +194,8 @@ module.exports.todoMVCTest = function (frameworkName, baseUrl, speedMode, laxMod
createStandardItems(); createStandardItems();
page.doubleClickItemAtIndex(1); page.doubleClickItemAtIndex(1);
testOps.assertItemToggleIsHidden(); testOps.assertItemToggleIsHidden(1);
testOps.assertItemLabelIsHidden(); testOps.assertItemLabelIsHidden(1);
}); });
test.it('should save edits on enter', function () { test.it('should save edits on enter', function () {
......
...@@ -9,36 +9,37 @@ function TestOperations(page) { ...@@ -9,36 +9,37 @@ function TestOperations(page) {
// element exists. The standard approach is to obtain an array of elements // element exists. The standard approach is to obtain an array of elements
// and test that the length is zero. In this case the item is hidden if // and test that the length is zero. In this case the item is hidden if
// it is either not in the DOM, or is in the DOM but not visible. // it is either not in the DOM, or is in the DOM but not visible.
function testIsHidden(elements) { function testIsHidden(elements, name) {
if (elements.length === 1) { if (elements.length === 1) {
elements[0].isDisplayed().then(function (isDisplayed) { elements[0].isDisplayed().then(function (isDisplayed) {
assert(!isDisplayed); assert(!isDisplayed, 'the ' + name + ' element should be hidden');
}); });
} }
} }
function testIsVisible(elements) { function testIsVisible(elements, name) {
assert.equal(1, elements.length); assert.equal(1, elements.length);
elements[0].isDisplayed().then(function (isDisplayed) { elements[0].isDisplayed().then(function (isDisplayed) {
assert(isDisplayed); assert(isDisplayed, 'the ' + name + ' element should be displayed');
}); });
} }
this.assertClearCompleteButtonIsHidden = function () { this.assertClearCompleteButtonIsHidden = function () {
page.tryGetClearCompleteButton().then(function (element) { page.tryGetClearCompleteButton().then(function (element) {
testIsHidden(element); testIsHidden(element, 'clear completed items button');
}); });
}; };
this.assertClearCompleteButtonIsVisible = function () { this.assertClearCompleteButtonIsVisible = function () {
page.tryGetClearCompleteButton().then(function (element) { page.tryGetClearCompleteButton().then(function (element) {
testIsVisible(element); testIsVisible(element, 'clear completed items button');
}); });
}; };
this.assertItemCount = function (itemCount) { this.assertItemCount = function (itemCount) {
page.getItemElements().then(function (toDoItems) { page.getItemElements().then(function (toDoItems) {
assert.equal(itemCount, toDoItems.length); assert.equal(itemCount, toDoItems.length,
itemCount + ' items expected in the todo list, ' + toDoItems.length + ' items observed');
}); });
}; };
...@@ -53,37 +54,38 @@ function TestOperations(page) { ...@@ -53,37 +54,38 @@ function TestOperations(page) {
this.assertMainSectionIsHidden = function () { this.assertMainSectionIsHidden = function () {
page.tryGetMainSectionElement().then(function (mainSection) { page.tryGetMainSectionElement().then(function (mainSection) {
testIsHidden(mainSection); testIsHidden(mainSection, 'main');
}); });
}; };
this.assertFooterIsHidden = function () { this.assertFooterIsHidden = function () {
page.tryGetFooterElement().then(function (footer) { page.tryGetFooterElement().then(function (footer) {
testIsHidden(footer); testIsHidden(footer, 'footer');
}); });
}; };
this.assertMainSectionIsVisible = function () { this.assertMainSectionIsVisible = function () {
page.tryGetMainSectionElement().then(function (mainSection) { page.tryGetMainSectionElement().then(function (mainSection) {
testIsVisible(mainSection); testIsVisible(mainSection, 'main');
}); });
}; };
this.assertItemToggleIsHidden = function () { //TODO: fishy!
page.tryGetToggleForItemAtIndex().then(function (toggleItem) { this.assertItemToggleIsHidden = function (index) {
testIsHidden(toggleItem); page.tryGetToggleForItemAtIndex(index).then(function (toggleItem) {
testIsHidden(toggleItem, 'item-toggle');
}); });
}; };
this.assertItemLabelIsHidden = function () { this.assertItemLabelIsHidden = function (index) {
page.tryGetItemLabelAtIndex().then(function (toggleItem) { page.tryGetItemLabelAtIndex(index).then(function (toggleItem) {
testIsHidden(toggleItem); testIsHidden(toggleItem, 'item-label');
}); });
}; };
this.assertFooterIsVisible = function () { this.assertFooterIsVisible = function () {
page.tryGetFooterElement().then(function (footer) { page.tryGetFooterElement().then(function (footer) {
testIsVisible(footer); testIsVisible(footer, 'footer');
}); });
}; };
...@@ -95,14 +97,17 @@ function TestOperations(page) { ...@@ -95,14 +97,17 @@ function TestOperations(page) {
this.assertItemText = function (itemIndex, textToAssert) { this.assertItemText = function (itemIndex, textToAssert) {
page.getItemLabelAtIndex(itemIndex).getText().then(function (text) { page.getItemLabelAtIndex(itemIndex).getText().then(function (text) {
assert.equal(textToAssert, text.trim()); assert.equal(textToAssert, text,
'A todo item with text \'' + textToAssert + '\' was expected at index ' +
itemIndex + ', the text \'' + text + '\' was observed');
}); });
}; };
// tests that the list contains the following items, independant of order // tests that the list contains the following items, independant of order
this.assertItems = function (textArray) { this.assertItems = function (textArray) {
page.getItemLabels().then(function (labels) { page.getItemLabels().then(function (labels) {
assert.equal(textArray.length, labels.length); assert.equal(textArray.length, labels.length,
textArray.length, + ' items expected in the todo list, ' + labels.length + ' items observed');
// create an array of promises which check the presence of the // create an array of promises which check the presence of the
// label text within the 'textArray' // label text within the 'textArray'
var tests = []; var tests = [];
...@@ -121,7 +126,7 @@ function TestOperations(page) { ...@@ -121,7 +126,7 @@ function TestOperations(page) {
this.assertItemCountText = function (textToAssert) { this.assertItemCountText = function (textToAssert) {
page.getItemsCountElement().getText().then(function (text) { page.getItemsCountElement().getText().then(function (text) {
assert.equal(textToAssert, text.trim()); assert.equal(textToAssert, text.trim(), 'the item count text was incorrect');
}); });
}; };
...@@ -129,7 +134,8 @@ function TestOperations(page) { ...@@ -129,7 +134,8 @@ function TestOperations(page) {
this.assertItemAtIndexIsCompleted = function (index) { this.assertItemAtIndexIsCompleted = function (index) {
page.getItemElements().then(function (toDoItems) { page.getItemElements().then(function (toDoItems) {
toDoItems[index].getAttribute('class').then(function (cssClass) { toDoItems[index].getAttribute('class').then(function (cssClass) {
assert(cssClass.indexOf('completed') !== -1); assert(cssClass.indexOf('completed') !== -1,
'the item at index ' + index + ' should have been marked as completed');
}); });
}); });
}; };
...@@ -139,7 +145,8 @@ function TestOperations(page) { ...@@ -139,7 +145,8 @@ function TestOperations(page) {
toDoItems[index].getAttribute('class').then(function (cssClass) { toDoItems[index].getAttribute('class').then(function (cssClass) {
// the maria implementation uses an 'incompleted' CSS class which is redundant // the maria implementation uses an 'incompleted' CSS class which is redundant
// TODO: this should really be moved into the pageLaxMode // TODO: this should really be moved into the pageLaxMode
assert(cssClass.indexOf('completed') === -1 || cssClass.indexOf('incompleted') !== -1); assert(cssClass.indexOf('completed') === -1 || cssClass.indexOf('incompleted') !== -1,
'the item at index ' + index + ' should not have been marked as completed');
}); });
}); });
}; };
...@@ -148,26 +155,33 @@ function TestOperations(page) { ...@@ -148,26 +155,33 @@ function TestOperations(page) {
return cssClass.indexOf('selected') !== -1; return cssClass.indexOf('selected') !== -1;
} }
this.assertFilterAtIndexIsSelected = function (index) { this.assertFilterAtIndexIsSelected = function (selectedIndex) {
page.getFilterElements().then(function (filterElements) { page.getFilterElements().then(function (filterElements) {
filterElements[0].getAttribute('class').then(function (cssClass) {
assert(index === 0 ? isSelected(cssClass) : !isSelected(cssClass));
});
filterElements[1].getAttribute('class').then(function (cssClass) { // create an array of promises, each one holding a test
assert(index === 1 ? isSelected(cssClass) : !isSelected(cssClass)); var tests = [];
});
filterElements[2].getAttribute('class').then(function (cssClass) { // push a test into the array, avoiding the classic JS for loops + closures issue!
assert(index === 2 ? isSelected(cssClass) : !isSelected(cssClass)); function pushTest(itemIndex) {
}); tests.push(filterElements[itemIndex].getAttribute('class').then(function (cssClass) {
assert(selectedIndex === itemIndex ? isSelected(cssClass) : !isSelected(cssClass),
'the filter / route at index ' + selectedIndex + ' should have been selected');
}));
}
for (var i=0; i<3;i++) {
pushTest(i);
};
// execute all the tests
return Q.all(tests);
}); });
}; };
this.assertCompleteAllIsClear = function () { this.assertCompleteAllIsClear = function () {
page.getMarkAllCompletedCheckBox().then(function (markAllCompleted) { page.getMarkAllCompletedCheckBox().then(function (markAllCompleted) {
markAllCompleted.isSelected().then(function (isSelected) { markAllCompleted.isSelected().then(function (isSelected) {
assert(!isSelected); assert(!isSelected, 'the mark-all-completed checkbox should be clear');
}); });
}); });
}; };
...@@ -175,7 +189,7 @@ function TestOperations(page) { ...@@ -175,7 +189,7 @@ function TestOperations(page) {
this.assertCompleteAllIsChecked = function () { this.assertCompleteAllIsChecked = function () {
page.getMarkAllCompletedCheckBox().then(function (markAllCompleted) { page.getMarkAllCompletedCheckBox().then(function (markAllCompleted) {
markAllCompleted.isSelected().then(function (isSelected) { markAllCompleted.isSelected().then(function (isSelected) {
assert(isSelected); assert(isSelected, 'the mark-all-completed checkbox should be checked');
}); });
}); });
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment