From 191c02af1ebfc7e6c53dc88d97c4e3ca23fbea8b Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Wed, 26 Oct 2016 16:46:32 +0200 Subject: Basic skeleton --- test/e2e/custom-assertions/elementCount.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 test/e2e/custom-assertions/elementCount.js (limited to 'test/e2e/custom-assertions/elementCount.js') diff --git a/test/e2e/custom-assertions/elementCount.js b/test/e2e/custom-assertions/elementCount.js new file mode 100644 index 00000000..c0d5fe00 --- /dev/null +++ b/test/e2e/custom-assertions/elementCount.js @@ -0,0 +1,26 @@ +// A custom Nightwatch assertion. +// the name of the method is the filename. +// can be used in tests like this: +// +// browser.assert.elementCount(selector, count) +// +// for how to write custom assertions see +// http://nightwatchjs.org/guide#writing-custom-assertions +exports.assertion = function (selector, count) { + this.message = 'Testing if element <' + selector + '> has count: ' + count + this.expected = count + this.pass = function (val) { + return val === this.expected + } + this.value = function (res) { + return res.value + } + this.command = function (cb) { + var self = this + return this.api.execute(function (selector) { + return document.querySelectorAll(selector).length + }, [selector], function (res) { + cb.call(self, res) + }) + } +} -- cgit v1.2.3-70-g09d2