Skip to content
This repository was archived by the owner on Sep 21, 2022. It is now read-only.

Commit c36ed78

Browse files
author
Mikhail Korotin
committed
feat: Allow to ignore every element, matching selector
1 parent a1b4f34 commit c36ed78

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

doc/tests.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@ All methods are chainable:
6262

6363
All tests in a suite will fail if none of the elements will be found.
6464

65-
* `ignoreElements('selector1', 'selector2', ...)` - elements, matching
65+
* `ignoreElements('.selector1', {every: '.selector2'}, ...)` - elements, matching
6666
specified selectors will be ignored when comparing images.
67+
- `.selector1` - Ignore only the first matched element.
68+
- `{every: '.selector2'}` - Ignore all matched elements.
6769

6870
* `setTolerance(value)` - overrides global tolerance value for the whole suite
6971
(See `tolerance`option description in [config](./config.md) documentation

lib/browser/client-scripts/gemini.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,21 @@ function getCaptureRect(selectors) {
114114
function findIgnoreAreas(selectors) {
115115
var result = [];
116116
util.each(selectors, function(selector) {
117-
var element = lib.queryFirst(selector);
118-
if (element) {
119-
var rect = getElementCaptureRect(element);
120-
if (rect) {
121-
result.push(rect.round().serialize());
122-
}
123-
}
117+
var elements = typeof selector === 'string'
118+
? [lib.queryFirst(selector)]
119+
: lib.queryAll(selector.every);
120+
121+
util.each(elements, addIgnoreArea.bind(result));
124122
});
125123

126124
return result;
127125
}
128126

127+
function addIgnoreArea(element) {
128+
var rect = element && getElementCaptureRect(element);
129+
rect && this.push(rect.round().serialize());
130+
}
131+
129132
function isHidden(css, clientRect) {
130133
return css.display === 'none' ||
131134
css.visibility === 'hidden' ||

lib/tests-api/suite-builder.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ module.exports = function(suite) {
9393
this.ignoreElements = function ignoreElements() {
9494
var selectors = argumentsToArray(arguments);
9595

96-
if (selectors.some(notString)) {
97-
throw new TypeError('suite.ignoreElements accepts only strings or array of strings');
96+
if (selectors.some(isNotValidSelector)) {
97+
throw new TypeError('suite.ignoreElements accepts strings, object with property "every" as string or array of them');
9898
}
9999
suite.ignoreSelectors = selectors;
100100
return this;
@@ -133,6 +133,11 @@ function notString(arg) {
133133
return typeof arg !== 'string';
134134
}
135135

136+
// Check if selector is not a string or not an object with "every" option.
137+
function isNotValidSelector(arg) {
138+
return !(_.isString(arg) || (_.isObject(arg) && _.isString(arg.every)));
139+
}
140+
136141
function argumentsToArray(args) {
137142
if (args.length === 1 && Array.isArray(args[0])) {
138143
return args[0];

0 commit comments

Comments
 (0)