I baked this down to the simplest example in our codebase and it's showing what you see in the console image I took a screenshot of.
module.exports = {
'HTML Page Integrity Checks' : function (browser) {
browser
.url(browser.launch_url + "/pagetemplates/homepage")
.waitForElementVisible("body", 1000)
.waitForElementVisible("header", 1000)
.waitForElementVisible("div.container", 1000)
.waitForElementVisible("footer", 1000)
.waitForElementVisible("div.drawer", 1000)
.end();
}
}
var util = require('util'),
async = require('async'),
events = require('events');
function Assertion() {
events.EventEmitter.call(this);
this.startTimer = null;
this.cb = null;
this.ms = null;
this.abortOnFailure = true;
this.selector = null;
}
util.inherits(Assertion, events.EventEmitter);
Assertion.prototype.command = function(selectors, callback) {
var args = Array.prototype.slice.call(arguments, 0);
var lastArgument = args[args.length - 1];
if (typeof (lastArgument) === 'function') {
callback = args.pop();
} else {
callback = function() {};
}
this.startTimer = new Date().getTime();
this.cb = callback;
this.selectors = args.slice(0);
this.checkElements();
return this;
};
Assertion.prototype.checkElements = function() {
var self = this;
var missing = [];
var found = [];
var selectors = this.selectors;
function checkElement(selector, cb) {
self.client.element.call(self, 'css selector', selector, function(result) {
var value;
if (result.status == 0) {
value = result.value.ELEMENT;
}
if (value) {
found.push(selector);
} else {
missing.push(selector);
}
cb();
});
}
function returnResults(err) {
var result = missing.length;
if (result === 0) {
var foundMsg = found.map(function(el){
return '<' + el + '>';
});
var msg = foundMsg.join(', ') + ' located on page.';
var passed = true;
} else {
var missingMsg = missing.map(function(el){
return '<' + el + '>';
});
var msg = missingMsg.join(', ') + ' missing from page.';
var passed = false;
}
self.client.assertion(passed, result, 0, msg, false);
self.cb(result);
self.emit('complete');
}
async.each(selectors, checkElement, returnResults);
};
module.exports = Assertion;--
You received this message because you are subscribed to the Google Groups "NightwatchJs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nightwatchjs...@googlegroups.com.
To post to this group, send email to nightw...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nightwatchjs/2929fa7a-4350-455f-bd3e-0935737aaba4%40googlegroups.com.
Hey guys, I've just released 0.4 with so many changes/refactoring that I'm a bit concerned about backwards compatibility issue. Could you let me know if you have any issues with custom command/assertions?
The assertions have a new interface now, but this format should still work. I'm curious if this complex example of custom assertion still can be written with the new interface and how it would look.
Oh scratch that 2nd point. I had missed it when transcribing your code :)
--
You received this message because you are subscribed to the Google Groups "NightwatchJs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nightwatchjs...@googlegroups.com.
To post to this group, send email to nightw...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nightwatchjs/09258387-7e11-4967-80dd-de7f3d8eadf4%40googlegroups.com.