Skip to content

Commit f384074

Browse files
chore: add visual reporting option (#13511)
1 parent bb9cd2a commit f384074

File tree

1 file changed

+135
-10
lines changed

1 file changed

+135
-10
lines changed

website/docs/visual-testing/service-options.md

Lines changed: 135 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ export const config = {
1414
// =====
1515
services: [
1616
[
17-
'visual',
17+
"visual",
1818
{
1919
// The options
20-
}
21-
]
22-
]
20+
},
21+
],
22+
],
2323
// ...
24-
}
24+
};
2525
```
2626

2727
## Default Options
@@ -110,9 +110,9 @@ The directory will hold all the baseline images that are used during the compari
110110
```js
111111
{
112112
baselineFolder: (options) => {
113-
const testFolder = path.dirname(options.specs[0])
114-
return path.join(testFolder, 'snapshots', type)
115-
}
113+
const testFolder = path.dirname(options.specs[0]);
114+
return path.join(testFolder, "snapshots", type);
115+
};
116116
}
117117
```
118118

@@ -129,6 +129,131 @@ Delete runtime folder (`actual` & `diff) on initialization
129129
This will only work when the [`screenshotPath`](#screenshotpath) is set through the plugin options, and **WILL NOT WORK** when you set the folders in the methods
130130
:::
131131

132+
### `createJsonReportFiles` **(NEW)**
133+
134+
- **Type:** `boolean`
135+
- **Mandatory:** No
136+
- **Default:** `false`
137+
138+
You now have the option to export the compare results into a JSON report file. By providing the option `createJsonReportFiles: true`, each image that is compared will create a report stored in the `actual` folder, next to each `actual` image result. The output will look like this:
139+
140+
```json
141+
{
142+
"parent": "check methods",
143+
"test": "should fail comparing with a baseline",
144+
"tag": "examplePageFail",
145+
"instanceData": {
146+
"browser": {
147+
"name": "chrome-headless-shell",
148+
"version": "126.0.6478.183"
149+
},
150+
"platform": {
151+
"name": "mac",
152+
"version": "not-known"
153+
}
154+
},
155+
"commandName": "checkScreen",
156+
"boundingBoxes": {
157+
"diffBoundingBoxes": [
158+
{
159+
"left": 1088,
160+
"top": 717,
161+
"right": 1186,
162+
"bottom": 730
163+
}
164+
//....
165+
],
166+
"ignoredBoxes": [
167+
{
168+
"left": 159,
169+
"top": 652,
170+
"right": 356,
171+
"bottom": 703
172+
}
173+
//...
174+
]
175+
},
176+
"fileData": {
177+
"actualFilePath": "/Users/wdio/visual-testing/.tmp/actual/desktop_chrome-headless-shellexamplePageFail-local-chrome-latest-1366x768.png",
178+
"baselineFilePath": "/Users/wdio/visual-testing/localBaseline/desktop_chrome-headless-shellexamplePageFail-local-chrome-latest-1366x768.png",
179+
"diffFilePath": "/Users/wdio/visual-testing/.tmp/diff/desktop_chrome-headless-shell/examplePageFail-local-chrome-latest-1366x768png",
180+
"fileName": "examplePageFail-local-chrome-latest-1366x768.png",
181+
"size": {
182+
"actual": {
183+
"height": 768,
184+
"width": 1366
185+
},
186+
"baseline": {
187+
"height": 768,
188+
"width": 1366
189+
},
190+
"diff": {
191+
"height": 768,
192+
"width": 1366
193+
}
194+
}
195+
},
196+
"misMatchPercentage": "12.90",
197+
"rawMisMatchPercentage": 12.900729014153246
198+
}
199+
```
200+
201+
When all tests are executed, a new JSON file with the collection of the comparisons will be generated and can be found in the root of your `actual` folder. The data is grouped by:
202+
203+
- `describe` for Jasmine/Mocha or `Feature` for CucumberJS
204+
- `it` for Jasmine/Mocha or `Scenario` for CucumberJS
205+
and then sorted by:
206+
- `commandName`, which are the compare method names used to compare the images
207+
- `instanceData`, browser first, then device, then platform
208+
it will look like this
209+
210+
```json
211+
[
212+
{
213+
"description": "check methods",
214+
"data": [
215+
{
216+
"test": "should fail comparing with a baseline",
217+
"data": [
218+
{
219+
"tag": "examplePageFail",
220+
"instanceData": {},
221+
"commandName": "checkScreen",
222+
"framework": "mocha",
223+
"boundingBoxes": {
224+
"diffBoundingBoxes": [],
225+
"ignoredBoxes": []
226+
},
227+
"fileData": {},
228+
"misMatchPercentage": "14.34",
229+
"rawMisMatchPercentage": 14.335403703025868
230+
},
231+
{
232+
"tag": "exampleElementFail",
233+
"instanceData": {},
234+
"commandName": "checkElement",
235+
"framework": "mocha",
236+
"boundingBoxes": {
237+
"diffBoundingBoxes": [],
238+
"ignoredBoxes": []
239+
},
240+
"fileData": {},
241+
"misMatchPercentage": "1.34",
242+
"rawMisMatchPercentage": 1.335403703025868
243+
}
244+
]
245+
}
246+
]
247+
}
248+
]
249+
```
250+
251+
The report data will give you the opportunity to build your own visual report without doing all the magic and data collection yourself.
252+
253+
:::info NOTE
254+
You need to use `@wdio/visual-testing` version `5.2.0` or higher
255+
:::
256+
132257
### `disableCSSAnimation`
133258

134259
- **Type:** `boolean`
@@ -146,12 +271,12 @@ and reset when done
146271
- **Default:** `false`
147272
- **Supported:** Web
148273

149-
This will hide all text on a page so only the layout will be used for comparison. Hiding will be done by adding the style `'color': 'transparent !important'` to __each__ element.
274+
This will hide all text on a page so only the layout will be used for comparison. Hiding will be done by adding the style `'color': 'transparent !important'` to **each** element.
150275

151276
For the output see [Test Output](./test-output#enablelayouttesting)
152277

153278
:::info
154-
By using this flag each element that contains text (so not only `p, h1, h2, h3, h4, h5, h6, span, a, li`, but also `div|button|..`) will get this property. There is __no__ option to tailor this.
279+
By using this flag each element that contains text (so not only `p, h1, h2, h3, h4, h5, h6, span, a, li`, but also `div|button|..`) will get this property. There is **no** option to tailor this.
155280
:::
156281

157282
### `formatImageName`

0 commit comments

Comments
 (0)