@e2e-dev/electron 0.0.0-stage → 0.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.
Files changed (75) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +5 -0
  3. package/README.md +91 -2
  4. package/dist/.build.json +1 -0
  5. package/dist/actionability.d.ts +41 -0
  6. package/dist/actionability.js +121 -0
  7. package/dist/actions.d.ts +52 -0
  8. package/dist/actions.js +418 -0
  9. package/dist/app-process.d.ts +114 -0
  10. package/dist/app-process.js +610 -0
  11. package/dist/budget.d.ts +33 -0
  12. package/dist/budget.js +64 -0
  13. package/dist/capture.d.ts +21 -0
  14. package/dist/capture.js +137 -0
  15. package/dist/cdp/connection.d.ts +68 -0
  16. package/dist/cdp/connection.js +232 -0
  17. package/dist/cdp/input.d.ts +67 -0
  18. package/dist/cdp/input.js +195 -0
  19. package/dist/cdp/keys.d.ts +21 -0
  20. package/dist/cdp/keys.js +114 -0
  21. package/dist/console-text.d.ts +4 -0
  22. package/dist/console-text.js +27 -0
  23. package/dist/devtools.d.ts +36 -0
  24. package/dist/devtools.js +111 -0
  25. package/dist/dialogs.d.ts +38 -0
  26. package/dist/dialogs.js +81 -0
  27. package/dist/electron.d.ts +9 -0
  28. package/dist/electron.js +174 -0
  29. package/dist/engine-entry.d.ts +13 -0
  30. package/dist/engine-entry.js +9 -0
  31. package/dist/engine.d.ts +27 -0
  32. package/dist/engine.js +98 -0
  33. package/dist/errors.d.ts +17 -0
  34. package/dist/errors.js +54 -0
  35. package/dist/evaluate.d.ts +40 -0
  36. package/dist/evaluate.js +115 -0
  37. package/dist/executable.d.ts +29 -0
  38. package/dist/executable.js +249 -0
  39. package/dist/ffmpeg.d.ts +12 -0
  40. package/dist/ffmpeg.js +100 -0
  41. package/dist/fields.d.ts +93 -0
  42. package/dist/fields.js +254 -0
  43. package/dist/file-bound.d.ts +31 -0
  44. package/dist/file-bound.js +104 -0
  45. package/dist/fixtures.d.ts +168 -0
  46. package/dist/fixtures.js +6 -0
  47. package/dist/in-page/masks.d.ts +25 -0
  48. package/dist/in-page/masks.js +140 -0
  49. package/dist/in-page/node-ops.d.ts +96 -0
  50. package/dist/in-page/node-ops.js +406 -0
  51. package/dist/index.d.ts +18 -0
  52. package/dist/index.js +18 -0
  53. package/dist/launcher.d.ts +45 -0
  54. package/dist/launcher.js +167 -0
  55. package/dist/locate.d.ts +46 -0
  56. package/dist/locate.js +103 -0
  57. package/dist/main-process.d.ts +25 -0
  58. package/dist/main-process.js +60 -0
  59. package/dist/options.d.ts +65 -0
  60. package/dist/options.js +120 -0
  61. package/dist/page.d.ts +100 -0
  62. package/dist/page.js +229 -0
  63. package/dist/runner-test.d.ts +15 -0
  64. package/dist/runner-test.js +45 -0
  65. package/dist/snapshot.d.ts +143 -0
  66. package/dist/snapshot.js +260 -0
  67. package/dist/surface.d.ts +158 -0
  68. package/dist/surface.js +602 -0
  69. package/dist/tree.d.ts +51 -0
  70. package/dist/tree.js +406 -0
  71. package/dist/video.d.ts +42 -0
  72. package/dist/video.js +253 -0
  73. package/dist/windows.d.ts +81 -0
  74. package/dist/windows.js +200 -0
  75. package/package.json +72 -3
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,5 @@
1
+ @e2e-dev/electron
2
+ Copyright 2026 TesterArmy, Inc.
3
+
4
+ This product includes software developed at TesterArmy, Inc.
5
+ (https://tester.army).
package/README.md CHANGED
@@ -1,3 +1,92 @@
1
- # Temporary Holding Version
1
+ # @e2e-dev/electron
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The Electron engine for [`e2e`](https://www.npmjs.com/package/e2e): an
4
+ Electron app's windows, read through Chromium's accessibility tree over the
5
+ DevTools protocol and driven with trusted input, through the same
6
+ `@e2e-dev/core/engine` contract the browser, mobile, and desktop engines
7
+ implement. A test written against `screen`, `expect`, `app`, and `agent` runs
8
+ on an Electron target unchanged.
9
+
10
+ It is also the reference for an engine built outside this repository: it
11
+ imports only `@e2e-dev/core/engine` and speaks the DevTools protocol itself,
12
+ with no automation library and never another engine. [Engines](https://e2e.com/docs/engines) lists what
13
+ building it changed in the contract.
14
+
15
+ ## Install
16
+
17
+ ```bash
18
+ npm install --save-dev e2e @e2e-dev/electron electron
19
+ ```
20
+
21
+ The engine starts the `electron` package installed in the project, and
22
+ downloads its binary one time per run when it is missing. Run
23
+ `npx e2e doctor` to check.
24
+
25
+ ```ts title="e2e.config.ts"
26
+ import type { E2EConfig } from 'e2e';
27
+ import { electron } from '@e2e-dev/electron';
28
+
29
+ export default {
30
+ targets: [{ name: 'electron', engine: electron(), app: { appPath: '.' } }],
31
+ } satisfies E2EConfig;
32
+ ```
33
+
34
+ `app.appPath` is the app's directory or main script, and `app.launchArguments`
35
+ are the switches every launch gets, the app's own and Chromium's. For a packaged app, pass
36
+ `electron({ executablePath })` and leave out `appPath`.
37
+
38
+ ```ts title="tests/sign-in.e2e.ts"
39
+ import { test } from '@e2e-dev/electron';
40
+ import { credentials, expect } from 'e2e';
41
+
42
+ test('signs in', async ({ app, screen }) => {
43
+ await app.open();
44
+ await screen.getByRole('textbox', 'Username').fill('ada');
45
+ await screen.getByRole('textbox', 'Password').fill(credentials.user('ada').password);
46
+ await screen.getByRole('button', 'Sign in').tap();
47
+ await expect(screen.getByTestId('status')).toContainText('Signed in');
48
+ });
49
+ ```
50
+
51
+ ## How it works
52
+
53
+ - **Launch.** `app.open()` starts the app on an empty user-data directory and
54
+ waits for a window to load. Every test ends with the app quit.
55
+ - **Read.** Chromium's accessibility tree joined with one DOM snapshot.
56
+ Nothing runs in the app's page to read it.
57
+ - **Act.** Trusted mouse and keyboard input, once the node is enabled, on
58
+ screen, and topmost at its point.
59
+ - **Windows.** The agent sees them as tabs. The `electron` fixture has
60
+ `launch` (per-test arguments and environment), `userDataDir`, `evaluate`
61
+ (main process), `windows`, `activeWindow`, `waitForWindow`, `window`,
62
+ `waitForDownload`, `onDialog`, `locator` (CSS), `keyboard`, and `mouse`. A
63
+ window has `evaluate` (its page) and `reload`.
64
+ - **Video.** The shown window's screencast, encoded to one `.webm` by ffmpeg,
65
+ which the engine downloads on the first recording when the machine has none.
66
+ - **Secrets.** Password fields report no value, and screenshots paint them
67
+ and nested documents over.
68
+
69
+ ## Limits
70
+
71
+ Not on Electron, because the platform has no such thing:
72
+
73
+ | What | Instead |
74
+ | --- | --- |
75
+ | `prompt()` | Electron does not implement it. Build the prompt in the page |
76
+ | Headless mode | On Linux CI, run under a virtual display such as `xvfb-run` |
77
+ | Menu accelerators from key presses | Call the menu item from `electron.evaluate` |
78
+
79
+ Not supported yet:
80
+
81
+ | What | Until then |
82
+ | --- | --- |
83
+ | Content inside an `iframe` or `webview` | A `webview` guest is listed as a window: `electron.window()` |
84
+ | Routes and cookies | `session.defaultSession` in `electron.evaluate` |
85
+ | Session save and restore | |
86
+
87
+ [The Electron guide](https://e2e.com/docs/electron) lists every difference
88
+ from the web.
89
+
90
+ ## License
91
+
92
+ Apache-2.0
@@ -0,0 +1 @@
1
+ {"version":"0.0.0"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * The waits before an action: until the node can take it, and for a pointer
3
+ * action the point to send it to.
4
+ */
5
+ import { type Deadline, type OperationContext, type ViewportPoint } from '@e2e-dev/core/engine';
6
+ import type { DevTools } from './devtools.ts';
7
+ import type { NodeOps, Readiness } from './in-page/node-ops.ts';
8
+ import type { AppWindow } from './windows.ts';
9
+ /** A box in viewport CSS pixels. */
10
+ export interface Box {
11
+ readonly x: number;
12
+ readonly y: number;
13
+ readonly width: number;
14
+ readonly height: number;
15
+ }
16
+ /** One node an action waits on: where it is, and the deadline the wait gives up at. */
17
+ export interface WaitTarget {
18
+ readonly devtools: DevTools;
19
+ readonly window: AppWindow;
20
+ readonly backendNodeId: number;
21
+ readonly operation: OperationContext;
22
+ readonly deadline: Deadline;
23
+ }
24
+ /** The checks `waitReady` runs: the `NodeOps` that answer `Readiness`. */
25
+ type ReadinessCheck = {
26
+ [K in keyof NodeOps]: ReturnType<NodeOps[K]> extends Readiness ? K : never;
27
+ }[keyof NodeOps];
28
+ /** Waits until a page-side check passes, for actions that need no point. Gives up with the check's last reason at the deadline. */
29
+ export declare function waitReady<K extends ReadinessCheck>(target: WaitTarget, check: K, ...args: Parameters<NodeOps[K]>): Promise<void>;
30
+ /**
31
+ * Waits until the node can take a pointer action, then returns the point to
32
+ * send it to: in the document, laid out with a box, enabled when `enabled`
33
+ * asks, scrolled into view, and the topmost thing at its centre (or a label
34
+ * for it). Gives up with the last reason at the deadline.
35
+ */
36
+ export declare function actionablePoint(target: WaitTarget, enabled: boolean): Promise<ViewportPoint>;
37
+ /** The node's first content box with an area, in viewport CSS pixels; undefined when it has none. A node that is gone fails. */
38
+ export declare function contentBox(target: Pick<WaitTarget, 'devtools' | 'window' | 'backendNodeId'>): Promise<Box | undefined>;
39
+ /** Rounds a point to whole CSS pixels: Chromium truncates fractional pointer coordinates. */
40
+ export declare function whole(point: ViewportPoint): ViewportPoint;
41
+ export {};
@@ -0,0 +1,121 @@
1
+ /**
2
+ * The waits before an action: until the node can take it, and for a pointer
3
+ * action the point to send it to.
4
+ */
5
+ import { pollCondition } from '@e2e-dev/core/engine';
6
+ import { GONE, notActionable } from './errors.js';
7
+ /** Why Chromium's accessibility tree leaves out a node a modal dialog or an `inert` element blocks. */
8
+ const INERT_REASONS = new Set(['activeModalDialog', 'inertElement']);
9
+ /**
10
+ * Whether Chromium holds the node inert. It alone knows which modal dialog is
11
+ * on top and what a closed shadow root holds; the page-side checks read only
12
+ * the `inert` attributes the page can reach.
13
+ */
14
+ async function blocked(target) {
15
+ const { nodes } = await target.window.page.session.send('Accessibility.getPartialAXTree', { backendNodeId: target.backendNodeId, fetchRelatives: false });
16
+ return nodes[0]?.ignoredReasons?.some((reason) => INERT_REASONS.has(reason.name)) === true;
17
+ }
18
+ /** Waits until a page-side check passes, for actions that need no point. Gives up with the check's last reason at the deadline. */
19
+ export async function waitReady(target, check, ...args) {
20
+ let reason = '';
21
+ await pollCondition({
22
+ deadline: target.deadline,
23
+ signal: target.operation.signal,
24
+ negated: false,
25
+ evaluate: async () => {
26
+ const state = await target.devtools.callOn(target.window.page, target.backendNodeId, check, ...args);
27
+ if (state.ok && (check === 'checkConnected' || !(await blocked(target))))
28
+ return true;
29
+ reason = state.ok ? 'it is inert (a modal or the app blocks it)' : state.reason;
30
+ return false;
31
+ },
32
+ onTimeout: () => notActionable(`the element cannot take the action: ${reason}`),
33
+ });
34
+ }
35
+ /**
36
+ * Waits until the node can take a pointer action, then returns the point to
37
+ * send it to: in the document, laid out with a box, enabled when `enabled`
38
+ * asks, scrolled into view, and the topmost thing at its centre (or a label
39
+ * for it). Gives up with the last reason at the deadline.
40
+ */
41
+ export async function actionablePoint(target, enabled) {
42
+ const { devtools, window, backendNodeId } = target;
43
+ const { session } = window.page;
44
+ let reason = 'it never became actionable';
45
+ let point;
46
+ let covered = false;
47
+ const probe = async () => {
48
+ const state = await devtools.callOn(window.page, backendNodeId, 'checkEnabled', enabled);
49
+ if (!state.ok)
50
+ return state.reason;
51
+ // After a read where something covered the element, it is scrolled to the window's centre, clear of sticky chrome at an edge.
52
+ if (covered)
53
+ await devtools.callOn(window.page, backendNodeId, 'scrollIntoView');
54
+ else
55
+ await session.send('DOM.scrollIntoViewIfNeeded', { backendNodeId }).catch(() => devtools.callOn(window.page, backendNodeId, 'scrollIntoView'));
56
+ // A checkbox or radio a label draws has no box of its own: the click goes to the label, as on the web.
57
+ const box = (await contentBox(target)) ?? pointBox(await devtools.callOn(window.page, backendNodeId, 'labelPoint'));
58
+ if (box === undefined)
59
+ return 'it has no box on screen (hidden, or empty)';
60
+ // A node wider or taller than the window is clicked in the middle of the part the window shows.
61
+ const { cssVisualViewport: viewport } = await session.send('Page.getLayoutMetrics');
62
+ const shown = clip(box, viewport.clientWidth, viewport.clientHeight);
63
+ if (shown === undefined)
64
+ return 'it is outside the window';
65
+ const centre = whole({ x: shown.x + shown.width / 2, y: shown.y + shown.height / 2 });
66
+ const hit = await devtools.callOn(window.page, backendNodeId, 'hitTest', centre.x, centre.y);
67
+ covered = !hit.ok;
68
+ return hit.ok ? centre : hit.reason;
69
+ };
70
+ await pollCondition({
71
+ deadline: target.deadline,
72
+ signal: target.operation.signal,
73
+ negated: false,
74
+ evaluate: async () => {
75
+ const found = await probe();
76
+ if (typeof found === 'string') {
77
+ reason = found;
78
+ return false;
79
+ }
80
+ point = found;
81
+ return true;
82
+ },
83
+ onTimeout: () => notActionable(`the element cannot take the action: ${reason}`),
84
+ });
85
+ if (point === undefined)
86
+ throw notActionable(`the element cannot take the action: ${reason}`);
87
+ return point;
88
+ }
89
+ /** The node's first content box with an area, in viewport CSS pixels; undefined when it has none. A node that is gone fails. */
90
+ export async function contentBox(target) {
91
+ const { session } = target.window.page;
92
+ const { quads } = await session.send('DOM.getContentQuads', { backendNodeId: target.backendNodeId }).catch((cause) => {
93
+ if (cause instanceof Error && GONE.test(cause.message))
94
+ throw cause;
95
+ return { quads: [] };
96
+ });
97
+ return quads.map(boxOf).find((box) => box.width * box.height > 0);
98
+ }
99
+ /** A point as the one-pixel box around it, so it clips and centres as any box does. */
100
+ function pointBox(point) {
101
+ return point === null ? undefined : { x: point.x - 0.5, y: point.y - 0.5, width: 1, height: 1 };
102
+ }
103
+ /** Rounds a point to whole CSS pixels: Chromium truncates fractional pointer coordinates. */
104
+ export function whole(point) {
105
+ return { x: Math.round(point.x), y: Math.round(point.y) };
106
+ }
107
+ function boxOf(quad) {
108
+ const xs = [quad[0] ?? 0, quad[2] ?? 0, quad[4] ?? 0, quad[6] ?? 0];
109
+ const ys = [quad[1] ?? 0, quad[3] ?? 0, quad[5] ?? 0, quad[7] ?? 0];
110
+ const x = Math.min(...xs);
111
+ const y = Math.min(...ys);
112
+ return { x, y, width: Math.max(...xs) - x, height: Math.max(...ys) - y };
113
+ }
114
+ /** The part of a box inside a viewport of the given size, or undefined when none of it is. */
115
+ function clip(box, width, height) {
116
+ const left = Math.max(0, box.x);
117
+ const top = Math.max(0, box.y);
118
+ const right = Math.min(width, box.x + box.width);
119
+ const bottom = Math.min(height, box.y + box.height);
120
+ return right > left && bottom > top ? { x: left, y: top, width: right - left, height: bottom - top } : undefined;
121
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Actions: one function per kind, each waiting for its node as the kind
3
+ * needs, then sending trusted input through the operation's budget. A node
4
+ * action finds the point to act at and makes the gesture a point action
5
+ * makes there.
6
+ */
7
+ import { type LocatorAction, type PointerAction, type ViewportPoint } from '@e2e-dev/core/engine';
8
+ import type { Budget } from './budget.ts';
9
+ import type { DevTools } from './devtools.ts';
10
+ import type { AppWindow, Windows } from './windows.ts';
11
+ /** What every action reads beside its window. */
12
+ export interface ActionContext {
13
+ readonly devtools: DevTools;
14
+ readonly windows: Windows;
15
+ readonly projectRoot: string;
16
+ /** The attempt's directory for files the engine writes for the app to read, made on first use and removed with the attempt. */
17
+ uploads(): string;
18
+ }
19
+ type ActionOf<K extends LocatorAction['kind']> = Extract<LocatorAction, {
20
+ readonly kind: K;
21
+ }>;
22
+ /** Performs a locator action on a node of the shown window. */
23
+ export declare function performOnNode(context: ActionContext, window: AppWindow, backendNodeId: number, action: LocatorAction, budget: Budget): Promise<void>;
24
+ /** A pointer action at a viewport point of the shown window. */
25
+ export declare function performAtPoint(context: ActionContext, window: AppWindow, point: ViewportPoint, action: PointerAction, budget: Budget): Promise<void>;
26
+ /** A swipe on the window itself, from its centre. */
27
+ export declare function swipeWindow(context: ActionContext, window: AppWindow, action: ActionOf<'swipe'>, budget: Budget): Promise<void>;
28
+ /** Types into the focused element of the shown window, one character at a time: no key goes out once the caller stopped waiting. */
29
+ export declare function typeText(context: ActionContext, window: AppWindow, text: string, replace: boolean, budget: Budget): Promise<void>;
30
+ /** Types text into whatever holds focus, key by key, `delayMs` apart: each character's key, or the character inserted when the layout has none. */
31
+ export declare function typeKeys(window: AppWindow, text: string, delayMs: number, budget: Budget): Promise<void>;
32
+ /** Presses a key in the shown window, wherever focus is. */
33
+ export declare function pressKey(window: AppWindow, key: string, budget: Budget): Promise<void>;
34
+ /**
35
+ * Sends `input` with `modifiers` held. Each press passes the budget's check
36
+ * on its own: a modifier the app was slow to take is not followed by the key
37
+ * once the caller stopped waiting. Every modifier that went down comes up,
38
+ * whatever happens.
39
+ */
40
+ export declare function withModifiers(budget: Budget, window: AppWindow, modifiers: readonly string[], input: () => Promise<void>): Promise<void>;
41
+ /**
42
+ * A key of the contract grammar as the keyboard presses it: the key and the
43
+ * modifiers held with it. The keyboard has the named keys and the characters
44
+ * of a US layout; any other character (`é`, `ß`) is
45
+ * `UNSUPPORTED_CAPABILITY`, as the contract asks of a key a surface cannot
46
+ * deliver.
47
+ */
48
+ export declare function keyChord(key: string): {
49
+ readonly key: string;
50
+ readonly modifiers: readonly string[];
51
+ };
52
+ export {};