@cloudscape-design/browser-test-tools 3.0.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 +201 -0
- package/NOTICE +2 -0
- package/README.md +21 -0
- package/browser.d.ts +1 -0
- package/browser.js +1 -0
- package/chrome-launcher.d.ts +1 -0
- package/chrome-launcher.js +1 -0
- package/dist/browser-scripts/events-spy.d.ts +8 -0
- package/dist/browser-scripts/events-spy.js +27 -0
- package/dist/browser-scripts/index.d.ts +3 -0
- package/dist/browser-scripts/index.js +21 -0
- package/dist/browser-scripts/scroll.d.ts +10 -0
- package/dist/browser-scripts/scroll.js +45 -0
- package/dist/browser-scripts/sizes.d.ts +3 -0
- package/dist/browser-scripts/sizes.js +33 -0
- package/dist/browser.d.ts +2 -0
- package/dist/browser.js +40 -0
- package/dist/browsers/browser-creator.d.ts +21 -0
- package/dist/browsers/browser-creator.js +66 -0
- package/dist/browsers/browserstack.d.ts +21 -0
- package/dist/browsers/browserstack.js +138 -0
- package/dist/browsers/capabilities.d.ts +4 -0
- package/dist/browsers/capabilities.js +84 -0
- package/dist/browsers/devicefarm-mobile.d.ts +8 -0
- package/dist/browsers/devicefarm-mobile.js +33 -0
- package/dist/browsers/devicefarm.d.ts +15 -0
- package/dist/browsers/devicefarm.js +78 -0
- package/dist/browsers/index.d.ts +4 -0
- package/dist/browsers/index.js +16 -0
- package/dist/browsers/local.d.ts +8 -0
- package/dist/browsers/local.js +76 -0
- package/dist/chrome-launcher.d.ts +2 -0
- package/dist/chrome-launcher.js +52 -0
- package/dist/exceptions.d.ts +17 -0
- package/dist/exceptions.js +48 -0
- package/dist/image-utils/compare.d.ts +10 -0
- package/dist/image-utils/compare.js +68 -0
- package/dist/image-utils/crop.d.ts +5 -0
- package/dist/image-utils/crop.js +21 -0
- package/dist/image-utils/index.d.ts +3 -0
- package/dist/image-utils/index.js +11 -0
- package/dist/image-utils/merge.d.ts +1 -0
- package/dist/image-utils/merge.js +23 -0
- package/dist/image-utils/utils.d.ts +7 -0
- package/dist/image-utils/utils.js +59 -0
- package/dist/page-objects/base.d.ts +76 -0
- package/dist/page-objects/base.js +186 -0
- package/dist/page-objects/browser-scripts.d.ts +1 -0
- package/dist/page-objects/browser-scripts.js +11 -0
- package/dist/page-objects/events-spy.d.ts +10 -0
- package/dist/page-objects/events-spy.js +22 -0
- package/dist/page-objects/full-page-screenshot.d.ts +2 -0
- package/dist/page-objects/full-page-screenshot.js +66 -0
- package/dist/page-objects/index.d.ts +4 -0
- package/dist/page-objects/index.js +14 -0
- package/dist/page-objects/screenshot.d.ts +10 -0
- package/dist/page-objects/screenshot.js +57 -0
- package/dist/page-objects/types.d.ts +27 -0
- package/dist/page-objects/types.js +2 -0
- package/dist/page-objects/utils.d.ts +8 -0
- package/dist/page-objects/utils.js +72 -0
- package/dist/use-browser.d.ts +15 -0
- package/dist/use-browser.js +50 -0
- package/image-utils.d.ts +1 -0
- package/image-utils.js +1 -0
- package/package.json +63 -0
- package/page-objects.d.ts +1 -0
- package/page-objects.js +1 -0
- package/use-browser.d.ts +1 -0
- package/use-browser.js +1 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
7
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
8
|
+
const browser_scripts_1 = require("../browser-scripts");
|
|
9
|
+
const image_utils_1 = require("../image-utils");
|
|
10
|
+
const base_1 = __importDefault(require("./base"));
|
|
11
|
+
const full_page_screenshot_1 = __importDefault(require("./full-page-screenshot"));
|
|
12
|
+
class ScreenshotPageObject extends base_1.default {
|
|
13
|
+
async focusNextElement() {
|
|
14
|
+
return this.keys('Tab');
|
|
15
|
+
}
|
|
16
|
+
async scrollToBottom(selector) {
|
|
17
|
+
await this.browser.execute(browser_scripts_1.scrollToBottom, selector);
|
|
18
|
+
}
|
|
19
|
+
async scrollToRight(selector) {
|
|
20
|
+
await this.browser.execute(browser_scripts_1.scrollToRight, selector);
|
|
21
|
+
}
|
|
22
|
+
async fullPageScreenshot() {
|
|
23
|
+
// preserve scroll position in order to avoid side effects after screenshot taking
|
|
24
|
+
const scrollPosition = await this.getWindowScroll();
|
|
25
|
+
// Wait for the page to settle before taking a screenshot
|
|
26
|
+
await this.waitForJsTimers();
|
|
27
|
+
const screenshot = await (0, full_page_screenshot_1.default)(this.browser);
|
|
28
|
+
// restore scroll position
|
|
29
|
+
await this.windowScrollTo(scrollPosition);
|
|
30
|
+
return screenshot;
|
|
31
|
+
}
|
|
32
|
+
async captureBySelector(selector, options = {}) {
|
|
33
|
+
await this.waitForVisible(selector);
|
|
34
|
+
const { pixelRatio, top, left } = await this.getViewportSize();
|
|
35
|
+
const box = await this.getBoundingBox(selector);
|
|
36
|
+
const screenshot = options.viewportOnly ? await this.browser.takeScreenshot() : await this.fullPageScreenshot();
|
|
37
|
+
const image = await (0, image_utils_1.parsePng)(screenshot);
|
|
38
|
+
const offset = { top: box.top, left: box.left };
|
|
39
|
+
if (!options.viewportOnly) {
|
|
40
|
+
// Correct potential scrolling offsets when using a full page screenshot
|
|
41
|
+
offset.top += top;
|
|
42
|
+
offset.left += left;
|
|
43
|
+
}
|
|
44
|
+
return { image, offset, pixelRatio, height: box.height, width: box.width };
|
|
45
|
+
}
|
|
46
|
+
async captureViewport() {
|
|
47
|
+
const { height, width } = await this.getViewportSize();
|
|
48
|
+
const offset = {
|
|
49
|
+
top: 0,
|
|
50
|
+
left: 0,
|
|
51
|
+
};
|
|
52
|
+
const screenshot = await this.browser.takeScreenshot();
|
|
53
|
+
const image = await (0, image_utils_1.parsePng)(screenshot);
|
|
54
|
+
return { image, offset, height, width };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.default = ScreenshotPageObject;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { PNG } from 'pngjs';
|
|
2
|
+
export interface ElementSize {
|
|
3
|
+
width: number;
|
|
4
|
+
height: number;
|
|
5
|
+
}
|
|
6
|
+
export interface ElementOffset {
|
|
7
|
+
top: number;
|
|
8
|
+
left: number;
|
|
9
|
+
}
|
|
10
|
+
export interface ElementRect extends ElementOffset, ElementSize {
|
|
11
|
+
bottom: number;
|
|
12
|
+
right: number;
|
|
13
|
+
}
|
|
14
|
+
export interface ViewportSize extends ElementOffset, ElementSize {
|
|
15
|
+
pageHeight: number;
|
|
16
|
+
screenWidth: number;
|
|
17
|
+
screenHeight: number;
|
|
18
|
+
pixelRatio: number;
|
|
19
|
+
}
|
|
20
|
+
export interface ScreenshotCapturingOptions {
|
|
21
|
+
viewportOnly?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface ScreenshotWithOffset extends ElementSize {
|
|
24
|
+
image: PNG;
|
|
25
|
+
offset: ElementOffset;
|
|
26
|
+
pixelRatio?: number;
|
|
27
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="webdriverio/async" />
|
|
2
|
+
import { ViewportSize, ElementRect } from './types';
|
|
3
|
+
export declare function getElementCenter(rect: ElementRect): {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
};
|
|
7
|
+
export declare function calculateIosTopOffset(dimensions: Pick<ViewportSize, 'screenWidth' | 'screenHeight' | 'pixelRatio'>): number;
|
|
8
|
+
export declare function getPuppeteer(browser: WebdriverIO.Browser): Promise<import("puppeteer-core/lib/cjs/puppeteer/common/Browser").Browser | null>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPuppeteer = exports.calculateIosTopOffset = exports.getElementCenter = void 0;
|
|
4
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
5
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
const exceptions_1 = require("../exceptions");
|
|
7
|
+
function getElementCenter(rect) {
|
|
8
|
+
return {
|
|
9
|
+
x: Math.floor(rect.left + rect.width / 2),
|
|
10
|
+
y: Math.floor(rect.top + rect.height / 2),
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
exports.getElementCenter = getElementCenter;
|
|
14
|
+
// This is the pixel value *before* applying the device pixel ratio
|
|
15
|
+
const iosAddressBarHeight = 50;
|
|
16
|
+
// Device specific sizes for iOS devices. Models before iPhone X are covered by the default value.
|
|
17
|
+
// Viewport values taken from https://yesviz.com/iphones.php
|
|
18
|
+
const iosDeviceConfig = [
|
|
19
|
+
{
|
|
20
|
+
name: 'iPhone 12 (Pro)',
|
|
21
|
+
width: 390,
|
|
22
|
+
height: 844,
|
|
23
|
+
statusBarHeight: 141,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: 'iPhone 12 Pro Max',
|
|
27
|
+
width: 428,
|
|
28
|
+
height: 926,
|
|
29
|
+
statusBarHeight: 141,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: 'iPhone 11 Pro',
|
|
33
|
+
width: 375,
|
|
34
|
+
height: 812,
|
|
35
|
+
statusBarHeight: 132,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: 'iPhone 11 Pro Max',
|
|
39
|
+
width: 414,
|
|
40
|
+
height: 896,
|
|
41
|
+
statusBarHeight: 132,
|
|
42
|
+
},
|
|
43
|
+
];
|
|
44
|
+
// Screenshots on iOS include all iOS UI elements like toolbars and navigation, so we need to
|
|
45
|
+
// cut them out of screenshots. This function provides relevant offsets.
|
|
46
|
+
function calculateIosTopOffset(dimensions) {
|
|
47
|
+
const { screenWidth: width, screenHeight: height } = dimensions;
|
|
48
|
+
// Default height for most models before the iPhone X
|
|
49
|
+
let statusBarHeight = 20 * dimensions.pixelRatio;
|
|
50
|
+
const deviceConfig = iosDeviceConfig.find(config => (width === config.width && height === config.height) || (width === config.height && height === config.width));
|
|
51
|
+
if (deviceConfig) {
|
|
52
|
+
statusBarHeight = deviceConfig.statusBarHeight;
|
|
53
|
+
}
|
|
54
|
+
const addressBarHeight = iosAddressBarHeight * dimensions.pixelRatio;
|
|
55
|
+
return statusBarHeight + addressBarHeight;
|
|
56
|
+
}
|
|
57
|
+
exports.calculateIosTopOffset = calculateIosTopOffset;
|
|
58
|
+
async function getPuppeteer(browser) {
|
|
59
|
+
try {
|
|
60
|
+
const puppeteer = await browser.getPuppeteer();
|
|
61
|
+
return puppeteer;
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
if (error instanceof Error &&
|
|
65
|
+
(error.message.includes(exceptions_1.WebdriverIoUnsupportedPuppeteerErrorText) ||
|
|
66
|
+
error.message.includes(exceptions_1.WebdriverIoRemotePuppeteerErrorText))) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.getPuppeteer = getPuppeteer;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="webdriverio/async" />
|
|
2
|
+
import { WebDriverOptions } from './browsers/browser-creator';
|
|
3
|
+
declare type BrowserOptions = {
|
|
4
|
+
browserName: string;
|
|
5
|
+
seleniumType: string;
|
|
6
|
+
browserCreatorOptions: Record<string, any>;
|
|
7
|
+
webdriverOptions: Partial<WebDriverOptions>;
|
|
8
|
+
};
|
|
9
|
+
interface TestFunction {
|
|
10
|
+
(browser: WebdriverIO.Browser): Promise<void> | void;
|
|
11
|
+
}
|
|
12
|
+
declare function useBrowser(optionsOverride: Partial<WebDriverOptions>, testFn: TestFunction): () => Promise<void>;
|
|
13
|
+
declare function useBrowser(testFn: TestFunction): () => Promise<void>;
|
|
14
|
+
export default useBrowser;
|
|
15
|
+
export declare function configure(newOptions: Partial<BrowserOptions>): void;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.configure = void 0;
|
|
7
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
8
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
+
const assert_1 = require("assert");
|
|
10
|
+
const browser_1 = __importDefault(require("./browser"));
|
|
11
|
+
const merge_1 = __importDefault(require("lodash/merge"));
|
|
12
|
+
const options = {
|
|
13
|
+
browserName: 'ChromeHeadless',
|
|
14
|
+
seleniumType: 'local',
|
|
15
|
+
browserCreatorOptions: {},
|
|
16
|
+
webdriverOptions: {},
|
|
17
|
+
};
|
|
18
|
+
function useBrowser(...args) {
|
|
19
|
+
// How to do type-safe function overloads: https://stackoverflow.com/questions/55852612/typescript-overloads-optional-arguments-and-type-inference
|
|
20
|
+
const optionsOverride = args.length === 1 ? {} : args[0];
|
|
21
|
+
const testFn = args.length === 1 ? args[0] : args[1];
|
|
22
|
+
return async () => {
|
|
23
|
+
const creator = (0, browser_1.default)(options.browserName, options.seleniumType, options.browserCreatorOptions);
|
|
24
|
+
const browser = await creator.getBrowser({ ...options.webdriverOptions, ...optionsOverride });
|
|
25
|
+
try {
|
|
26
|
+
if ('getLogs' in browser) {
|
|
27
|
+
// dispose logs from previous sessions, if there are any
|
|
28
|
+
await browser.getLogs('browser');
|
|
29
|
+
}
|
|
30
|
+
await testFn(browser);
|
|
31
|
+
// This method does not exist in w3c protocol
|
|
32
|
+
if ('getLogs' in browser) {
|
|
33
|
+
const logs = (await browser.getLogs('browser'));
|
|
34
|
+
const errors = logs.filter(entry => entry.level === 'SEVERE');
|
|
35
|
+
assert_1.strict.deepEqual(errors, [], 'There should be no errors in the console');
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
console.warn('Unable to check browser console, webdriver does not support this feature');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
finally {
|
|
42
|
+
await browser.deleteSession();
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
exports.default = useBrowser;
|
|
47
|
+
function configure(newOptions) {
|
|
48
|
+
(0, merge_1.default)(options, newOptions);
|
|
49
|
+
}
|
|
50
|
+
exports.configure = configure;
|
package/image-utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/image-utils';export { default } from './dist/image-utils';
|
package/image-utils.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/image-utils');
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"bugs": {
|
|
3
|
+
"url": "https://github.com/cloudscape-design/browser-test-tools/issues"
|
|
4
|
+
},
|
|
5
|
+
"bundleDependencies": false,
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"@types/pngjs": "^6.0.1",
|
|
8
|
+
"aws-sdk": "^2.1140.0",
|
|
9
|
+
"get-stream": "^6.0.1",
|
|
10
|
+
"lodash": "^4.17.21",
|
|
11
|
+
"p-retry": "^4.6.2",
|
|
12
|
+
"pixelmatch": "^5.3.0",
|
|
13
|
+
"pngjs": "^6.0.0",
|
|
14
|
+
"webdriverio": "^7.19.7"
|
|
15
|
+
},
|
|
16
|
+
"deprecated": false,
|
|
17
|
+
"description": "This package contains the source code for tools used for building and testing the React components for the [Cloudscape Design System](https://cloudscape.design/).",
|
|
18
|
+
"exports": {
|
|
19
|
+
"./chrome-launcher": "./chrome-launcher.js",
|
|
20
|
+
"./image-utils": "./image-utils.js",
|
|
21
|
+
"./page-objects": "./page-objects.js",
|
|
22
|
+
"./use-browser": "./use-browser.js",
|
|
23
|
+
"./browser": "./browser.js"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"*.js",
|
|
28
|
+
"*.d.ts"
|
|
29
|
+
],
|
|
30
|
+
"homepage": "https://cloudscape.design",
|
|
31
|
+
"jest": {
|
|
32
|
+
"preset": "ts-jest",
|
|
33
|
+
"testEnvironment": "node",
|
|
34
|
+
"collectCoverage": true,
|
|
35
|
+
"collectCoverageFrom": [
|
|
36
|
+
"src/**/*.ts",
|
|
37
|
+
"!src/browser-scripts/**",
|
|
38
|
+
"!src/page-objects/browser-scripts.ts"
|
|
39
|
+
],
|
|
40
|
+
"coverageReporters": [
|
|
41
|
+
"json-summary",
|
|
42
|
+
"lcov",
|
|
43
|
+
"cobertura"
|
|
44
|
+
],
|
|
45
|
+
"setupFilesAfterEnv": [
|
|
46
|
+
"<rootDir>/test/utils/setup.js"
|
|
47
|
+
],
|
|
48
|
+
"globalSetup": "<rootDir>/test/utils/start-chromedriver.js",
|
|
49
|
+
"globalTeardown": "<rootDir>/test/utils/stop-chromedriver.js"
|
|
50
|
+
},
|
|
51
|
+
"lint-staged": {
|
|
52
|
+
"*.{js,ts}": [
|
|
53
|
+
"eslint --fix"
|
|
54
|
+
]
|
|
55
|
+
},
|
|
56
|
+
"name": "@cloudscape-design/browser-test-tools",
|
|
57
|
+
"repository": {
|
|
58
|
+
"type": "git",
|
|
59
|
+
"url": "git+https://github.com/cloudscape-design/browser-test-tools.git"
|
|
60
|
+
},
|
|
61
|
+
"version": "3.0.0",
|
|
62
|
+
"license": "Apache-2.0"
|
|
63
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/page-objects';export { default } from './dist/page-objects';
|
package/page-objects.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/page-objects');
|
package/use-browser.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/use-browser';export { default } from './dist/use-browser';
|
package/use-browser.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/use-browser');
|