diff --git a/doc/tests.md b/doc/tests.md index 08c64038c..d2efa06af 100644 --- a/doc/tests.md +++ b/doc/tests.md @@ -62,8 +62,10 @@ All methods are chainable: All tests in a suite will fail if none of the elements will be found. -* `ignoreElements('selector1', 'selector2', ...)` - elements, matching +* `ignoreElements('.selector1', {every: '.selector2'}, ...)` - elements, matching specified selectors will be ignored when comparing images. + - `.selector1` - Ignore only the first matched element. + - `{every: '.selector2'}` - Ignore all matched elements. * `setTolerance(value)` - overrides global tolerance value for the whole suite (See `tolerance`option description in [config](./config.md) documentation diff --git a/lib/browser/client-scripts/gemini.js b/lib/browser/client-scripts/gemini.js index a32fe18ee..96b3fa028 100644 --- a/lib/browser/client-scripts/gemini.js +++ b/lib/browser/client-scripts/gemini.js @@ -114,18 +114,21 @@ function getCaptureRect(selectors) { function findIgnoreAreas(selectors) { var result = []; util.each(selectors, function(selector) { - var element = lib.queryFirst(selector); - if (element) { - var rect = getElementCaptureRect(element); - if (rect) { - result.push(rect.round().serialize()); - } - } + var elements = typeof selector === 'string' + ? [lib.queryFirst(selector)] + : lib.queryAll(selector.every); + + util.each(elements, addIgnoreArea.bind(result)); }); return result; } +function addIgnoreArea(element) { + var rect = element && getElementCaptureRect(element); + rect && this.push(rect.round().serialize()); +} + function isHidden(css, clientRect) { return css.display === 'none' || css.visibility === 'hidden' || diff --git a/lib/tests-api/suite-builder.js b/lib/tests-api/suite-builder.js index 693db25b9..8569b0329 100644 --- a/lib/tests-api/suite-builder.js +++ b/lib/tests-api/suite-builder.js @@ -93,8 +93,8 @@ module.exports = function(suite) { this.ignoreElements = function ignoreElements() { var selectors = argumentsToArray(arguments); - if (selectors.some(notString)) { - throw new TypeError('suite.ignoreElements accepts only strings or array of strings'); + if (selectors.some(isNotValidSelector)) { + throw new TypeError('suite.ignoreElements accepts strings, object with property "every" as string or array of them'); } suite.ignoreSelectors = selectors; return this; @@ -133,6 +133,11 @@ function notString(arg) { return typeof arg !== 'string'; } +// Check if selector is not a string or not an object with "every" option. +function isNotValidSelector(arg) { + return !(_.isString(arg) || (_.isObject(arg) && _.isString(arg.every))); +} + function argumentsToArray(args) { if (args.length === 1 && Array.isArray(args[0])) { return args[0];