@testspectra/matchers 1.1.8-rc.2 → 1.1.8-rc.21

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.
@@ -1,178 +1,178 @@
1
- /**
2
- * Element action methods for `SingleElementProxy`.
3
- *
4
- * Each action delegates to the bound `PlatformDriverBridge` and wraps the invocation in a
5
- * semantic `trackStep('action')` log entry. There is zero platform branching here — every
6
- * platform-specific behavior lives inside the active driver.
7
- */
8
-
9
- import type {
10
- ClickOptions,
11
- ElementTarget,
12
- LongPressOptions,
13
- ScopedSelector,
14
- TypeOptions,
15
- } from '@testspectra/matchers';
16
-
17
- export function createElementActions(
18
- selector: string | ScopedSelector,
19
- index: number | null,
20
- ): Record<string, any> {
21
- const driver = () => globalThis.__TS_RUNTIME__.activeDriver!;
22
-
23
- async function click(_options?: ClickOptions): Promise<void> {
24
- return globalThis.__TS_RUNTIME__.trackStep(
25
- 'action',
26
- { type: 'action', key: 'click', target: selector, args: [] },
27
- async () => {
28
- await driver().click(selector, index);
29
- },
30
- );
31
- }
32
-
33
- async function doubleClick(): Promise<void> {
34
- return globalThis.__TS_RUNTIME__.trackStep(
35
- 'action',
36
- { type: 'action', key: 'doubleClick', target: selector, args: [] },
37
- async () => {
38
- await driver().doubleClick(selector, index);
39
- },
40
- );
41
- }
42
-
43
- async function rightClick(): Promise<void> {
44
- return globalThis.__TS_RUNTIME__.trackStep(
45
- 'action',
46
- { type: 'action', key: 'rightClick', target: selector, args: [] },
47
- async () => {
48
- await driver().rightClick(selector, index);
49
- },
50
- );
51
- }
52
-
53
- async function setValue(value: unknown): Promise<void> {
54
- return globalThis.__TS_RUNTIME__.trackStep(
55
- 'action',
56
- { type: 'action', key: 'type', target: selector, args: [value] },
57
- async () => {
58
- await driver().setValue(selector, value, index);
59
- },
60
- );
61
- }
62
-
63
- async function type(value: unknown, options?: TypeOptions): Promise<void> {
64
- if (options?.clearFirst) {
65
- await clearValue();
66
- }
67
- await setValue(value);
68
- }
69
-
70
- async function clearValue(): Promise<void> {
71
- return globalThis.__TS_RUNTIME__.trackStep(
72
- 'action',
73
- { type: 'action', key: 'clear', target: selector, args: [] },
74
- async () => {
75
- await driver().clearValue(selector, index);
76
- },
77
- );
78
- }
79
-
80
- async function clear(): Promise<void> {
81
- await clearValue();
82
- }
83
-
84
- async function select(option: string): Promise<void> {
85
- return globalThis.__TS_RUNTIME__.trackStep(
86
- 'action',
87
- { type: 'action', key: 'select', target: selector, args: [option] },
88
- async () => {
89
- await driver().select(selector, option, index);
90
- },
91
- );
92
- }
93
-
94
- async function selectByVisibleText(text: string): Promise<void> {
95
- await select(text);
96
- }
97
-
98
- async function hover(): Promise<void> {
99
- return globalThis.__TS_RUNTIME__.trackStep(
100
- 'action',
101
- { type: 'action', key: 'hover', target: selector, args: [] },
102
- async () => {
103
- await driver().hover(selector, index);
104
- },
105
- );
106
- }
107
-
108
- async function focus(): Promise<void> {
109
- return globalThis.__TS_RUNTIME__.trackStep(
110
- 'action',
111
- { type: 'action', key: 'focus', target: selector, args: [] },
112
- async () => {
113
- await driver().focus(selector, index);
114
- },
115
- );
116
- }
117
-
118
- async function moveTo(): Promise<void> {
119
- await hover();
120
- }
121
-
122
- async function dragDrop(target: ElementTarget): Promise<void> {
123
- const destSelector = typeof target === 'string' ? target : (target as any)?.selector || String(target);
124
- return globalThis.__TS_RUNTIME__.trackStep(
125
- 'action',
126
- { type: 'action', key: 'dragDrop', target: selector, args: [destSelector] },
127
- async () => {
128
- await driver().dragDrop(selector, destSelector, index);
129
- },
130
- );
131
- }
132
-
133
- async function dragAndDrop(target: ElementTarget): Promise<void> {
134
- await dragDrop(target);
135
- }
136
-
137
- async function longPress(options?: number | LongPressOptions): Promise<void> {
138
- const duration = typeof options === 'number' ? options : options?.duration || 1000;
139
- return globalThis.__TS_RUNTIME__.trackStep(
140
- 'action',
141
- { type: 'action', key: 'longPress', target: selector, args: [duration] },
142
- async () => {
143
- await driver().longPress(selector, duration, index);
144
- },
145
- );
146
- }
147
-
148
- async function scrollIntoView(): Promise<void> {
149
- return globalThis.__TS_RUNTIME__.trackStep(
150
- 'action',
151
- { type: 'action', key: 'scrollIntoView', target: selector, args: [] },
152
- async () => {
153
- await driver().scrollIntoView(selector, index);
154
- },
155
- );
156
- }
157
-
158
- return {
159
- click,
160
- doubleClick,
161
- rightClick,
162
- setValue,
163
- type,
164
- clearValue,
165
- clear,
166
- select,
167
- selectByVisibleText,
168
- hover,
169
- focus,
170
- moveTo,
171
- dragDrop,
172
- dragAndDrop,
173
- longPress,
174
- scrollIntoView,
175
- };
176
- }
177
-
178
- globalThis.__TS_RUNTIME__.createElementActions = createElementActions;
1
+ /**
2
+ * Element action methods for `SingleElementProxy`.
3
+ *
4
+ * Each action delegates to the bound `PlatformDriverBridge` and wraps the invocation in a
5
+ * semantic `trackStep('action')` log entry. There is zero platform branching here — every
6
+ * platform-specific behavior lives inside the active driver.
7
+ */
8
+
9
+ import type {
10
+ ClickOptions,
11
+ ElementTarget,
12
+ LongPressOptions,
13
+ ScopedSelector,
14
+ TypeOptions,
15
+ } from '@testspectra/matchers';
16
+
17
+ export function createElementActions(
18
+ selector: string | ScopedSelector,
19
+ index: number | null,
20
+ ): Record<string, any> {
21
+ const driver = () => globalThis.__TS_RUNTIME__.activeDriver!;
22
+
23
+ async function click(_options?: ClickOptions): Promise<void> {
24
+ return globalThis.__TS_RUNTIME__.trackStep(
25
+ 'action',
26
+ { type: 'action', key: 'click', target: selector, args: [] },
27
+ async () => {
28
+ await driver().click(selector, index);
29
+ },
30
+ );
31
+ }
32
+
33
+ async function doubleClick(): Promise<void> {
34
+ return globalThis.__TS_RUNTIME__.trackStep(
35
+ 'action',
36
+ { type: 'action', key: 'doubleClick', target: selector, args: [] },
37
+ async () => {
38
+ await driver().doubleClick(selector, index);
39
+ },
40
+ );
41
+ }
42
+
43
+ async function rightClick(): Promise<void> {
44
+ return globalThis.__TS_RUNTIME__.trackStep(
45
+ 'action',
46
+ { type: 'action', key: 'rightClick', target: selector, args: [] },
47
+ async () => {
48
+ await driver().rightClick(selector, index);
49
+ },
50
+ );
51
+ }
52
+
53
+ async function setValue(value: unknown): Promise<void> {
54
+ return globalThis.__TS_RUNTIME__.trackStep(
55
+ 'action',
56
+ { type: 'action', key: 'type', target: selector, args: [value] },
57
+ async () => {
58
+ await driver().setValue(selector, value, index);
59
+ },
60
+ );
61
+ }
62
+
63
+ async function type(value: unknown, options?: TypeOptions): Promise<void> {
64
+ if (options?.clearFirst) {
65
+ await clearValue();
66
+ }
67
+ await setValue(value);
68
+ }
69
+
70
+ async function clearValue(): Promise<void> {
71
+ return globalThis.__TS_RUNTIME__.trackStep(
72
+ 'action',
73
+ { type: 'action', key: 'clear', target: selector, args: [] },
74
+ async () => {
75
+ await driver().clearValue(selector, index);
76
+ },
77
+ );
78
+ }
79
+
80
+ async function clear(): Promise<void> {
81
+ await clearValue();
82
+ }
83
+
84
+ async function select(option: string): Promise<void> {
85
+ return globalThis.__TS_RUNTIME__.trackStep(
86
+ 'action',
87
+ { type: 'action', key: 'select', target: selector, args: [option] },
88
+ async () => {
89
+ await driver().select(selector, option, index);
90
+ },
91
+ );
92
+ }
93
+
94
+ async function selectByVisibleText(text: string): Promise<void> {
95
+ await select(text);
96
+ }
97
+
98
+ async function hover(): Promise<void> {
99
+ return globalThis.__TS_RUNTIME__.trackStep(
100
+ 'action',
101
+ { type: 'action', key: 'hover', target: selector, args: [] },
102
+ async () => {
103
+ await driver().hover(selector, index);
104
+ },
105
+ );
106
+ }
107
+
108
+ async function focus(): Promise<void> {
109
+ return globalThis.__TS_RUNTIME__.trackStep(
110
+ 'action',
111
+ { type: 'action', key: 'focus', target: selector, args: [] },
112
+ async () => {
113
+ await driver().focus(selector, index);
114
+ },
115
+ );
116
+ }
117
+
118
+ async function moveTo(): Promise<void> {
119
+ await hover();
120
+ }
121
+
122
+ async function dragDrop(target: ElementTarget): Promise<void> {
123
+ const destSelector = typeof target === 'string' ? target : (target as any)?.selector || String(target);
124
+ return globalThis.__TS_RUNTIME__.trackStep(
125
+ 'action',
126
+ { type: 'action', key: 'dragDrop', target: selector, args: [destSelector] },
127
+ async () => {
128
+ await driver().dragDrop(selector, destSelector, index);
129
+ },
130
+ );
131
+ }
132
+
133
+ async function dragAndDrop(target: ElementTarget): Promise<void> {
134
+ await dragDrop(target);
135
+ }
136
+
137
+ async function longPress(options?: number | LongPressOptions): Promise<void> {
138
+ const duration = typeof options === 'number' ? options : options?.duration || 1000;
139
+ return globalThis.__TS_RUNTIME__.trackStep(
140
+ 'action',
141
+ { type: 'action', key: 'longPress', target: selector, args: [duration] },
142
+ async () => {
143
+ await driver().longPress(selector, duration, index);
144
+ },
145
+ );
146
+ }
147
+
148
+ async function scrollIntoView(): Promise<void> {
149
+ return globalThis.__TS_RUNTIME__.trackStep(
150
+ 'action',
151
+ { type: 'action', key: 'scrollIntoView', target: selector, args: [] },
152
+ async () => {
153
+ await driver().scrollIntoView(selector, index);
154
+ },
155
+ );
156
+ }
157
+
158
+ return {
159
+ click,
160
+ doubleClick,
161
+ rightClick,
162
+ setValue,
163
+ type,
164
+ clearValue,
165
+ clear,
166
+ select,
167
+ selectByVisibleText,
168
+ hover,
169
+ focus,
170
+ moveTo,
171
+ dragDrop,
172
+ dragAndDrop,
173
+ longPress,
174
+ scrollIntoView,
175
+ };
176
+ }
177
+
178
+ globalThis.__TS_RUNTIME__.createElementActions = createElementActions;