@cloudscape-design/browser-test-tools 3.0.123 → 3.0.125
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/browser-scripts/index.d.ts +1 -0
- package/browser-scripts/index.js +1 -0
- package/browser-scripts/permutations.d.ts +11 -0
- package/browser-scripts/permutations.js +27 -0
- package/internal/manifest.json +1 -1
- package/package.json +1 -1
- package/page-objects/index.d.ts +1 -1
- package/page-objects/screenshot.d.ts +6 -0
- package/page-objects/screenshot.js +35 -0
package/browser-scripts/index.js
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ElementOffset, ElementSize } from '../page-objects/types';
|
|
2
|
+
export interface PermutationInfo extends ElementSize {
|
|
3
|
+
id: string;
|
|
4
|
+
offset: ElementOffset;
|
|
5
|
+
}
|
|
6
|
+
export interface PageDimensions {
|
|
7
|
+
pageHeight: number;
|
|
8
|
+
viewportHeight: number;
|
|
9
|
+
}
|
|
10
|
+
export declare function getPermutationSizes(): PermutationInfo[];
|
|
11
|
+
export declare function getPageDimensions(): PageDimensions;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPermutationSizes = getPermutationSizes;
|
|
4
|
+
exports.getPageDimensions = getPageDimensions;
|
|
5
|
+
function getPermutationSizes() {
|
|
6
|
+
var pixelRatio = window.devicePixelRatio || 1;
|
|
7
|
+
return Array.prototype.slice
|
|
8
|
+
.call(document.querySelectorAll('[data-permutation]'))
|
|
9
|
+
.map(function (element) {
|
|
10
|
+
var rect = element.getBoundingClientRect();
|
|
11
|
+
return {
|
|
12
|
+
id: element.getAttribute('data-permutation') || '',
|
|
13
|
+
width: rect.width * pixelRatio,
|
|
14
|
+
height: rect.height * pixelRatio,
|
|
15
|
+
offset: {
|
|
16
|
+
top: rect.top * pixelRatio,
|
|
17
|
+
left: rect.left * pixelRatio,
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function getPageDimensions() {
|
|
23
|
+
return {
|
|
24
|
+
pageHeight: document.documentElement.scrollHeight,
|
|
25
|
+
viewportHeight: window.innerHeight,
|
|
26
|
+
};
|
|
27
|
+
}
|
package/internal/manifest.json
CHANGED
package/package.json
CHANGED
package/page-objects/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { default as BasePageObject } from './base';
|
|
2
|
-
export { default as ScreenshotPageObject } from './screenshot';
|
|
2
|
+
export { default as ScreenshotPageObject, PermutationScreenshot } from './screenshot';
|
|
3
3
|
export { default as EventsSpy } from './events-spy';
|
|
4
4
|
export { ScreenshotWithOffset, ElementSize, ElementRect, ElementOffset } from './types';
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import BasePageObject from './base';
|
|
2
2
|
import { ScreenshotCapturingOptions, ScreenshotWithOffset } from './types';
|
|
3
|
+
export interface PermutationScreenshot extends ScreenshotWithOffset {
|
|
4
|
+
id: string;
|
|
5
|
+
}
|
|
3
6
|
export default class ScreenshotPageObject extends BasePageObject {
|
|
4
7
|
readonly forceScrollAndMerge: boolean;
|
|
5
8
|
constructor(browser: WebdriverIO.Browser, forceScrollAndMerge?: boolean);
|
|
@@ -9,4 +12,7 @@ export default class ScreenshotPageObject extends BasePageObject {
|
|
|
9
12
|
fullPageScreenshot(): Promise<string>;
|
|
10
13
|
captureBySelector(selector: string, options?: ScreenshotCapturingOptions): Promise<ScreenshotWithOffset>;
|
|
11
14
|
captureViewport(): Promise<ScreenshotWithOffset>;
|
|
15
|
+
capturePermutations(): Promise<PermutationScreenshot[]>;
|
|
16
|
+
private fitWindowHeightToContent;
|
|
17
|
+
private safeSetWindowSize;
|
|
12
18
|
}
|
|
@@ -59,5 +59,40 @@ class ScreenshotPageObject extends base_1.default {
|
|
|
59
59
|
const image = await (0, image_utils_1.parsePng)(screenshot);
|
|
60
60
|
return { image, offset, height, width };
|
|
61
61
|
}
|
|
62
|
+
async capturePermutations() {
|
|
63
|
+
await this.windowScrollTo({ top: 0, left: 0 });
|
|
64
|
+
// Adapt viewport height to fit all elements before taking a screenshot
|
|
65
|
+
const originalWindowSize = await this.fitWindowHeightToContent();
|
|
66
|
+
const permutations = await this.browser.execute(browser_scripts_1.getPermutationSizes);
|
|
67
|
+
// Restore window size after taking the screenshot
|
|
68
|
+
await this.safeSetWindowSize(originalWindowSize.width, originalWindowSize.height);
|
|
69
|
+
if (permutations.length === 0) {
|
|
70
|
+
throw new Error('No permutations found on current page.');
|
|
71
|
+
}
|
|
72
|
+
const screenshot = await this.fullPageScreenshot();
|
|
73
|
+
const image = await (0, image_utils_1.parsePng)(screenshot);
|
|
74
|
+
return permutations.map((permutation) => ({ ...permutation, image }));
|
|
75
|
+
}
|
|
76
|
+
async fitWindowHeightToContent() {
|
|
77
|
+
const originalWindowSize = await this.browser.getWindowSize();
|
|
78
|
+
const { viewportHeight, pageHeight } = await this.browser.execute(browser_scripts_1.getPageDimensions);
|
|
79
|
+
const windowUIHeight = originalWindowSize.height - viewportHeight;
|
|
80
|
+
await this.safeSetWindowSize(originalWindowSize.width, pageHeight + windowUIHeight);
|
|
81
|
+
return originalWindowSize;
|
|
82
|
+
}
|
|
83
|
+
/* istanbul ignore next -- setWindowSize is unsupported on some mobile browsers, not testable in CI */
|
|
84
|
+
async safeSetWindowSize(width, height) {
|
|
85
|
+
try {
|
|
86
|
+
await this.browser.setWindowSize(width, height);
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
if (error instanceof Error && error.message.includes('Method has not yet been implemented')) {
|
|
90
|
+
console.log('setWindowSize is not supported on this device');
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
62
97
|
}
|
|
63
98
|
exports.default = ScreenshotPageObject;
|