@argos-ci/webdriverio 0.1.0
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/LICENSE +7 -0
- package/dist/index.cjs +8 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.mjs +92 -0
- package/package.json +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2022 Smooth Code
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/dist/index.cjs
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
type ArgosScreenshotOptions = {
|
|
2
|
+
/**
|
|
3
|
+
* Specify ares that should be masked when the screenshot is taken.
|
|
4
|
+
* Masked elements will be overlaid with a pink box #FF00FF (customized by maskColor)
|
|
5
|
+
* that completely covers its bounding box.
|
|
6
|
+
*/
|
|
7
|
+
mask?: {
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
}[];
|
|
13
|
+
/**
|
|
14
|
+
* Specify the color of the overlay box for masked elements, in CSS color format.
|
|
15
|
+
* Default color is pink #FF00FF.
|
|
16
|
+
* @default "#FF00FF"
|
|
17
|
+
*/
|
|
18
|
+
maskColor?: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Take a screenshot of the current page, optionally masking certain areas.
|
|
22
|
+
* @param browser A WebdriverIO `browser` object.
|
|
23
|
+
* @param filepath The path to save the screenshot to.
|
|
24
|
+
* @param options Options for the screenshot.
|
|
25
|
+
*/
|
|
26
|
+
declare function argosScreenshot(browser: WebdriverIO.Browser, name: string, { mask, maskColor }?: ArgosScreenshotOptions): Promise<Buffer>;
|
|
27
|
+
export { ArgosScreenshotOptions, argosScreenshot };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import sharp from 'sharp';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { mkdir } from 'node:fs/promises';
|
|
4
|
+
|
|
5
|
+
// Function to create a mask with Sharp
|
|
6
|
+
async function createMask(dimensions, areas, maskColor) {
|
|
7
|
+
// Start with a black image
|
|
8
|
+
let mask = sharp({
|
|
9
|
+
create: {
|
|
10
|
+
width: dimensions.width,
|
|
11
|
+
height: dimensions.height,
|
|
12
|
+
channels: 4,
|
|
13
|
+
background: {
|
|
14
|
+
r: 0,
|
|
15
|
+
g: 0,
|
|
16
|
+
b: 0,
|
|
17
|
+
alpha: 0
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
const areasImages = areas.map((coords)=>({
|
|
22
|
+
input: Buffer.from('<svg><rect x="0" y="0" width="' + coords.width + '" height="' + coords.height + `" fill="${maskColor}"/></svg>`),
|
|
23
|
+
top: coords.y,
|
|
24
|
+
left: coords.x
|
|
25
|
+
}));
|
|
26
|
+
mask = mask.composite(areasImages);
|
|
27
|
+
return mask.png().toBuffer();
|
|
28
|
+
}
|
|
29
|
+
async function applyMask(image, mask) {
|
|
30
|
+
try {
|
|
31
|
+
return await sharp(image).composite([
|
|
32
|
+
{
|
|
33
|
+
input: mask,
|
|
34
|
+
blend: "over"
|
|
35
|
+
}
|
|
36
|
+
]).png().toBuffer();
|
|
37
|
+
} catch (err) {
|
|
38
|
+
throw new Error("Error applying mask", {
|
|
39
|
+
cause: err
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async function getImageDimensions(buffer) {
|
|
44
|
+
try {
|
|
45
|
+
const imageInfo = await sharp(buffer).metadata();
|
|
46
|
+
const { width, height } = imageInfo;
|
|
47
|
+
if (!width || !height) {
|
|
48
|
+
throw new Error("Dimensions not found.");
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
width,
|
|
52
|
+
height
|
|
53
|
+
};
|
|
54
|
+
} catch (err) {
|
|
55
|
+
throw new Error("Error getting image dimensions", {
|
|
56
|
+
cause: err
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async function getFilePath(name) {
|
|
61
|
+
if (name.endsWith(".png")) return name;
|
|
62
|
+
const screenshotFolder = resolve(process.cwd(), "screenshots/argos");
|
|
63
|
+
await mkdir(screenshotFolder, {
|
|
64
|
+
recursive: true
|
|
65
|
+
});
|
|
66
|
+
return resolve(screenshotFolder, name + ".png");
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Take a screenshot of the current page, optionally masking certain areas.
|
|
70
|
+
* @param browser A WebdriverIO `browser` object.
|
|
71
|
+
* @param filepath The path to save the screenshot to.
|
|
72
|
+
* @param options Options for the screenshot.
|
|
73
|
+
*/ async function argosScreenshot(browser, name, { mask, maskColor = "#FF00FF" } = {}) {
|
|
74
|
+
if (!browser) {
|
|
75
|
+
throw new Error("A WebdriverIO `browser` object is required.");
|
|
76
|
+
}
|
|
77
|
+
if (!name) {
|
|
78
|
+
throw new Error("The `name` argument is required.");
|
|
79
|
+
}
|
|
80
|
+
const filepath = await getFilePath(name);
|
|
81
|
+
const imageBuffer = await browser.saveScreenshot(filepath);
|
|
82
|
+
if (!mask) {
|
|
83
|
+
return imageBuffer;
|
|
84
|
+
}
|
|
85
|
+
const dimensions = await getImageDimensions(imageBuffer);
|
|
86
|
+
const maskBuffer = await createMask(dimensions, mask, maskColor);
|
|
87
|
+
const maskedBuffer = await applyMask(imageBuffer, maskBuffer);
|
|
88
|
+
await sharp(maskedBuffer).toFile(filepath);
|
|
89
|
+
return maskedBuffer;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export { argosScreenshot };
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@argos-ci/webdriverio",
|
|
3
|
+
"description": "Visual testing solution to avoid visual regression. Webdriver SDK and utilities for Argos visual testing.",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"author": "Smooth Code",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/argos-ci/argos-javascript.git",
|
|
10
|
+
"directory": "packages/webdriverio"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"webdriverio",
|
|
14
|
+
"argos",
|
|
15
|
+
"automation",
|
|
16
|
+
"test automation",
|
|
17
|
+
"testing",
|
|
18
|
+
"visual testing",
|
|
19
|
+
"regression",
|
|
20
|
+
"visual regression"
|
|
21
|
+
],
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"type": "module",
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"import": "./dist/index.mjs",
|
|
31
|
+
"require": "./dist/index.cjs",
|
|
32
|
+
"default": "./dist/index.mjs"
|
|
33
|
+
},
|
|
34
|
+
"./package.json": "./package.json"
|
|
35
|
+
},
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=16.0.0"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"webdriverio": "^6 || ^7 || ^8"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"sharp": "^0.32.5"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@argos-ci/cli": "1.0.5",
|
|
47
|
+
"@types/mocha": "^10.0.6",
|
|
48
|
+
"@wdio/cli": "^8.27.1",
|
|
49
|
+
"@wdio/globals": "^8.27.0",
|
|
50
|
+
"@wdio/local-runner": "^8.27.0",
|
|
51
|
+
"@wdio/mocha-framework": "^8.27.0",
|
|
52
|
+
"@wdio/spec-reporter": "^8.27.0",
|
|
53
|
+
"@wdio/types": "^8.27.0",
|
|
54
|
+
"chromedriver": "^120.0.1",
|
|
55
|
+
"ts-node": "^10.9.2",
|
|
56
|
+
"wdio-chromedriver-service": "^8.1.1",
|
|
57
|
+
"webdriverio": "^8.27.0"
|
|
58
|
+
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"prebuild": "rm -rf dist",
|
|
61
|
+
"build": "rollup -c",
|
|
62
|
+
"test": "wdio run ./wdio.conf.ts",
|
|
63
|
+
"argos-upload": "pnpm exec argos upload screenshots --build-name \"argos-webdriverio-e2e-node-$NODE_VERSION-$OS\"",
|
|
64
|
+
"e2e": "pnpm run test && pnpm run argos-upload"
|
|
65
|
+
},
|
|
66
|
+
"gitHead": "fe6ced21faf2cfceacb073abfe21bce71b977c8a"
|
|
67
|
+
}
|