more test improvement wooo

This commit is contained in:
Peter Cottle 2015-03-23 20:13:57 -07:00
parent 4b5eb3d54d
commit c7aeae7913
3 changed files with 48 additions and 7 deletions

View file

@ -55,6 +55,12 @@ var CasperUtils = {
}; };
}, },
visibleSelector: function(selector) {
return function then() {
this.test.assertVisible(selector);
};
},
existingIDs: function(existingIDs) { existingIDs: function(existingIDs) {
return function then() { return function then() {
existingIDs.forEach(function(id) { existingIDs.forEach(function(id) {
@ -77,14 +83,12 @@ var CasperUtils = {
entirePage: function () { entirePage: function () {
screenshotCounter++; screenshotCounter++;
var documentBounds = this.evaluate(function() {
return __utils__.getElementBounds('body');
});
casper.capture('screenshots/entirePage' + screenshotCounter + '.png', { casper.capture('screenshots/entirePage' + screenshotCounter + '.png', {
top: 0, top: 0,
left: 0, left: 0,
height: documentBounds.height, // These seem to be the hardcoded viewport dimensions
width: documentBounds.width height: 600,
width: 1000
}); });
casper.echo('<<< Took screenshot ' + screenshotCounter + ' >>>', 'COMMENT'); casper.echo('<<< Took screenshot ' + screenshotCounter + ' >>>', 'COMMENT');
} }
@ -121,7 +125,6 @@ var CasperUtils = {
return this.evaluate(function() { return this.evaluate(function() {
var allVisible = true; var allVisible = true;
for (var i = 0; i < ids.length; i++) { for (var i = 0; i < ids.length; i++) {
allVisible = allVisible && __utils__.exists('#' + ids[i]);
allVisible = allVisible && __utils__.visible('#' + ids[i]); allVisible = allVisible && __utils__.visible('#' + ids[i]);
} }
return allVisible; return allVisible;

View file

@ -0,0 +1,35 @@
var CasperUtils = require('./casperUtils').CasperUtils;
casper.start(
CasperUtils.getUrlForCommands([
'level intro1 --noIntroDialog --noStartCommand',
]),
function() {
casper.waitFor(CasperUtils.waits.jsMount)
.waitFor(CasperUtils.waits.allCommandsFinished)
.then(CasperUtils.asserts.visibleSelectors([
'p.commandLine.finished',
'div.levelNameWrapper'
]))
.then(CasperUtils.screenshot.entirePage)
.then(function() {
this.mouse.click('#show-goal')
})
.then(CasperUtils.waits.selectorVisible(
'p.helperText'
))
.wait(1000)
.then(CasperUtils.screenshot.entirePage)
.then(CasperUtils.asserts.visibleSelector('p.helperText'))
.then(function() {
var text = this.evaluate(function() {
return document.querySelector('p.helperText').innerText;
});
casper.echo(text);
this.test.assert(
text === 'You can hide this window with "hide goal"'
);
})
.then(CasperUtils.testDone);
}).run();

View file

@ -31,6 +31,7 @@ casper.start(
casper.waitFor(CasperUtils.waits.jsMount) casper.waitFor(CasperUtils.waits.jsMount)
.waitFor(CasperUtils.waits.commandVisible) .waitFor(CasperUtils.waits.commandVisible)
.wait(1000)
.then( .then(
CasperUtils.multiAssert( CasperUtils.multiAssert(
CasperUtils.asserts.visibleSelectors([ CasperUtils.asserts.visibleSelectors([
@ -46,8 +47,10 @@ casper.start(
this.mouse.click('div[data-id="remote"]'); this.mouse.click('div[data-id="remote"]');
}) })
.then(CasperUtils.waits.idVisible('levelIcon-remote1')) .then(CasperUtils.waits.idVisible('levelIcon-remote1'))
.then(CasperUtils.waits.idsVisible( .wait(1000)
.then(CasperUtils.asserts.visibleIDs(
levelIconIDsForPages(5, numLevelSequences) levelIconIDsForPages(5, numLevelSequences)
)) ))
.then(CasperUtils.screenshot.entirePage)
.then(CasperUtils.testDone); .then(CasperUtils.testDone);
}).run(); }).run();