@percy/playwright 1.0.7 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -0
- package/index.js +53 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -131,6 +131,65 @@ const desired_cap = {
|
|
|
131
131
|
- `bottom` (int): Bottom coordinate of the consider region.
|
|
132
132
|
- `left` (int): Left coordinate of the consider region.
|
|
133
133
|
- `right` (int): Right coordinate of the consider region.
|
|
134
|
+
- `regions` parameter that allows users to apply snapshot options to specific areas of the page. This parameter is an array where each object defines a custom region with configurations.
|
|
135
|
+
- Parameters:
|
|
136
|
+
- `elementSelector` (optional, only one of the following must be provided, if this is not provided then full page will be considered as region)
|
|
137
|
+
- `boundingBox` (object): Defines the coordinates and size of the region.
|
|
138
|
+
- `x` (number): X-coordinate of the region.
|
|
139
|
+
- `y` (number): Y-coordinate of the region.
|
|
140
|
+
- `width` (number): Width of the region.
|
|
141
|
+
- `height` (number): Height of the region.
|
|
142
|
+
- `elementXpath` (string): The XPath selector for the element.
|
|
143
|
+
- `elementCSS` (string): The CSS selector for the element.
|
|
144
|
+
|
|
145
|
+
- `algorithm` (mandatory)
|
|
146
|
+
- Specifies the snapshot comparison algorithm.
|
|
147
|
+
- Allowed values: `standard`, `layout`, `ignore`, `intelliignore`.
|
|
148
|
+
|
|
149
|
+
- `configuration` (required for `standard` and `intelliignore` algorithms, ignored otherwise)
|
|
150
|
+
- `diffSensitivity` (number): Sensitivity level for detecting differences.
|
|
151
|
+
- `imageIgnoreThreshold` (number): Threshold for ignoring minor image differences.
|
|
152
|
+
- `carouselsEnabled` (boolean): Whether to enable carousel detection.
|
|
153
|
+
- `bannersEnabled` (boolean): Whether to enable banner detection.
|
|
154
|
+
- `adsEnabled` (boolean): Whether to enable ad detection.
|
|
155
|
+
|
|
156
|
+
- `assertion` (optional)
|
|
157
|
+
- Defines assertions to apply to the region.
|
|
158
|
+
- `diffIgnoreThreshold` (number): The threshold for ignoring minor differences.
|
|
159
|
+
|
|
160
|
+
### Example Usage for regions
|
|
161
|
+
|
|
162
|
+
```
|
|
163
|
+
const obj1 = {
|
|
164
|
+
elementSelector: {
|
|
165
|
+
elementCSS: ".ad-banner"
|
|
166
|
+
},
|
|
167
|
+
algorithm: "intelliignore",
|
|
168
|
+
configuration: {
|
|
169
|
+
diffSensitivity: 2,
|
|
170
|
+
imageIgnoreThreshold: 0.2,
|
|
171
|
+
carouselsEnabled: true,
|
|
172
|
+
bannersEnabled: true,
|
|
173
|
+
adsEnabled: true
|
|
174
|
+
},
|
|
175
|
+
assertion: {
|
|
176
|
+
diffIgnoreThreshold: 0.4,
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
// we can use the createRegion function
|
|
181
|
+
|
|
182
|
+
const { createRegion } = percySnapshot;
|
|
183
|
+
|
|
184
|
+
const obj2 = createRegion({
|
|
185
|
+
algorithm: "intelliignore",
|
|
186
|
+
diffSensitivity: 3,
|
|
187
|
+
adsEnabled: true,
|
|
188
|
+
diffIgnoreThreshold: 0.4
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
percySnapshot(page, "Homepage 1", { regions: [obj1] });
|
|
192
|
+
```
|
|
134
193
|
|
|
135
194
|
### Creating Percy on automate build
|
|
136
195
|
Note: Automate Percy Token starts with `auto` keyword. The command can be triggered using `exec` keyword.
|
package/index.js
CHANGED
|
@@ -41,6 +41,58 @@ const percySnapshot = async function(page, name, options) {
|
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
43
|
|
|
44
|
+
const createRegion = function({
|
|
45
|
+
boundingBox = null,
|
|
46
|
+
elementXpath = null,
|
|
47
|
+
elementCSS = null,
|
|
48
|
+
padding = null,
|
|
49
|
+
algorithm = 'ignore',
|
|
50
|
+
diffSensitivity = null,
|
|
51
|
+
imageIgnoreThreshold = null,
|
|
52
|
+
carouselsEnabled = null,
|
|
53
|
+
bannersEnabled = null,
|
|
54
|
+
adsEnabled = null,
|
|
55
|
+
diffIgnoreThreshold = null
|
|
56
|
+
} = {}) {
|
|
57
|
+
const elementSelector = {};
|
|
58
|
+
if (boundingBox) elementSelector.boundingBox = boundingBox;
|
|
59
|
+
if (elementXpath) elementSelector.elementXpath = elementXpath;
|
|
60
|
+
if (elementCSS) elementSelector.elementCSS = elementCSS;
|
|
61
|
+
|
|
62
|
+
const region = {
|
|
63
|
+
algorithm,
|
|
64
|
+
elementSelector
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
if (padding) {
|
|
68
|
+
region.padding = padding;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const configuration = {};
|
|
72
|
+
if (['standard', 'intelliignore'].includes(algorithm)) {
|
|
73
|
+
if (diffSensitivity) configuration.diffSensitivity = diffSensitivity;
|
|
74
|
+
if (imageIgnoreThreshold) configuration.imageIgnoreThreshold = imageIgnoreThreshold;
|
|
75
|
+
if (carouselsEnabled) configuration.carouselsEnabled = carouselsEnabled;
|
|
76
|
+
if (bannersEnabled) configuration.bannersEnabled = bannersEnabled;
|
|
77
|
+
if (adsEnabled) configuration.adsEnabled = adsEnabled;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (Object.keys(configuration).length > 0) {
|
|
81
|
+
region.configuration = configuration;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const assertion = {};
|
|
85
|
+
if (diffIgnoreThreshold) {
|
|
86
|
+
assertion.diffIgnoreThreshold = diffIgnoreThreshold;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (Object.keys(assertion).length > 0) {
|
|
90
|
+
region.assertion = assertion;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return region;
|
|
94
|
+
};
|
|
95
|
+
|
|
44
96
|
// Takes Playwright screenshot with Automate
|
|
45
97
|
const percyScreenshot = async function(page, name, options) {
|
|
46
98
|
if (!page) throw new Error('A Playwright `page` object is required.');
|
|
@@ -75,6 +127,7 @@ const percyScreenshot = async function(page, name, options) {
|
|
|
75
127
|
|
|
76
128
|
module.exports = percySnapshot;
|
|
77
129
|
module.exports.percySnapshot = percySnapshot;
|
|
130
|
+
module.exports.createRegion = createRegion;
|
|
78
131
|
module.exports.percyScreenshot = percyScreenshot;
|
|
79
132
|
module.exports.CLIENT_INFO = CLIENT_INFO;
|
|
80
133
|
module.exports.ENV_INFO = ENV_INFO;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@percy/playwright",
|
|
3
3
|
"description": "Playwright client library for visual testing with Percy",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.8",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Perceptual Inc.",
|
|
7
7
|
"repository": "https://github.com/percy/percy-playwright",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"playwright-core": ">=1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@percy/cli": "^1.30.
|
|
38
|
+
"@percy/cli": "^1.30.9",
|
|
39
39
|
"@playwright/test": "^1.24.2",
|
|
40
40
|
"babel-eslint": "^10.1.0",
|
|
41
41
|
"cross-env": "^7.0.2",
|