@wordpress/e2e-test-utils-playwright 1.36.1-next.738bb1424.0 → 1.37.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/build/admin/create-new-post.js +48 -28
- package/build/admin/create-new-post.js.map +7 -1
- package/build/admin/edit-post.js +37 -17
- package/build/admin/edit-post.js.map +7 -1
- package/build/admin/get-page-error.js +33 -23
- package/build/admin/get-page-error.js.map +7 -1
- package/build/admin/index.js +58 -36
- package/build/admin/index.js.map +7 -1
- package/build/admin/visit-admin-page.js +44 -29
- package/build/admin/visit-admin-page.js.map +7 -1
- package/build/admin/visit-site-editor.js +73 -64
- package/build/admin/visit-site-editor.js.map +7 -1
- package/build/config.js +43 -11
- package/build/config.js.map +7 -1
- package/build/editor/click-block-options-menu-item.js +31 -14
- package/build/editor/click-block-options-menu-item.js.map +7 -1
- package/build/editor/click-block-toolbar-button.js +35 -13
- package/build/editor/click-block-toolbar-button.js.map +7 -1
- package/build/editor/get-blocks.js +61 -43
- package/build/editor/get-blocks.js.map +7 -1
- package/build/editor/get-edited-post-content.js +33 -12
- package/build/editor/get-edited-post-content.js.map +7 -1
- package/build/editor/index.js +96 -74
- package/build/editor/index.js.map +7 -1
- package/build/editor/insert-block.js +52 -21
- package/build/editor/insert-block.js.map +7 -1
- package/build/editor/open-document-settings-sidebar.js +39 -24
- package/build/editor/open-document-settings-sidebar.js.map +7 -1
- package/build/editor/preview.js +39 -18
- package/build/editor/preview.js.map +7 -1
- package/build/editor/publish-post.js +44 -42
- package/build/editor/publish-post.js.map +7 -1
- package/build/editor/save-draft.js +31 -15
- package/build/editor/save-draft.js.map +7 -1
- package/build/editor/select-blocks.js +48 -25
- package/build/editor/select-blocks.js.map +7 -1
- package/build/editor/set-content.js +36 -14
- package/build/editor/set-content.js.map +7 -1
- package/build/editor/set-is-fixed-toolbar.js +33 -15
- package/build/editor/set-is-fixed-toolbar.js.map +7 -1
- package/build/editor/set-preferences.js +40 -18
- package/build/editor/set-preferences.js.map +7 -1
- package/build/editor/show-block-toolbar.js +32 -16
- package/build/editor/show-block-toolbar.js.map +7 -1
- package/build/editor/site-editor.js +48 -41
- package/build/editor/site-editor.js.map +7 -1
- package/build/editor/switch-editor-tool.js +44 -30
- package/build/editor/switch-editor-tool.js.map +7 -1
- package/build/editor/switch-to-legacy-canvas.js +35 -14
- package/build/editor/switch-to-legacy-canvas.js.map +7 -1
- package/build/editor/transform-block-to.js +43 -21
- package/build/editor/transform-block-to.js.map +7 -1
- package/build/index.js +53 -18
- package/build/index.js.map +7 -1
- package/build/lighthouse/index.js +93 -55
- package/build/lighthouse/index.js.map +7 -1
- package/build/metrics/index.js +302 -251
- package/build/metrics/index.js.map +7 -1
- package/build/page-utils/drag-files.js +136 -112
- package/build/page-utils/drag-files.js.map +7 -1
- package/build/page-utils/emulate-network-conditions.js +95 -67
- package/build/page-utils/emulate-network-conditions.js.map +7 -1
- package/build/page-utils/index.js +58 -36
- package/build/page-utils/index.js.map +7 -1
- package/build/page-utils/is-current-url.js +33 -18
- package/build/page-utils/is-current-url.js.map +7 -1
- package/build/page-utils/keycodes.js +53 -39
- package/build/page-utils/keycodes.js.map +7 -1
- package/build/page-utils/press-keys.js +153 -130
- package/build/page-utils/press-keys.js.map +7 -1
- package/build/page-utils/set-browser-viewport.js +35 -42
- package/build/page-utils/set-browser-viewport.js.map +7 -1
- package/build/request-utils/blocks.js +51 -40
- package/build/request-utils/blocks.js.map +7 -1
- package/build/request-utils/comments.js +59 -45
- package/build/request-utils/comments.js.map +7 -1
- package/build/request-utils/gutenberg-experiments.js +63 -38
- package/build/request-utils/gutenberg-experiments.js.map +7 -1
- package/build/request-utils/index.js +191 -155
- package/build/request-utils/index.js.map +7 -1
- package/build/request-utils/login.js +45 -18
- package/build/request-utils/login.js.map +7 -1
- package/build/request-utils/media.js +74 -64
- package/build/request-utils/media.js.map +7 -1
- package/build/request-utils/menus.js +121 -109
- package/build/request-utils/menus.js.map +7 -1
- package/build/request-utils/pages.js +63 -50
- package/build/request-utils/pages.js.map +7 -1
- package/build/request-utils/patterns.js +41 -24
- package/build/request-utils/patterns.js.map +7 -1
- package/build/request-utils/plugins.js +70 -74
- package/build/request-utils/plugins.js.map +7 -1
- package/build/request-utils/posts.js +55 -41
- package/build/request-utils/posts.js.map +7 -1
- package/build/request-utils/preferences.js +38 -17
- package/build/request-utils/preferences.js.map +7 -1
- package/build/request-utils/rest.js +155 -129
- package/build/request-utils/rest.js.map +7 -1
- package/build/request-utils/site-settings.js +40 -28
- package/build/request-utils/site-settings.js.map +7 -1
- package/build/request-utils/templates.js +60 -46
- package/build/request-utils/templates.js.map +7 -1
- package/build/request-utils/themes.js +80 -53
- package/build/request-utils/themes.js.map +7 -1
- package/build/request-utils/users.js +74 -72
- package/build/request-utils/users.js.map +7 -1
- package/build/request-utils/widgets.js +73 -55
- package/build/request-utils/widgets.js.map +7 -1
- package/build/test.js +130 -146
- package/build/test.js.map +7 -1
- package/build/types.js +18 -2
- package/build/types.js.map +7 -1
- package/build-types/index.d.ts +1 -1
- package/build-types/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/build/admin/create-new-post.cjs +0 -51
- package/build/admin/create-new-post.cjs.map +0 -7
- package/build/admin/edit-post.cjs +0 -40
- package/build/admin/edit-post.cjs.map +0 -7
- package/build/admin/get-page-error.cjs +0 -36
- package/build/admin/get-page-error.cjs.map +0 -7
- package/build/admin/index.cjs +0 -59
- package/build/admin/index.cjs.map +0 -7
- package/build/admin/visit-admin-page.cjs +0 -47
- package/build/admin/visit-admin-page.cjs.map +0 -7
- package/build/admin/visit-site-editor.cjs +0 -77
- package/build/admin/visit-site-editor.cjs.map +0 -7
- package/build/config.cjs +0 -45
- package/build/config.cjs.map +0 -7
- package/build/editor/click-block-options-menu-item.cjs +0 -34
- package/build/editor/click-block-options-menu-item.cjs.map +0 -7
- package/build/editor/click-block-toolbar-button.cjs +0 -38
- package/build/editor/click-block-toolbar-button.cjs.map +0 -7
- package/build/editor/get-blocks.cjs +0 -64
- package/build/editor/get-blocks.cjs.map +0 -7
- package/build/editor/get-edited-post-content.cjs +0 -36
- package/build/editor/get-edited-post-content.cjs.map +0 -7
- package/build/editor/index.cjs +0 -97
- package/build/editor/index.cjs.map +0 -7
- package/build/editor/insert-block.cjs +0 -55
- package/build/editor/insert-block.cjs.map +0 -7
- package/build/editor/open-document-settings-sidebar.cjs +0 -42
- package/build/editor/open-document-settings-sidebar.cjs.map +0 -7
- package/build/editor/preview.cjs +0 -42
- package/build/editor/preview.cjs.map +0 -7
- package/build/editor/publish-post.cjs +0 -47
- package/build/editor/publish-post.cjs.map +0 -7
- package/build/editor/save-draft.cjs +0 -34
- package/build/editor/save-draft.cjs.map +0 -7
- package/build/editor/select-blocks.cjs +0 -51
- package/build/editor/select-blocks.cjs.map +0 -7
- package/build/editor/set-content.cjs +0 -39
- package/build/editor/set-content.cjs.map +0 -7
- package/build/editor/set-is-fixed-toolbar.cjs +0 -36
- package/build/editor/set-is-fixed-toolbar.cjs.map +0 -7
- package/build/editor/set-preferences.cjs +0 -43
- package/build/editor/set-preferences.cjs.map +0 -7
- package/build/editor/show-block-toolbar.cjs +0 -35
- package/build/editor/show-block-toolbar.cjs.map +0 -7
- package/build/editor/site-editor.cjs +0 -51
- package/build/editor/site-editor.cjs.map +0 -7
- package/build/editor/switch-editor-tool.cjs +0 -47
- package/build/editor/switch-editor-tool.cjs.map +0 -7
- package/build/editor/switch-to-legacy-canvas.cjs +0 -39
- package/build/editor/switch-to-legacy-canvas.cjs.map +0 -7
- package/build/editor/transform-block-to.cjs +0 -46
- package/build/editor/transform-block-to.cjs.map +0 -7
- package/build/index.cjs +0 -51
- package/build/index.cjs.map +0 -7
- package/build/lighthouse/index.cjs +0 -96
- package/build/lighthouse/index.cjs.map +0 -7
- package/build/metrics/index.cjs +0 -309
- package/build/metrics/index.cjs.map +0 -7
- package/build/page-utils/drag-files.cjs +0 -143
- package/build/page-utils/drag-files.cjs.map +0 -7
- package/build/page-utils/emulate-network-conditions.cjs +0 -99
- package/build/page-utils/emulate-network-conditions.cjs.map +0 -7
- package/build/page-utils/index.cjs +0 -59
- package/build/page-utils/index.cjs.map +0 -7
- package/build/page-utils/is-current-url.cjs +0 -36
- package/build/page-utils/is-current-url.cjs.map +0 -7
- package/build/page-utils/keycodes.cjs +0 -55
- package/build/page-utils/keycodes.cjs.map +0 -7
- package/build/page-utils/press-keys.cjs +0 -165
- package/build/page-utils/press-keys.cjs.map +0 -7
- package/build/page-utils/set-browser-viewport.cjs +0 -39
- package/build/page-utils/set-browser-viewport.cjs.map +0 -7
- package/build/request-utils/blocks.cjs +0 -56
- package/build/request-utils/blocks.cjs.map +0 -7
- package/build/request-utils/comments.cjs +0 -66
- package/build/request-utils/comments.cjs.map +0 -7
- package/build/request-utils/gutenberg-experiments.cjs +0 -66
- package/build/request-utils/gutenberg-experiments.cjs.map +0 -7
- package/build/request-utils/index.cjs +0 -194
- package/build/request-utils/index.cjs.map +0 -7
- package/build/request-utils/login.cjs +0 -48
- package/build/request-utils/login.cjs.map +0 -7
- package/build/request-utils/media.cjs +0 -83
- package/build/request-utils/media.cjs.map +0 -7
- package/build/request-utils/menus.cjs +0 -132
- package/build/request-utils/menus.cjs.map +0 -7
- package/build/request-utils/pages.cjs +0 -71
- package/build/request-utils/pages.cjs.map +0 -7
- package/build/request-utils/patterns.cjs +0 -44
- package/build/request-utils/patterns.cjs.map +0 -7
- package/build/request-utils/plugins.cjs +0 -81
- package/build/request-utils/plugins.cjs.map +0 -7
- package/build/request-utils/posts.cjs +0 -61
- package/build/request-utils/posts.cjs.map +0 -7
- package/build/request-utils/preferences.cjs +0 -41
- package/build/request-utils/preferences.cjs.map +0 -7
- package/build/request-utils/rest.cjs +0 -174
- package/build/request-utils/rest.cjs.map +0 -7
- package/build/request-utils/site-settings.cjs +0 -45
- package/build/request-utils/site-settings.cjs.map +0 -7
- package/build/request-utils/templates.cjs +0 -68
- package/build/request-utils/templates.cjs.map +0 -7
- package/build/request-utils/themes.cjs +0 -89
- package/build/request-utils/themes.cjs.map +0 -7
- package/build/request-utils/users.cjs +0 -83
- package/build/request-utils/users.cjs.map +0 -7
- package/build/request-utils/widgets.cjs +0 -79
- package/build/request-utils/widgets.cjs.map +0 -7
- package/build/test.cjs +0 -136
- package/build/test.cjs.map +0 -7
- package/build/types.cjs +0 -19
- package/build/types.cjs.map +0 -7
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// packages/e2e-test-utils-playwright/src/page-utils/drag-files.ts
|
|
21
|
-
var drag_files_exports = {};
|
|
22
|
-
__export(drag_files_exports, {
|
|
23
|
-
dragFiles: () => dragFiles
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(drag_files_exports);
|
|
26
|
-
var import_promises = require("fs/promises");
|
|
27
|
-
var import_path = require("path");
|
|
28
|
-
var import_mime = require("mime");
|
|
29
|
-
async function dragFiles(files) {
|
|
30
|
-
const filesList = Array.isArray(files) ? files : [files];
|
|
31
|
-
const fileObjects = await Promise.all(
|
|
32
|
-
filesList.map(async (filePathOrObject) => {
|
|
33
|
-
if (typeof filePathOrObject !== "string") {
|
|
34
|
-
return {
|
|
35
|
-
name: filePathOrObject.name,
|
|
36
|
-
mimeType: filePathOrObject.mimeType || (0, import_mime.getType)(filePathOrObject.name),
|
|
37
|
-
base64: filePathOrObject.buffer.toString("base64")
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
const base64 = await (0, import_promises.readFile)(filePathOrObject, "base64");
|
|
41
|
-
const name = (0, import_path.basename)(filePathOrObject);
|
|
42
|
-
return {
|
|
43
|
-
name,
|
|
44
|
-
mimeType: (0, import_mime.getType)(filePathOrObject),
|
|
45
|
-
base64
|
|
46
|
-
};
|
|
47
|
-
})
|
|
48
|
-
);
|
|
49
|
-
const dragData = {
|
|
50
|
-
items: fileObjects.map((fileObject) => ({
|
|
51
|
-
mimeType: fileObject.mimeType ?? "File",
|
|
52
|
-
data: fileObject.base64
|
|
53
|
-
})),
|
|
54
|
-
files: fileObjects.map((fileObject) => fileObject.name),
|
|
55
|
-
// Copy = 1, Link = 2, Move = 16.
|
|
56
|
-
dragOperationsMask: 1
|
|
57
|
-
};
|
|
58
|
-
const cdpSession = await this.context.newCDPSession(this.page);
|
|
59
|
-
const position = {
|
|
60
|
-
x: 0,
|
|
61
|
-
y: 0
|
|
62
|
-
};
|
|
63
|
-
return {
|
|
64
|
-
/**
|
|
65
|
-
* Drag the files over an element (fires `dragenter` and `dragover` events).
|
|
66
|
-
*
|
|
67
|
-
* @param selectorOrLocator A selector or a locator to search for an element.
|
|
68
|
-
* @param options The optional options.
|
|
69
|
-
* @param options.position A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the element.
|
|
70
|
-
*/
|
|
71
|
-
dragOver: async (selectorOrLocator, options = {}) => {
|
|
72
|
-
const locator = typeof selectorOrLocator === "string" ? this.page.locator(selectorOrLocator) : selectorOrLocator;
|
|
73
|
-
const boundingBox = await locator.boundingBox();
|
|
74
|
-
if (!boundingBox) {
|
|
75
|
-
throw new Error(
|
|
76
|
-
"Cannot find the element or the element is not visible on the viewport."
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
position.x = boundingBox.x + (options.position?.x ?? boundingBox.width / 2);
|
|
80
|
-
position.y = boundingBox.y + (options.position?.y ?? boundingBox.height / 2);
|
|
81
|
-
await cdpSession.send("Input.dispatchDragEvent", {
|
|
82
|
-
type: "dragEnter",
|
|
83
|
-
...position,
|
|
84
|
-
data: dragData
|
|
85
|
-
});
|
|
86
|
-
await cdpSession.send("Input.dispatchDragEvent", {
|
|
87
|
-
type: "dragOver",
|
|
88
|
-
...position,
|
|
89
|
-
data: dragData
|
|
90
|
-
});
|
|
91
|
-
},
|
|
92
|
-
/**
|
|
93
|
-
* Drop the files at the current position.
|
|
94
|
-
*/
|
|
95
|
-
drop: async () => {
|
|
96
|
-
const topMostElement = await this.page.evaluateHandle(
|
|
97
|
-
({ x, y }) => {
|
|
98
|
-
const element = document.elementFromPoint(x, y);
|
|
99
|
-
if (element instanceof HTMLIFrameElement) {
|
|
100
|
-
const offsetBox = element.getBoundingClientRect();
|
|
101
|
-
return element.contentDocument.elementFromPoint(
|
|
102
|
-
x - offsetBox.x,
|
|
103
|
-
y - offsetBox.y
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
return element;
|
|
107
|
-
},
|
|
108
|
-
position
|
|
109
|
-
);
|
|
110
|
-
const elementHandle = topMostElement.asElement();
|
|
111
|
-
if (!elementHandle) {
|
|
112
|
-
throw new Error("Element not found.");
|
|
113
|
-
}
|
|
114
|
-
const dataTransfer = await elementHandle.evaluateHandle(
|
|
115
|
-
async (_node, _fileObjects) => {
|
|
116
|
-
const dt = new DataTransfer();
|
|
117
|
-
const fileInstances = await Promise.all(
|
|
118
|
-
_fileObjects.map(async (fileObject) => {
|
|
119
|
-
const blob = await fetch(
|
|
120
|
-
`data:${fileObject.mimeType};base64,${fileObject.base64}`
|
|
121
|
-
).then((res) => res.blob());
|
|
122
|
-
return new File([blob], fileObject.name, {
|
|
123
|
-
type: fileObject.mimeType ?? void 0
|
|
124
|
-
});
|
|
125
|
-
})
|
|
126
|
-
);
|
|
127
|
-
fileInstances.forEach((file) => {
|
|
128
|
-
dt.items.add(file);
|
|
129
|
-
});
|
|
130
|
-
return dt;
|
|
131
|
-
},
|
|
132
|
-
fileObjects
|
|
133
|
-
);
|
|
134
|
-
await elementHandle.dispatchEvent("drop", { dataTransfer });
|
|
135
|
-
await cdpSession.detach();
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
140
|
-
0 && (module.exports = {
|
|
141
|
-
dragFiles
|
|
142
|
-
});
|
|
143
|
-
//# sourceMappingURL=drag-files.cjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/page-utils/drag-files.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport { readFile } from 'fs/promises';\nimport { basename } from 'path';\nimport { getType } from 'mime';\n\n/**\n * Internal dependencies\n */\nimport type { PageUtils } from './index';\nimport type { Locator } from '@playwright/test';\n\ntype FileObject = {\n\tname: string;\n\tmimeType?: string;\n\tbuffer: Buffer;\n};\n\ntype Options = {\n\tposition?: { x: number; y: number };\n};\n\n/**\n * Simulate dragging files from outside the current page.\n *\n * @param this\n * @param files The files to be dragged.\n * @return The methods of the drag operation.\n */\nasync function dragFiles(\n\tthis: PageUtils,\n\tfiles: string | string[] | FileObject | FileObject[]\n) {\n\tconst filesList = Array.isArray( files ) ? files : [ files ];\n\tconst fileObjects = await Promise.all(\n\t\tfilesList.map( async ( filePathOrObject ) => {\n\t\t\tif ( typeof filePathOrObject !== 'string' ) {\n\t\t\t\treturn {\n\t\t\t\t\tname: filePathOrObject.name,\n\t\t\t\t\tmimeType:\n\t\t\t\t\t\tfilePathOrObject.mimeType ||\n\t\t\t\t\t\tgetType( filePathOrObject.name ),\n\t\t\t\t\tbase64: filePathOrObject.buffer.toString( 'base64' ),\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst base64 = await readFile( filePathOrObject, 'base64' );\n\t\t\tconst name = basename( filePathOrObject );\n\t\t\treturn {\n\t\t\t\tname,\n\t\t\t\tmimeType: getType( filePathOrObject ),\n\t\t\t\tbase64,\n\t\t\t};\n\t\t} )\n\t);\n\n\t// CDP doesn't actually support dragging files, this is only a _good enough_\n\t// dummy data so that it will correctly send the relevant events.\n\tconst dragData = {\n\t\titems: fileObjects.map( ( fileObject ) => ( {\n\t\t\tmimeType: fileObject.mimeType ?? 'File',\n\t\t\tdata: fileObject.base64,\n\t\t} ) ),\n\t\tfiles: fileObjects.map( ( fileObject ) => fileObject.name ),\n\t\t// Copy = 1, Link = 2, Move = 16.\n\t\tdragOperationsMask: 1,\n\t};\n\n\tconst cdpSession = await this.context.newCDPSession( this.page );\n\n\tconst position = {\n\t\tx: 0,\n\t\ty: 0,\n\t};\n\n\treturn {\n\t\t/**\n\t\t * Drag the files over an element (fires `dragenter` and `dragover` events).\n\t\t *\n\t\t * @param selectorOrLocator A selector or a locator to search for an element.\n\t\t * @param options The optional options.\n\t\t * @param options.position A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the element.\n\t\t */\n\t\tdragOver: async (\n\t\t\tselectorOrLocator: string | Locator,\n\t\t\toptions: Options = {}\n\t\t) => {\n\t\t\tconst locator =\n\t\t\t\ttypeof selectorOrLocator === 'string'\n\t\t\t\t\t? this.page.locator( selectorOrLocator )\n\t\t\t\t\t: selectorOrLocator;\n\t\t\tconst boundingBox = await locator.boundingBox();\n\n\t\t\tif ( ! boundingBox ) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'Cannot find the element or the element is not visible on the viewport.'\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tposition.x =\n\t\t\t\tboundingBox.x +\n\t\t\t\t( options.position?.x ?? boundingBox.width / 2 );\n\t\t\tposition.y =\n\t\t\t\tboundingBox.y +\n\t\t\t\t( options.position?.y ?? boundingBox.height / 2 );\n\n\t\t\tawait cdpSession.send( 'Input.dispatchDragEvent', {\n\t\t\t\ttype: 'dragEnter',\n\t\t\t\t...position,\n\t\t\t\tdata: dragData,\n\t\t\t} );\n\t\t\tawait cdpSession.send( 'Input.dispatchDragEvent', {\n\t\t\t\ttype: 'dragOver',\n\t\t\t\t...position,\n\t\t\t\tdata: dragData,\n\t\t\t} );\n\t\t},\n\n\t\t/**\n\t\t * Drop the files at the current position.\n\t\t */\n\t\tdrop: async () => {\n\t\t\tconst topMostElement = await this.page.evaluateHandle(\n\t\t\t\t( { x, y } ) => {\n\t\t\t\t\tconst element = document.elementFromPoint( x, y );\n\t\t\t\t\tif ( element instanceof HTMLIFrameElement ) {\n\t\t\t\t\t\tconst offsetBox = element.getBoundingClientRect();\n\t\t\t\t\t\treturn element.contentDocument!.elementFromPoint(\n\t\t\t\t\t\t\tx - offsetBox.x,\n\t\t\t\t\t\t\ty - offsetBox.y\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn element;\n\t\t\t\t},\n\t\t\t\tposition\n\t\t\t);\n\t\t\tconst elementHandle = topMostElement.asElement();\n\n\t\t\tif ( ! elementHandle ) {\n\t\t\t\tthrow new Error( 'Element not found.' );\n\t\t\t}\n\n\t\t\tconst dataTransfer = await elementHandle.evaluateHandle(\n\t\t\t\tasync ( _node, _fileObjects ) => {\n\t\t\t\t\tconst dt = new DataTransfer();\n\t\t\t\t\tconst fileInstances = await Promise.all(\n\t\t\t\t\t\t_fileObjects.map( async ( fileObject: any ) => {\n\t\t\t\t\t\t\tconst blob = await fetch(\n\t\t\t\t\t\t\t\t`data:${ fileObject.mimeType };base64,${ fileObject.base64 }`\n\t\t\t\t\t\t\t).then( ( res ) => res.blob() );\n\t\t\t\t\t\t\treturn new File( [ blob ], fileObject.name, {\n\t\t\t\t\t\t\t\ttype: fileObject.mimeType ?? undefined,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t} )\n\t\t\t\t\t);\n\n\t\t\t\t\tfileInstances.forEach( ( file ) => {\n\t\t\t\t\t\tdt.items.add( file );\n\t\t\t\t\t} );\n\n\t\t\t\t\treturn dt;\n\t\t\t\t},\n\t\t\t\tfileObjects\n\t\t\t);\n\n\t\t\tawait elementHandle.dispatchEvent( 'drop', { dataTransfer } );\n\n\t\t\tawait cdpSession.detach();\n\t\t},\n\t};\n}\n\nexport { dragFiles };\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,sBAAyB;AACzB,kBAAyB;AACzB,kBAAwB;AAyBxB,eAAe,UAEd,OACC;AACD,QAAM,YAAY,MAAM,QAAS,KAAM,IAAI,QAAQ,CAAE,KAAM;AAC3D,QAAM,cAAc,MAAM,QAAQ;AAAA,IACjC,UAAU,IAAK,OAAQ,qBAAsB;AAC5C,UAAK,OAAO,qBAAqB,UAAW;AAC3C,eAAO;AAAA,UACN,MAAM,iBAAiB;AAAA,UACvB,UACC,iBAAiB,gBACjB,qBAAS,iBAAiB,IAAK;AAAA,UAChC,QAAQ,iBAAiB,OAAO,SAAU,QAAS;AAAA,QACpD;AAAA,MACD;AACA,YAAM,SAAS,UAAM,0BAAU,kBAAkB,QAAS;AAC1D,YAAM,WAAO,sBAAU,gBAAiB;AACxC,aAAO;AAAA,QACN;AAAA,QACA,cAAU,qBAAS,gBAAiB;AAAA,QACpC;AAAA,MACD;AAAA,IACD,CAAE;AAAA,EACH;AAIA,QAAM,WAAW;AAAA,IAChB,OAAO,YAAY,IAAK,CAAE,gBAAkB;AAAA,MAC3C,UAAU,WAAW,YAAY;AAAA,MACjC,MAAM,WAAW;AAAA,IAClB,EAAI;AAAA,IACJ,OAAO,YAAY,IAAK,CAAE,eAAgB,WAAW,IAAK;AAAA;AAAA,IAE1D,oBAAoB;AAAA,EACrB;AAEA,QAAM,aAAa,MAAM,KAAK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OAAQ,OAAO,iBAAkB;AAChC,gBAAM,KAAK,IAAI,aAAa;AAC5B,gBAAM,gBAAgB,MAAM,QAAQ;AAAA,YACnC,aAAa,IAAK,OAAQ,eAAqB;AAC9C,oBAAM,OAAO,MAAM;AAAA,gBAClB,QAAS,WAAW,QAAS,WAAY,WAAW,MAAO;AAAA,cAC5D,EAAE,KAAM,CAAE,QAAS,IAAI,KAAK,CAAE;AAC9B,qBAAO,IAAI,KAAM,CAAE,IAAK,GAAG,WAAW,MAAM;AAAA,gBAC3C,MAAM,WAAW,YAAY;AAAA,cAC9B,CAAE;AAAA,YACH,CAAE;AAAA,UACH;AAEA,wBAAc,QAAS,CAAE,SAAU;AAClC,eAAG,MAAM,IAAK,IAAK;AAAA,UACpB,CAAE;AAEF,iBAAO;AAAA,QACR;AAAA,QACA;AAAA,MACD;AAEA,YAAM,cAAc,cAAe,QAAQ,EAAE,aAAa,CAAE;AAE5D,YAAM,WAAW,OAAO;AAAA,IACzB;AAAA,EACD;AACD;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// packages/e2e-test-utils-playwright/src/page-utils/emulate-network-conditions.ts
|
|
21
|
-
var emulate_network_conditions_exports = {};
|
|
22
|
-
__export(emulate_network_conditions_exports, {
|
|
23
|
-
emulateNetworkConditions: () => emulateNetworkConditions
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(emulate_network_conditions_exports);
|
|
26
|
-
var PredefinedNetworkConditions = {
|
|
27
|
-
// Generally aligned with DevTools
|
|
28
|
-
// https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/front_end/core/sdk/NetworkManager.ts;l=398;drc=225e1240f522ca684473f541ae6dae6cd766dd33.
|
|
29
|
-
"Slow 3G": {
|
|
30
|
-
offline: false,
|
|
31
|
-
// ~500Kbps down
|
|
32
|
-
downloadThroughput: 500 * 1e3 / 8 * 0.8,
|
|
33
|
-
// ~500Kbps up
|
|
34
|
-
uploadThroughput: 500 * 1e3 / 8 * 0.8,
|
|
35
|
-
// 400ms RTT
|
|
36
|
-
latency: 400 * 5
|
|
37
|
-
},
|
|
38
|
-
"Fast 3G": {
|
|
39
|
-
offline: false,
|
|
40
|
-
// ~1.6 Mbps down
|
|
41
|
-
downloadThroughput: 1.6 * 1e3 * 1e3 / 8 * 0.9,
|
|
42
|
-
// ~0.75 Mbps up
|
|
43
|
-
uploadThroughput: 750 * 1e3 / 8 * 0.9,
|
|
44
|
-
// 150ms RTT
|
|
45
|
-
latency: 150 * 3.75
|
|
46
|
-
},
|
|
47
|
-
// alias to Fast 3G to align with Lighthouse (crbug.com/342406608)
|
|
48
|
-
// and DevTools (crbug.com/342406608),
|
|
49
|
-
"Slow 4G": {
|
|
50
|
-
offline: false,
|
|
51
|
-
// ~1.6 Mbps down
|
|
52
|
-
downloadThroughput: 1.6 * 1e3 * 1e3 / 8 * 0.9,
|
|
53
|
-
// ~0.75 Mbps up
|
|
54
|
-
uploadThroughput: 750 * 1e3 / 8 * 0.9,
|
|
55
|
-
// 150ms RTT
|
|
56
|
-
latency: 150 * 3.75
|
|
57
|
-
},
|
|
58
|
-
"Fast 4G": {
|
|
59
|
-
offline: false,
|
|
60
|
-
// 9 Mbps down
|
|
61
|
-
downloadThroughput: 9 * 1e3 * 1e3 / 8 * 0.9,
|
|
62
|
-
// 1.5 Mbps up
|
|
63
|
-
uploadThroughput: 1.5 * 1e3 * 1e3 / 8 * 0.9,
|
|
64
|
-
// 60ms RTT
|
|
65
|
-
latency: 60 * 2.75
|
|
66
|
-
},
|
|
67
|
-
/**
|
|
68
|
-
* Network conditions used for desktop in Lighthouse/PSI.
|
|
69
|
-
*
|
|
70
|
-
* 10,240 kb/s throughput with 40 ms TCP RTT.
|
|
71
|
-
*
|
|
72
|
-
* @see https://github.com/paulirish/lighthouse/blob/f0855904aaffaecf3089169449646960782d7e92/core/config/constants.js#L40-L49
|
|
73
|
-
* @see https://docs.google.com/document/d/1-p4HSp42REEA5-jCBVB6PqQcVhI1nQIblBCNKhPJUXg/edit?tab=t.0#heading=h.jsap7yf4phk6
|
|
74
|
-
*/
|
|
75
|
-
Broadband: {
|
|
76
|
-
offline: false,
|
|
77
|
-
downloadThroughput: 10240 * 1e3 / 8,
|
|
78
|
-
uploadThroughput: 10240 * 1e3 / 8,
|
|
79
|
-
latency: 40
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
async function emulateNetworkConditions(condition) {
|
|
83
|
-
if ("chromium" !== this.browserName) {
|
|
84
|
-
throw new Error(
|
|
85
|
-
"CDP sessions are only supported on Chromium-based browsers"
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
const session = await this.page.context().newCDPSession(this.page);
|
|
89
|
-
await session.send(
|
|
90
|
-
"Network.emulateNetworkConditions",
|
|
91
|
-
"string" === typeof condition ? PredefinedNetworkConditions[condition] : condition
|
|
92
|
-
);
|
|
93
|
-
await session.detach();
|
|
94
|
-
}
|
|
95
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
96
|
-
0 && (module.exports = {
|
|
97
|
-
emulateNetworkConditions
|
|
98
|
-
});
|
|
99
|
-
//# sourceMappingURL=emulate-network-conditions.cjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/page-utils/emulate-network-conditions.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { PageUtils } from './';\n\ninterface NetworkConditions {\n\t/**\n\t * True to emulate internet disconnection.\n\t */\n\toffline: boolean;\n\t/**\n\t * Minimum latency from request sent to response headers received (ms).\n\t */\n\tlatency: number;\n\t/**\n\t * Maximal aggregated download throughput (bytes/sec). -1 disables download throttling.\n\t */\n\tdownloadThroughput: number;\n\t/**\n\t * Maximal aggregated upload throughput (bytes/sec). -1 disables upload throttling.\n\t */\n\tuploadThroughput: number;\n}\n\n// Defaults from https://github.com/puppeteer/puppeteer/blob/401355610874beac23a51dcb75739a4bb4191a2b/packages/puppeteer-core/src/cdp/PredefinedNetworkConditions.ts.\nconst PredefinedNetworkConditions: Record< string, NetworkConditions > = {\n\t// Generally aligned with DevTools\n\t// https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/front_end/core/sdk/NetworkManager.ts;l=398;drc=225e1240f522ca684473f541ae6dae6cd766dd33.\n\t'Slow 3G': {\n\t\toffline: false,\n\t\t// ~500Kbps down\n\t\tdownloadThroughput: ( ( 500 * 1000 ) / 8 ) * 0.8,\n\t\t// ~500Kbps up\n\t\tuploadThroughput: ( ( 500 * 1000 ) / 8 ) * 0.8,\n\t\t// 400ms RTT\n\t\tlatency: 400 * 5,\n\t},\n\t'Fast 3G': {\n\t\toffline: false,\n\t\t// ~1.6 Mbps down\n\t\tdownloadThroughput: ( ( 1.6 * 1000 * 1000 ) / 8 ) * 0.9,\n\t\t// ~0.75 Mbps up\n\t\tuploadThroughput: ( ( 750 * 1000 ) / 8 ) * 0.9,\n\t\t// 150ms RTT\n\t\tlatency: 150 * 3.75,\n\t},\n\t// alias to Fast 3G to align with Lighthouse (crbug.com/342406608)\n\t// and DevTools (crbug.com/342406608),\n\t'Slow 4G': {\n\t\toffline: false,\n\t\t// ~1.6 Mbps down\n\t\tdownloadThroughput: ( ( 1.6 * 1000 * 1000 ) / 8 ) * 0.9,\n\t\t// ~0.75 Mbps up\n\t\tuploadThroughput: ( ( 750 * 1000 ) / 8 ) * 0.9,\n\t\t// 150ms RTT\n\t\tlatency: 150 * 3.75,\n\t},\n\t'Fast 4G': {\n\t\toffline: false,\n\t\t// 9 Mbps down\n\t\tdownloadThroughput: ( ( 9 * 1000 * 1000 ) / 8 ) * 0.9,\n\t\t// 1.5 Mbps up\n\t\tuploadThroughput: ( ( 1.5 * 1000 * 1000 ) / 8 ) * 0.9,\n\t\t// 60ms RTT\n\t\tlatency: 60 * 2.75,\n\t},\n\t/**\n\t * Network conditions used for desktop in Lighthouse/PSI.\n\t *\n\t * 10,240 kb/s throughput with 40 ms TCP RTT.\n\t *\n\t * @see https://github.com/paulirish/lighthouse/blob/f0855904aaffaecf3089169449646960782d7e92/core/config/constants.js#L40-L49\n\t * @see https://docs.google.com/document/d/1-p4HSp42REEA5-jCBVB6PqQcVhI1nQIblBCNKhPJUXg/edit?tab=t.0#heading=h.jsap7yf4phk6\n\t */\n\tBroadband: {\n\t\toffline: false,\n\t\tdownloadThroughput: ( 10240 * 1000 ) / 8,\n\t\tuploadThroughput: ( 10240 * 1000 ) / 8,\n\t\tlatency: 40,\n\t},\n};\n\nexport async function emulateNetworkConditions(\n\tthis: PageUtils,\n\tcondition: keyof typeof PredefinedNetworkConditions | NetworkConditions\n) {\n\tif ( 'chromium' !== this.browserName ) {\n\t\tthrow new Error(\n\t\t\t'CDP sessions are only supported on Chromium-based browsers'\n\t\t);\n\t}\n\n\tconst session = await this.page.context().newCDPSession( this.page );\n\tawait session.send(\n\t\t'Network.emulateNetworkConditions',\n\t\t'string' === typeof condition\n\t\t\t? PredefinedNetworkConditions[ condition ]\n\t\t\t: condition\n\t);\n\tawait session.detach();\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAyBA,IAAM,8BAAmE;AAAA;AAAA;AAAA,EAGxE,WAAW;AAAA,IACV,SAAS;AAAA;AAAA,IAET,oBAAwB,MAAM,MAAS,IAAM;AAAA;AAAA,IAE7C,kBAAsB,MAAM,MAAS,IAAM;AAAA;AAAA,IAE3C,SAAS,MAAM;AAAA,EAChB;AAAA,EACA,WAAW;AAAA,IACV,SAAS;AAAA;AAAA,IAET,oBAAwB,MAAM,MAAO,MAAS,IAAM;AAAA;AAAA,IAEpD,kBAAsB,MAAM,MAAS,IAAM;AAAA;AAAA,IAE3C,SAAS,MAAM;AAAA,EAChB;AAAA;AAAA;AAAA,EAGA,WAAW;AAAA,IACV,SAAS;AAAA;AAAA,IAET,oBAAwB,MAAM,MAAO,MAAS,IAAM;AAAA;AAAA,IAEpD,kBAAsB,MAAM,MAAS,IAAM;AAAA;AAAA,IAE3C,SAAS,MAAM;AAAA,EAChB;AAAA,EACA,WAAW;AAAA,IACV,SAAS;AAAA;AAAA,IAET,oBAAwB,IAAI,MAAO,MAAS,IAAM;AAAA;AAAA,IAElD,kBAAsB,MAAM,MAAO,MAAS,IAAM;AAAA;AAAA,IAElD,SAAS,KAAK;AAAA,EACf;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,WAAW;AAAA,IACV,SAAS;AAAA,IACT,oBAAsB,QAAQ,MAAS;AAAA,IACvC,kBAAoB,QAAQ,MAAS;AAAA,IACrC,SAAS;AAAA,EACV;AACD;AAEA,eAAsB,yBAErB,WACC;AACD,MAAK,eAAe,KAAK,aAAc;AACtC,UAAM,IAAI;AAAA,MACT;AAAA,IACD;AAAA,EACD;AAEA,QAAM,UAAU,MAAM,KAAK,KAAK,QAAQ,EAAE,cAAe,KAAK,IAAK;AACnE,QAAM,QAAQ;AAAA,IACb;AAAA,IACA,aAAa,OAAO,YACjB,4BAA6B,SAAU,IACvC;AAAA,EACJ;AACA,QAAM,QAAQ,OAAO;AACtB;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// packages/e2e-test-utils-playwright/src/page-utils/index.ts
|
|
21
|
-
var page_utils_exports = {};
|
|
22
|
-
__export(page_utils_exports, {
|
|
23
|
-
PageUtils: () => PageUtils
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(page_utils_exports);
|
|
26
|
-
var import_drag_files = require("./drag-files.cjs");
|
|
27
|
-
var import_is_current_url = require("./is-current-url.cjs");
|
|
28
|
-
var import_press_keys = require("./press-keys.cjs");
|
|
29
|
-
var import_set_browser_viewport = require("./set-browser-viewport.cjs");
|
|
30
|
-
var import_emulate_network_conditions = require("./emulate-network-conditions.cjs");
|
|
31
|
-
var PageUtils = class {
|
|
32
|
-
browser;
|
|
33
|
-
page;
|
|
34
|
-
context;
|
|
35
|
-
browserName;
|
|
36
|
-
constructor({ page, browserName }) {
|
|
37
|
-
this.page = page;
|
|
38
|
-
this.context = page.context();
|
|
39
|
-
this.browser = this.context.browser();
|
|
40
|
-
this.browserName = browserName;
|
|
41
|
-
}
|
|
42
|
-
/** @borrows dragFiles as this.dragFiles */
|
|
43
|
-
dragFiles = import_drag_files.dragFiles.bind(this);
|
|
44
|
-
/** @borrows isCurrentURL as this.isCurrentURL */
|
|
45
|
-
isCurrentURL = import_is_current_url.isCurrentURL.bind(this);
|
|
46
|
-
/** @borrows pressKeys as this.pressKeys */
|
|
47
|
-
pressKeys = import_press_keys.pressKeys.bind(this);
|
|
48
|
-
/** @borrows setBrowserViewport as this.setBrowserViewport */
|
|
49
|
-
setBrowserViewport = import_set_browser_viewport.setBrowserViewport.bind(this);
|
|
50
|
-
/** @borrows setClipboardData as this.setClipboardData */
|
|
51
|
-
setClipboardData = import_press_keys.setClipboardData.bind(this);
|
|
52
|
-
/** @borrows emulateNetworkConditions as this.emulateNetworkConditions */
|
|
53
|
-
emulateNetworkConditions = import_emulate_network_conditions.emulateNetworkConditions.bind(this);
|
|
54
|
-
};
|
|
55
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
56
|
-
0 && (module.exports = {
|
|
57
|
-
PageUtils
|
|
58
|
-
});
|
|
59
|
-
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/page-utils/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport type {\n\tBrowser,\n\tPage,\n\tBrowserContext,\n\tPlaywrightWorkerOptions,\n} from '@playwright/test';\n\n/**\n * Internal dependencies\n */\nimport { dragFiles } from './drag-files';\nimport { isCurrentURL } from './is-current-url';\nimport { setClipboardData, pressKeys } from './press-keys';\nimport { setBrowserViewport } from './set-browser-viewport';\nimport { emulateNetworkConditions } from './emulate-network-conditions';\n\ntype PageUtilConstructorParams = {\n\tpage: Page;\n\tbrowserName: PlaywrightWorkerOptions[ 'browserName' ];\n};\n\nclass PageUtils {\n\tbrowser: Browser;\n\tpage: Page;\n\tcontext: BrowserContext;\n\tbrowserName: PlaywrightWorkerOptions[ 'browserName' ];\n\n\tconstructor( { page, browserName }: PageUtilConstructorParams ) {\n\t\tthis.page = page;\n\t\tthis.context = page.context();\n\t\tthis.browser = this.context.browser()!;\n\t\tthis.browserName = browserName;\n\t}\n\n\t/** @borrows dragFiles as this.dragFiles */\n\tdragFiles: typeof dragFiles = dragFiles.bind( this );\n\t/** @borrows isCurrentURL as this.isCurrentURL */\n\tisCurrentURL: typeof isCurrentURL = isCurrentURL.bind( this );\n\t/** @borrows pressKeys as this.pressKeys */\n\tpressKeys: typeof pressKeys = pressKeys.bind( this );\n\t/** @borrows setBrowserViewport as this.setBrowserViewport */\n\tsetBrowserViewport: typeof setBrowserViewport =\n\t\tsetBrowserViewport.bind( this );\n\t/** @borrows setClipboardData as this.setClipboardData */\n\tsetClipboardData: typeof setClipboardData = setClipboardData.bind( this );\n\t/** @borrows emulateNetworkConditions as this.emulateNetworkConditions */\n\temulateNetworkConditions: typeof emulateNetworkConditions =\n\t\temulateNetworkConditions.bind( this );\n}\n\nexport { PageUtils };\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAaA,wBAA0B;AAC1B,4BAA6B;AAC7B,wBAA4C;AAC5C,kCAAmC;AACnC,wCAAyC;AAOzC,IAAM,YAAN,MAAgB;AAAA,EACf;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA,YAAa,EAAE,MAAM,YAAY,GAA+B;AAC/D,SAAK,OAAO;AACZ,SAAK,UAAU,KAAK,QAAQ;AAC5B,SAAK,UAAU,KAAK,QAAQ,QAAQ;AACpC,SAAK,cAAc;AAAA,EACpB;AAAA;AAAA,EAGA,YAA8B,4BAAU,KAAM,IAAK;AAAA;AAAA,EAEnD,eAAoC,mCAAa,KAAM,IAAK;AAAA;AAAA,EAE5D,YAA8B,4BAAU,KAAM,IAAK;AAAA;AAAA,EAEnD,qBACC,+CAAmB,KAAM,IAAK;AAAA;AAAA,EAE/B,mBAA4C,mCAAiB,KAAM,IAAK;AAAA;AAAA,EAExE,2BACC,2DAAyB,KAAM,IAAK;AACtC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// packages/e2e-test-utils-playwright/src/page-utils/is-current-url.ts
|
|
21
|
-
var is_current_url_exports = {};
|
|
22
|
-
__export(is_current_url_exports, {
|
|
23
|
-
isCurrentURL: () => isCurrentURL
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(is_current_url_exports);
|
|
26
|
-
var import_config = require("../config.cjs");
|
|
27
|
-
function isCurrentURL(path) {
|
|
28
|
-
const currentURL = new URL(this.page.url());
|
|
29
|
-
const expectedURL = new URL(path, import_config.WP_BASE_URL);
|
|
30
|
-
return expectedURL.pathname === currentURL.pathname;
|
|
31
|
-
}
|
|
32
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
33
|
-
0 && (module.exports = {
|
|
34
|
-
isCurrentURL
|
|
35
|
-
});
|
|
36
|
-
//# sourceMappingURL=is-current-url.cjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/page-utils/is-current-url.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport { WP_BASE_URL } from '../config';\nimport type { PageUtils } from './';\n\n/**\n * Checks if current path of the URL matches the provided path.\n *\n * @param this\n * @param path String to be serialized as pathname.\n *\n * @return Boolean represents whether current URL is or not a WordPress path.\n */\nexport function isCurrentURL( this: PageUtils, path: string ) {\n\tconst currentURL = new URL( this.page.url() );\n\tconst expectedURL = new URL( path, WP_BASE_URL );\n\n\treturn expectedURL.pathname === currentURL.pathname;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAA4B;AAWrB,SAAS,aAA+B,MAAe;AAC7D,QAAM,aAAa,IAAI,IAAK,KAAK,KAAK,IAAI,CAAE;AAC5C,QAAM,cAAc,IAAI,IAAK,MAAM,yBAAY;AAE/C,SAAO,YAAY,aAAa,WAAW;AAC5C;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// packages/e2e-test-utils-playwright/src/page-utils/keycodes.ts
|
|
21
|
-
var keycodes_exports = {};
|
|
22
|
-
__export(keycodes_exports, {
|
|
23
|
-
ALT: () => ALT,
|
|
24
|
-
COMMAND: () => COMMAND,
|
|
25
|
-
CTRL: () => CTRL,
|
|
26
|
-
SHIFT: () => SHIFT,
|
|
27
|
-
modifiers: () => modifiers
|
|
28
|
-
});
|
|
29
|
-
module.exports = __toCommonJS(keycodes_exports);
|
|
30
|
-
var ALT = "alt";
|
|
31
|
-
var CTRL = "ctrl";
|
|
32
|
-
var COMMAND = "meta";
|
|
33
|
-
var SHIFT = "shift";
|
|
34
|
-
var modifiers = {
|
|
35
|
-
primary: (_isApple) => _isApple() ? [COMMAND] : [CTRL],
|
|
36
|
-
primaryShift: (_isApple) => _isApple() ? [SHIFT, COMMAND] : [CTRL, SHIFT],
|
|
37
|
-
primaryAlt: (_isApple) => _isApple() ? [ALT, COMMAND] : [CTRL, ALT],
|
|
38
|
-
secondary: (_isApple) => _isApple() ? [SHIFT, ALT, COMMAND] : [CTRL, SHIFT, ALT],
|
|
39
|
-
access: (_isApple) => _isApple() ? [CTRL, ALT] : [SHIFT, ALT],
|
|
40
|
-
ctrl: () => [CTRL],
|
|
41
|
-
alt: () => [ALT],
|
|
42
|
-
ctrlShift: () => [CTRL, SHIFT],
|
|
43
|
-
shift: () => [SHIFT],
|
|
44
|
-
shiftAlt: () => [SHIFT, ALT],
|
|
45
|
-
undefined: () => []
|
|
46
|
-
};
|
|
47
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
48
|
-
0 && (module.exports = {
|
|
49
|
-
ALT,
|
|
50
|
-
COMMAND,
|
|
51
|
-
CTRL,
|
|
52
|
-
SHIFT,
|
|
53
|
-
modifiers
|
|
54
|
-
});
|
|
55
|
-
//# sourceMappingURL=keycodes.cjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/page-utils/keycodes.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * This filed is partially copied from @wordpress/keycodes to keep the package\n * (internal-)dependencies free.\n */\n\n/**\n * Keycode for ALT key.\n */\nexport const ALT = 'alt';\n\n/**\n * Keycode for CTRL key.\n */\nexport const CTRL = 'ctrl';\n\n/**\n * Keycode for COMMAND key.\n */\nexport const COMMAND = 'meta';\n\n/**\n * Keycode for SHIFT key.\n */\nexport const SHIFT = 'shift';\n\n/**\n * Object that contains functions that return the available modifier\n * depending on platform.\n */\nexport const modifiers: Record<\n\tstring,\n\t( _isApple: () => boolean ) => string[]\n> = {\n\tprimary: ( _isApple ) => ( _isApple() ? [ COMMAND ] : [ CTRL ] ),\n\tprimaryShift: ( _isApple ) =>\n\t\t_isApple() ? [ SHIFT, COMMAND ] : [ CTRL, SHIFT ],\n\tprimaryAlt: ( _isApple ) =>\n\t\t_isApple() ? [ ALT, COMMAND ] : [ CTRL, ALT ],\n\tsecondary: ( _isApple ) =>\n\t\t_isApple() ? [ SHIFT, ALT, COMMAND ] : [ CTRL, SHIFT, ALT ],\n\taccess: ( _isApple ) => ( _isApple() ? [ CTRL, ALT ] : [ SHIFT, ALT ] ),\n\tctrl: () => [ CTRL ],\n\talt: () => [ ALT ],\n\tctrlShift: () => [ CTRL, SHIFT ],\n\tshift: () => [ SHIFT ],\n\tshiftAlt: () => [ SHIFT, ALT ],\n\tundefined: () => [],\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQO,IAAM,MAAM;AAKZ,IAAM,OAAO;AAKb,IAAM,UAAU;AAKhB,IAAM,QAAQ;AAMd,IAAM,YAGT;AAAA,EACH,SAAS,CAAE,aAAgB,SAAS,IAAI,CAAE,OAAQ,IAAI,CAAE,IAAK;AAAA,EAC7D,cAAc,CAAE,aACf,SAAS,IAAI,CAAE,OAAO,OAAQ,IAAI,CAAE,MAAM,KAAM;AAAA,EACjD,YAAY,CAAE,aACb,SAAS,IAAI,CAAE,KAAK,OAAQ,IAAI,CAAE,MAAM,GAAI;AAAA,EAC7C,WAAW,CAAE,aACZ,SAAS,IAAI,CAAE,OAAO,KAAK,OAAQ,IAAI,CAAE,MAAM,OAAO,GAAI;AAAA,EAC3D,QAAQ,CAAE,aAAgB,SAAS,IAAI,CAAE,MAAM,GAAI,IAAI,CAAE,OAAO,GAAI;AAAA,EACpE,MAAM,MAAM,CAAE,IAAK;AAAA,EACnB,KAAK,MAAM,CAAE,GAAI;AAAA,EACjB,WAAW,MAAM,CAAE,MAAM,KAAM;AAAA,EAC/B,OAAO,MAAM,CAAE,KAAM;AAAA,EACrB,UAAU,MAAM,CAAE,OAAO,GAAI;AAAA,EAC7B,WAAW,MAAM,CAAC;AACnB;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// packages/e2e-test-utils-playwright/src/page-utils/press-keys.ts
|
|
21
|
-
var press_keys_exports = {};
|
|
22
|
-
__export(press_keys_exports, {
|
|
23
|
-
pressKeys: () => pressKeys,
|
|
24
|
-
setClipboardData: () => setClipboardData
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(press_keys_exports);
|
|
27
|
-
var import_change_case = require("change-case");
|
|
28
|
-
var import_keycodes = require("./keycodes.cjs");
|
|
29
|
-
var clipboardDataHolder = {
|
|
30
|
-
"text/plain": "",
|
|
31
|
-
"text/html": "",
|
|
32
|
-
"rich-text": ""
|
|
33
|
-
};
|
|
34
|
-
function setClipboardData({ plainText = "", html = "" }) {
|
|
35
|
-
clipboardDataHolder = {
|
|
36
|
-
"text/plain": plainText,
|
|
37
|
-
"text/html": html,
|
|
38
|
-
"rich-text": ""
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
async function emulateClipboard(page, type) {
|
|
42
|
-
const output = await page.evaluate(
|
|
43
|
-
([_type, _clipboardData]) => {
|
|
44
|
-
const canvasDoc = (
|
|
45
|
-
// @ts-ignore
|
|
46
|
-
document.activeElement?.contentDocument ?? document
|
|
47
|
-
);
|
|
48
|
-
const event = new ClipboardEvent(_type, {
|
|
49
|
-
bubbles: true,
|
|
50
|
-
cancelable: true,
|
|
51
|
-
clipboardData: new DataTransfer()
|
|
52
|
-
});
|
|
53
|
-
if (!event.clipboardData) {
|
|
54
|
-
throw new Error("ClipboardEvent.clipboardData is null");
|
|
55
|
-
}
|
|
56
|
-
if (_type === "paste") {
|
|
57
|
-
event.clipboardData.setData(
|
|
58
|
-
"text/plain",
|
|
59
|
-
_clipboardData["text/plain"]
|
|
60
|
-
);
|
|
61
|
-
event.clipboardData.setData(
|
|
62
|
-
"text/html",
|
|
63
|
-
_clipboardData["text/html"]
|
|
64
|
-
);
|
|
65
|
-
event.clipboardData.setData(
|
|
66
|
-
"rich-text",
|
|
67
|
-
_clipboardData["rich-text"]
|
|
68
|
-
);
|
|
69
|
-
} else {
|
|
70
|
-
const selection = canvasDoc.defaultView.getSelection();
|
|
71
|
-
const plainText = selection.toString();
|
|
72
|
-
let html = plainText;
|
|
73
|
-
if (selection.rangeCount) {
|
|
74
|
-
const range = selection.getRangeAt(0);
|
|
75
|
-
const fragment = range.cloneContents();
|
|
76
|
-
html = Array.from(fragment.childNodes).map(
|
|
77
|
-
(node) => node.outerHTML ?? node.nodeValue
|
|
78
|
-
).join("");
|
|
79
|
-
}
|
|
80
|
-
event.clipboardData.setData("text/plain", plainText);
|
|
81
|
-
event.clipboardData.setData("text/html", html);
|
|
82
|
-
}
|
|
83
|
-
canvasDoc.activeElement.dispatchEvent(event);
|
|
84
|
-
if (_type === "paste") {
|
|
85
|
-
return event.defaultPrevented;
|
|
86
|
-
}
|
|
87
|
-
return {
|
|
88
|
-
"text/plain": event.clipboardData.getData("text/plain"),
|
|
89
|
-
"text/html": event.clipboardData.getData("text/html"),
|
|
90
|
-
"rich-text": event.clipboardData.getData("rich-text")
|
|
91
|
-
};
|
|
92
|
-
},
|
|
93
|
-
[type, clipboardDataHolder]
|
|
94
|
-
);
|
|
95
|
-
if (typeof output === "object") {
|
|
96
|
-
clipboardDataHolder = output;
|
|
97
|
-
}
|
|
98
|
-
if (output === false) {
|
|
99
|
-
await page.keyboard.type(clipboardDataHolder["text/plain"]);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
var isAppleOS = () => process.platform === "darwin";
|
|
103
|
-
var isWebkit = (page) => page.context().browser().browserType().name() === "webkit";
|
|
104
|
-
var browserCache = /* @__PURE__ */ new WeakMap();
|
|
105
|
-
var getHasNaturalTabNavigation = async (page) => {
|
|
106
|
-
if (!isAppleOS() || !isWebkit(page)) {
|
|
107
|
-
return true;
|
|
108
|
-
}
|
|
109
|
-
if (browserCache.has(page.context().browser())) {
|
|
110
|
-
return browserCache.get(page.context().browser());
|
|
111
|
-
}
|
|
112
|
-
const testPage = await page.context().newPage();
|
|
113
|
-
await testPage.setContent(`<button>1</button><button>2</button>`);
|
|
114
|
-
await testPage.getByText("1").focus();
|
|
115
|
-
await testPage.keyboard.press("Tab");
|
|
116
|
-
const featureDetected = await testPage.getByText("2").evaluate((node) => node === document.activeElement);
|
|
117
|
-
browserCache.set(page.context().browser(), featureDetected);
|
|
118
|
-
await testPage.close();
|
|
119
|
-
return featureDetected;
|
|
120
|
-
};
|
|
121
|
-
var modifiers = {
|
|
122
|
-
...import_keycodes.modifiers,
|
|
123
|
-
shiftAlt: (_isApple) => _isApple() ? [import_keycodes.SHIFT, import_keycodes.ALT] : [import_keycodes.SHIFT, import_keycodes.CTRL]
|
|
124
|
-
};
|
|
125
|
-
async function pressKeys(key, { times, ...pressOptions } = {}) {
|
|
126
|
-
const hasNaturalTabNavigation = await getHasNaturalTabNavigation(
|
|
127
|
-
this.page
|
|
128
|
-
);
|
|
129
|
-
let command;
|
|
130
|
-
if (key.toLowerCase() === "primary+c") {
|
|
131
|
-
command = () => emulateClipboard(this.page, "copy");
|
|
132
|
-
} else if (key.toLowerCase() === "primary+x") {
|
|
133
|
-
command = () => emulateClipboard(this.page, "cut");
|
|
134
|
-
} else if (key.toLowerCase() === "primary+v") {
|
|
135
|
-
command = () => emulateClipboard(this.page, "paste");
|
|
136
|
-
} else {
|
|
137
|
-
const keys = key.split("+").flatMap((keyCode) => {
|
|
138
|
-
if (Object.prototype.hasOwnProperty.call(modifiers, keyCode)) {
|
|
139
|
-
return modifiers[keyCode](
|
|
140
|
-
isAppleOS
|
|
141
|
-
).map(
|
|
142
|
-
(modifier) => modifier === import_keycodes.CTRL ? "Control" : (0, import_change_case.capitalCase)(modifier)
|
|
143
|
-
);
|
|
144
|
-
} else if (keyCode === "Tab" && !hasNaturalTabNavigation) {
|
|
145
|
-
return ["Alt", "Tab"];
|
|
146
|
-
}
|
|
147
|
-
return keyCode;
|
|
148
|
-
});
|
|
149
|
-
const normalizedKeys = keys.join("+");
|
|
150
|
-
command = () => this.page.keyboard.press(normalizedKeys);
|
|
151
|
-
}
|
|
152
|
-
times = times ?? 1;
|
|
153
|
-
for (let i = 0; i < times; i += 1) {
|
|
154
|
-
await command();
|
|
155
|
-
if (times > 1 && pressOptions.delay) {
|
|
156
|
-
await this.page.waitForTimeout(pressOptions.delay);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
161
|
-
0 && (module.exports = {
|
|
162
|
-
pressKeys,
|
|
163
|
-
setClipboardData
|
|
164
|
-
});
|
|
165
|
-
//# sourceMappingURL=press-keys.cjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/page-utils/press-keys.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport { capitalCase } from 'change-case';\nimport type { Page } from '@playwright/test';\n\n/**\n * Internal dependencies\n */\nimport type { PageUtils } from './';\nimport { modifiers as baseModifiers, SHIFT, ALT, CTRL } from './keycodes';\n\nlet clipboardDataHolder: {\n\t'text/plain': string;\n\t'text/html': string;\n\t'rich-text': string;\n} = {\n\t'text/plain': '',\n\t'text/html': '',\n\t'rich-text': '',\n};\n\n/**\n * Sets the clipboard data that can be pasted with\n * `pressKeys( 'primary+v' )`.\n *\n * @param this\n * @param clipboardData\n * @param clipboardData.plainText\n * @param clipboardData.html\n */\nexport function setClipboardData(\n\tthis: PageUtils,\n\t{ plainText = '', html = '' }\n) {\n\tclipboardDataHolder = {\n\t\t'text/plain': plainText,\n\t\t'text/html': html,\n\t\t'rich-text': '',\n\t};\n}\n\nasync function emulateClipboard( page: Page, type: 'copy' | 'cut' | 'paste' ) {\n\tconst output = await page.evaluate(\n\t\t( [ _type, _clipboardData ] ) => {\n\t\t\tconst canvasDoc =\n\t\t\t\t// @ts-ignore\n\t\t\t\tdocument.activeElement?.contentDocument ?? document;\n\t\t\tconst event = new ClipboardEvent( _type, {\n\t\t\t\tbubbles: true,\n\t\t\t\tcancelable: true,\n\t\t\t\tclipboardData: new DataTransfer(),\n\t\t\t} );\n\n\t\t\tif ( ! event.clipboardData ) {\n\t\t\t\tthrow new Error( 'ClipboardEvent.clipboardData is null' );\n\t\t\t}\n\n\t\t\tif ( _type === 'paste' ) {\n\t\t\t\tevent.clipboardData.setData(\n\t\t\t\t\t'text/plain',\n\t\t\t\t\t_clipboardData[ 'text/plain' ]\n\t\t\t\t);\n\t\t\t\tevent.clipboardData.setData(\n\t\t\t\t\t'text/html',\n\t\t\t\t\t_clipboardData[ 'text/html' ]\n\t\t\t\t);\n\t\t\t\tevent.clipboardData.setData(\n\t\t\t\t\t'rich-text',\n\t\t\t\t\t_clipboardData[ 'rich-text' ]\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tconst selection = canvasDoc.defaultView.getSelection()!;\n\t\t\t\tconst plainText = selection.toString();\n\t\t\t\tlet html = plainText;\n\t\t\t\tif ( selection.rangeCount ) {\n\t\t\t\t\tconst range = selection.getRangeAt( 0 );\n\t\t\t\t\tconst fragment = range.cloneContents();\n\t\t\t\t\thtml = Array.from( fragment.childNodes )\n\t\t\t\t\t\t.map(\n\t\t\t\t\t\t\t( node ) =>\n\t\t\t\t\t\t\t\t( node as Element ).outerHTML ??\n\t\t\t\t\t\t\t\t( node as Element ).nodeValue\n\t\t\t\t\t\t)\n\t\t\t\t\t\t.join( '' );\n\t\t\t\t}\n\t\t\t\tevent.clipboardData.setData( 'text/plain', plainText );\n\t\t\t\tevent.clipboardData.setData( 'text/html', html );\n\t\t\t}\n\n\t\t\tcanvasDoc.activeElement.dispatchEvent( event );\n\n\t\t\tif ( _type === 'paste' ) {\n\t\t\t\treturn event.defaultPrevented;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t'text/plain': event.clipboardData.getData( 'text/plain' ),\n\t\t\t\t'text/html': event.clipboardData.getData( 'text/html' ),\n\t\t\t\t'rich-text': event.clipboardData.getData( 'rich-text' ),\n\t\t\t};\n\t\t},\n\t\t[ type, clipboardDataHolder ] as const\n\t);\n\n\tif ( typeof output === 'object' ) {\n\t\tclipboardDataHolder = output;\n\t}\n\n\tif ( output === false ) {\n\t\t// Emulate paste by typing the clipboard content, which works across all\n\t\t// elements and documents (keyboard.type does uses the nested active\n\t\t// element automatically).\n\t\tawait page.keyboard.type( clipboardDataHolder[ 'text/plain' ] );\n\t}\n}\n\nconst isAppleOS = () => process.platform === 'darwin';\n\nconst isWebkit = ( page: Page ) =>\n\tpage.context().browser()!.browserType().name() === 'webkit';\n\nconst browserCache = new WeakMap();\nconst getHasNaturalTabNavigation = async ( page: Page ) => {\n\tif ( ! isAppleOS() || ! isWebkit( page ) ) {\n\t\treturn true;\n\t}\n\tif ( browserCache.has( page.context().browser()! ) ) {\n\t\treturn browserCache.get( page.context().browser()! );\n\t}\n\tconst testPage = await page.context().newPage();\n\tawait testPage.setContent( `<button>1</button><button>2</button>` );\n\tawait testPage.getByText( '1' ).focus();\n\tawait testPage.keyboard.press( 'Tab' );\n\tconst featureDetected = await testPage\n\t\t.getByText( '2' )\n\t\t.evaluate( ( node ) => node === document.activeElement );\n\tbrowserCache.set( page.context().browser()!, featureDetected );\n\tawait testPage.close();\n\treturn featureDetected;\n};\n\ntype Options = {\n\ttimes?: number;\n\tdelay?: number;\n};\n\nconst modifiers = {\n\t...baseModifiers,\n\tshiftAlt: ( _isApple: () => boolean ) =>\n\t\t_isApple() ? [ SHIFT, ALT ] : [ SHIFT, CTRL ],\n};\n\nexport async function pressKeys(\n\tthis: PageUtils,\n\tkey: string,\n\t{ times, ...pressOptions }: Options = {}\n) {\n\tconst hasNaturalTabNavigation = await getHasNaturalTabNavigation(\n\t\tthis.page\n\t);\n\n\tlet command: () => Promise< void >;\n\n\tif ( key.toLowerCase() === 'primary+c' ) {\n\t\tcommand = () => emulateClipboard( this.page, 'copy' );\n\t} else if ( key.toLowerCase() === 'primary+x' ) {\n\t\tcommand = () => emulateClipboard( this.page, 'cut' );\n\t} else if ( key.toLowerCase() === 'primary+v' ) {\n\t\tcommand = () => emulateClipboard( this.page, 'paste' );\n\t} else {\n\t\tconst keys = key.split( '+' ).flatMap( ( keyCode ) => {\n\t\t\tif ( Object.prototype.hasOwnProperty.call( modifiers, keyCode ) ) {\n\t\t\t\treturn modifiers[ keyCode as keyof typeof modifiers ](\n\t\t\t\t\tisAppleOS\n\t\t\t\t).map( ( modifier ) =>\n\t\t\t\t\tmodifier === CTRL ? 'Control' : capitalCase( modifier )\n\t\t\t\t);\n\t\t\t} else if ( keyCode === 'Tab' && ! hasNaturalTabNavigation ) {\n\t\t\t\treturn [ 'Alt', 'Tab' ];\n\t\t\t}\n\t\t\treturn keyCode;\n\t\t} );\n\t\tconst normalizedKeys = keys.join( '+' );\n\t\tcommand = () => this.page.keyboard.press( normalizedKeys );\n\t}\n\n\ttimes = times ?? 1;\n\tfor ( let i = 0; i < times; i += 1 ) {\n\t\tawait command();\n\n\t\tif ( times > 1 && pressOptions.delay ) {\n\t\t\tawait this.page.waitForTimeout( pressOptions.delay );\n\t\t}\n\t}\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,yBAA4B;AAO5B,sBAA6D;AAE7D,IAAI,sBAIA;AAAA,EACH,cAAc;AAAA,EACd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