@testspectra/matchers 1.0.69 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +48 -0
- package/dist/__tests__/intercept.test.d.ts +1 -0
- package/dist/__tests__/intercept.test.js +183 -0
- package/dist/__tests__/matchers.test.d.ts +1 -0
- package/dist/__tests__/matchers.test.js +161 -0
- package/dist/index.d.ts +3 -21
- package/dist/index.js +3 -21
- package/dist/intercept/cdp-handler.d.ts +22 -0
- package/dist/intercept/cdp-handler.js +123 -0
- package/dist/intercept/index.d.ts +4 -0
- package/dist/intercept/index.js +4 -0
- package/dist/intercept/mock-handle.d.ts +49 -0
- package/dist/intercept/mock-handle.js +124 -0
- package/dist/intercept/mock-registry.d.ts +18 -0
- package/dist/intercept/mock-registry.js +97 -0
- package/dist/intercept/types.d.ts +43 -0
- package/dist/intercept/types.js +1 -0
- package/dist/matchers.d.ts +5 -1
- package/dist/matchers.js +116 -29
- package/dist/proto.d.ts +18 -283
- package/dist/proto.js +1 -114
- package/dist/reporter.d.ts +30 -0
- package/dist/reporter.js +85 -0
- package/dist/runner/collection.d.ts +33 -20
- package/dist/runner/collection.js +78 -26
- package/dist/runner/single.d.ts +123 -32
- package/dist/runner/single.js +266 -48
- package/dist/spectra.d.ts +32 -8
- package/dist/spectra.js +157 -40
- package/dist/types.d.ts +1195 -28
- package/package.json +16 -12
- package/src/index.ts +3 -22
- package/src/proto.ts +22 -433
- package/src/types.ts +1403 -96
- package/tsconfig.json +2 -2
- package/src/matchers.ts +0 -146
- package/src/runner/collection.ts +0 -153
- package/src/runner/single.ts +0 -301
- package/src/spectra.ts +0 -376
package/src/spectra.ts
DELETED
|
@@ -1,376 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ClickOptions,
|
|
3
|
-
ElementTarget,
|
|
4
|
-
KeyOption,
|
|
5
|
-
LongPressOptions,
|
|
6
|
-
ScrollOptions,
|
|
7
|
-
SwipeOptions,
|
|
8
|
-
TypeOptions,
|
|
9
|
-
} from "./types.js";
|
|
10
|
-
import { SingleElementRunner } from "./runner/single.js";
|
|
11
|
-
import { MultiElementRunner } from "./runner/collection.js";
|
|
12
|
-
import { resolveElement } from "./matchers.js";
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Main TestSpectra cross-platform automation and assertion orchestrator.
|
|
16
|
-
*
|
|
17
|
-
* Provides a unified, ergonomic testing API across Web, Android, and iOS.
|
|
18
|
-
* Features single element targeting (`.get`), collection targeting (`.getAll`),
|
|
19
|
-
* and built-in actions (`.click`, `.type`, `.scroll`, `.swipe`, `.navigate`).
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```ts
|
|
23
|
-
* // Single element interaction
|
|
24
|
-
* await Spectra.get("#username").type("admin");
|
|
25
|
-
*
|
|
26
|
-
* // Collection assertion
|
|
27
|
-
* await Spectra.getAll(".item").should("have.length", 5);
|
|
28
|
-
*
|
|
29
|
-
* // Mobile touch swipe
|
|
30
|
-
* await Spectra.swipe({ direction: "left", distance: 350 });
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
export class SpectraStatic {
|
|
34
|
-
/**
|
|
35
|
-
* Targets a single element by CSS/XPath selector or Page Object element.
|
|
36
|
-
*
|
|
37
|
-
* @param target - Selector string or Page Object element property.
|
|
38
|
-
* @example
|
|
39
|
-
* ```ts
|
|
40
|
-
* await Spectra.get("#login-btn").click();
|
|
41
|
-
* await Spectra.get(LoginPage.submitButton).should("be.visible");
|
|
42
|
-
* ```
|
|
43
|
-
* @returns `SingleElementRunner` for chaining actions and assertions.
|
|
44
|
-
*/
|
|
45
|
-
get(target: ElementTarget): SingleElementRunner {
|
|
46
|
-
return new SingleElementRunner(target);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Targets multiple elements or collections matching a CSS/XPath selector.
|
|
51
|
-
*
|
|
52
|
-
* @param selector - Selector string matching multiple elements.
|
|
53
|
-
* @example
|
|
54
|
-
* ```ts
|
|
55
|
-
* await Spectra.getAll(".product-card").should("have.length.greaterThan", 0);
|
|
56
|
-
* await Spectra.getAll("li.tab").first().click();
|
|
57
|
-
* ```
|
|
58
|
-
* @returns `MultiElementRunner` for collection assertions and indexing.
|
|
59
|
-
*/
|
|
60
|
-
getAll(selector: string): MultiElementRunner {
|
|
61
|
-
return new MultiElementRunner(selector);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// --- Browser & Navigation Actions ---
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Navigates the browser to the specified URL.
|
|
68
|
-
*
|
|
69
|
-
* @param url - Relative URL or absolute URL.
|
|
70
|
-
* @example
|
|
71
|
-
* ```ts
|
|
72
|
-
* await Spectra.navigate("/login");
|
|
73
|
-
* await Spectra.navigate("https://app.testspectra.dev/dashboard");
|
|
74
|
-
* ```
|
|
75
|
-
*/
|
|
76
|
-
navigate(url: string): SingleElementRunner {
|
|
77
|
-
return new SingleElementRunner(undefined, async () => {
|
|
78
|
-
await browser.url(url);
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Navigates back one step in the browser / app history.
|
|
84
|
-
*
|
|
85
|
-
* @example
|
|
86
|
-
* ```ts
|
|
87
|
-
* await Spectra.back();
|
|
88
|
-
* ```
|
|
89
|
-
*/
|
|
90
|
-
back(): SingleElementRunner {
|
|
91
|
-
return new SingleElementRunner(undefined, async () => {
|
|
92
|
-
await browser.back();
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Refreshes the current browser page.
|
|
98
|
-
*
|
|
99
|
-
* @example
|
|
100
|
-
* ```ts
|
|
101
|
-
* await Spectra.refresh();
|
|
102
|
-
* ```
|
|
103
|
-
*/
|
|
104
|
-
refresh(): SingleElementRunner {
|
|
105
|
-
return new SingleElementRunner(undefined, async () => {
|
|
106
|
-
await browser.refresh();
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// --- Direct Interaction Actions ---
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Clicks on the specified element.
|
|
114
|
-
*
|
|
115
|
-
* @param target - Selector string or Page Object element property.
|
|
116
|
-
* @param textOrOptions - Optional text filter or click configuration.
|
|
117
|
-
* @example
|
|
118
|
-
* ```ts
|
|
119
|
-
* await Spectra.click("#submit-button");
|
|
120
|
-
* await Spectra.click(LoginPage.loginBtn);
|
|
121
|
-
* ```
|
|
122
|
-
*/
|
|
123
|
-
click(target: ElementTarget, textOrOptions?: string | ClickOptions): SingleElementRunner {
|
|
124
|
-
return new SingleElementRunner(target, async () => {
|
|
125
|
-
const el = await resolveElement(target);
|
|
126
|
-
await el.click();
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Performs a double-click on the specified element.
|
|
132
|
-
*
|
|
133
|
-
* @param target - Selector string or Page Object element property.
|
|
134
|
-
* @param textOrOptions - Optional text filter or click configuration.
|
|
135
|
-
* @example
|
|
136
|
-
* ```ts
|
|
137
|
-
* await Spectra.doubleClick(".grid-row");
|
|
138
|
-
* ```
|
|
139
|
-
*/
|
|
140
|
-
doubleClick(target: ElementTarget, textOrOptions?: string | ClickOptions): SingleElementRunner {
|
|
141
|
-
return new SingleElementRunner(target, async () => {
|
|
142
|
-
const el = await resolveElement(target);
|
|
143
|
-
await el.doubleClick();
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Performs a long-press touch or hold gesture on the specified element.
|
|
149
|
-
*
|
|
150
|
-
* @param target - Selector string or Page Object element property.
|
|
151
|
-
* @param options - Optional duration in ms or LongPressOptions object.
|
|
152
|
-
* @example
|
|
153
|
-
* ```ts
|
|
154
|
-
* await Spectra.longPress("#message-item", 1500);
|
|
155
|
-
* await Spectra.longPress(ChatPage.audioRecordBtn, { duration: 2000 });
|
|
156
|
-
* ```
|
|
157
|
-
*/
|
|
158
|
-
longPress(target: ElementTarget, options?: LongPressOptions | number): SingleElementRunner {
|
|
159
|
-
const duration = typeof options === "number" ? options : options?.duration || 1000;
|
|
160
|
-
return new SingleElementRunner(target, async () => {
|
|
161
|
-
const el = await resolveElement(target);
|
|
162
|
-
if (typeof (el as any).touchAction === "function") {
|
|
163
|
-
await (el as any).touchAction([
|
|
164
|
-
{ action: "longPress", ms: duration },
|
|
165
|
-
{ action: "release" },
|
|
166
|
-
]);
|
|
167
|
-
} else {
|
|
168
|
-
await el.click();
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Types text into the specified element.
|
|
175
|
-
*
|
|
176
|
-
* @param target - Selector string or Page Object element property.
|
|
177
|
-
* @param value - Text string to enter.
|
|
178
|
-
* @param options - Optional typing options (e.g. `clearFirst: true`).
|
|
179
|
-
* @example
|
|
180
|
-
* ```ts
|
|
181
|
-
* await Spectra.type("#email", "user@example.com", { clearFirst: true });
|
|
182
|
-
* await Spectra.type(LoginPage.passwordInput, "SecretPass123");
|
|
183
|
-
* ```
|
|
184
|
-
*/
|
|
185
|
-
type(target: ElementTarget, value: string, options?: TypeOptions): SingleElementRunner {
|
|
186
|
-
return new SingleElementRunner(target, async () => {
|
|
187
|
-
const el = await resolveElement(target);
|
|
188
|
-
if (options?.clearFirst) {
|
|
189
|
-
await el.clearValue();
|
|
190
|
-
}
|
|
191
|
-
await el.setValue(value);
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Clears the input content from the specified element.
|
|
197
|
-
*
|
|
198
|
-
* @param target - Selector string or Page Object element property.
|
|
199
|
-
* @example
|
|
200
|
-
* ```ts
|
|
201
|
-
* await Spectra.clear("#coupon-input");
|
|
202
|
-
* ```
|
|
203
|
-
*/
|
|
204
|
-
clear(target: ElementTarget): SingleElementRunner {
|
|
205
|
-
return new SingleElementRunner(target, async () => {
|
|
206
|
-
const el = await resolveElement(target);
|
|
207
|
-
await el.clearValue();
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Selects an option from a `<select>` dropdown by its visible text.
|
|
213
|
-
*
|
|
214
|
-
* @param target - Selector string or Page Object element property.
|
|
215
|
-
* @param value - Visible text of the option to select.
|
|
216
|
-
* @example
|
|
217
|
-
* ```ts
|
|
218
|
-
* await Spectra.select("#shipping-country", "Indonesia");
|
|
219
|
-
* ```
|
|
220
|
-
*/
|
|
221
|
-
select(target: ElementTarget, value: string): SingleElementRunner {
|
|
222
|
-
return new SingleElementRunner(target, async () => {
|
|
223
|
-
const el = await resolveElement(target);
|
|
224
|
-
await el.selectByVisibleText(value);
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* Hovers the mouse pointer over the specified element.
|
|
230
|
-
*
|
|
231
|
-
* @param target - Selector string or Page Object element property.
|
|
232
|
-
* @example
|
|
233
|
-
* ```ts
|
|
234
|
-
* await Spectra.hover("#nav-profile-menu");
|
|
235
|
-
* ```
|
|
236
|
-
*/
|
|
237
|
-
hover(target: ElementTarget): SingleElementRunner {
|
|
238
|
-
return new SingleElementRunner(target, async () => {
|
|
239
|
-
const el = await resolveElement(target);
|
|
240
|
-
await el.moveTo();
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Simulates pressing a specific keyboard key.
|
|
246
|
-
*
|
|
247
|
-
* @param key - Key name string (e.g. `'Enter'`, `'Tab'`, `'Escape'`).
|
|
248
|
-
* @example
|
|
249
|
-
* ```ts
|
|
250
|
-
* await Spectra.pressKey("Enter");
|
|
251
|
-
* await Spectra.pressKey("Escape");
|
|
252
|
-
* ```
|
|
253
|
-
*/
|
|
254
|
-
pressKey(key: KeyOption | string): SingleElementRunner {
|
|
255
|
-
return new SingleElementRunner(undefined, async () => {
|
|
256
|
-
await browser.keys(key);
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* Drags a source element and drops it onto a destination target.
|
|
262
|
-
*
|
|
263
|
-
* @param sourceTarget - Element to drag.
|
|
264
|
-
* @param destTarget - Destination element or drop zone.
|
|
265
|
-
* @example
|
|
266
|
-
* ```ts
|
|
267
|
-
* await Spectra.dragDrop("#task-item-1", "#column-done");
|
|
268
|
-
* ```
|
|
269
|
-
*/
|
|
270
|
-
dragDrop(sourceTarget: ElementTarget, destTarget: ElementTarget): SingleElementRunner {
|
|
271
|
-
return new SingleElementRunner(sourceTarget, async () => {
|
|
272
|
-
const source = await resolveElement(sourceTarget);
|
|
273
|
-
const target = await resolveElement(destTarget);
|
|
274
|
-
await source.dragAndDrop(target);
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
// --- Gesture Actions ---
|
|
279
|
-
|
|
280
|
-
/**
|
|
281
|
-
* Scrolls the page or scrolls a specific element into view.
|
|
282
|
-
*
|
|
283
|
-
* @param options - Direction, pixels, or selector to scroll.
|
|
284
|
-
* @example
|
|
285
|
-
* ```ts
|
|
286
|
-
* await Spectra.scroll({ direction: "down", pixels: 400 });
|
|
287
|
-
* await Spectra.scroll({ selector: "#footer" });
|
|
288
|
-
* ```
|
|
289
|
-
*/
|
|
290
|
-
scroll(options?: ScrollOptions): SingleElementRunner {
|
|
291
|
-
return new SingleElementRunner(options?.selector, async () => {
|
|
292
|
-
if (options?.selector) {
|
|
293
|
-
const el = await resolveElement(options.selector);
|
|
294
|
-
await el.scrollIntoView();
|
|
295
|
-
} else {
|
|
296
|
-
await browser.execute((direction, pixels) => {
|
|
297
|
-
const delta = pixels || 500;
|
|
298
|
-
window.scrollBy({
|
|
299
|
-
top: direction === "up" ? -delta : direction === "down" ? delta : 0,
|
|
300
|
-
left: direction === "left" ? -delta : direction === "right" ? delta : 0,
|
|
301
|
-
behavior: "smooth",
|
|
302
|
-
});
|
|
303
|
-
}, options?.direction || "down", options?.pixels || 500);
|
|
304
|
-
}
|
|
305
|
-
});
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
/**
|
|
309
|
-
* Performs a touch swipe gesture in the given direction (for mobile and touch-enabled browsers).
|
|
310
|
-
*
|
|
311
|
-
* @param options - Swipe configuration with `direction` and optional `distance`.
|
|
312
|
-
* @example
|
|
313
|
-
* ```ts
|
|
314
|
-
* await Spectra.swipe({ direction: "left", distance: 300 });
|
|
315
|
-
* ```
|
|
316
|
-
*/
|
|
317
|
-
swipe(options: SwipeOptions): SingleElementRunner {
|
|
318
|
-
return new SingleElementRunner(options.selector, async () => {
|
|
319
|
-
if (typeof (browser as any).touchAction === "function") {
|
|
320
|
-
const distance = options.distance || 300;
|
|
321
|
-
await (browser as any).touchAction([
|
|
322
|
-
{ action: "press", x: 200, y: 500 },
|
|
323
|
-
{
|
|
324
|
-
action: "moveTo",
|
|
325
|
-
x: options.direction === "right" ? 200 + distance : options.direction === "left" ? 200 - distance : 200,
|
|
326
|
-
y: options.direction === "down" ? 500 + distance : options.direction === "up" ? 500 - distance : 500,
|
|
327
|
-
},
|
|
328
|
-
{ action: "release" },
|
|
329
|
-
]);
|
|
330
|
-
} else {
|
|
331
|
-
// Fallback to web scroll
|
|
332
|
-
await this.scroll({ direction: options.direction, pixels: options.distance });
|
|
333
|
-
}
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
// --- Timing Actions ---
|
|
338
|
-
|
|
339
|
-
/**
|
|
340
|
-
* Pauses test execution for a specified duration in milliseconds.
|
|
341
|
-
*
|
|
342
|
-
* @param durationMs - Time to wait in milliseconds.
|
|
343
|
-
* @example
|
|
344
|
-
* ```ts
|
|
345
|
-
* await Spectra.wait(1000);
|
|
346
|
-
* ```
|
|
347
|
-
*/
|
|
348
|
-
wait(durationMs: number): SingleElementRunner {
|
|
349
|
-
return new SingleElementRunner(undefined, async () => {
|
|
350
|
-
await browser.pause(durationMs);
|
|
351
|
-
});
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
/**
|
|
355
|
-
* Waits until the specified element is displayed on the screen.
|
|
356
|
-
*
|
|
357
|
-
* @param target - Selector string or Page Object element property.
|
|
358
|
-
* @param timeoutMs - Maximum time in milliseconds to wait (default: 10000).
|
|
359
|
-
* @example
|
|
360
|
-
* ```ts
|
|
361
|
-
* await Spectra.waitForElement("#confirmation-dialog", 5000);
|
|
362
|
-
* ```
|
|
363
|
-
*/
|
|
364
|
-
waitForElement(target: ElementTarget, timeoutMs = 10000): SingleElementRunner {
|
|
365
|
-
return new SingleElementRunner(target, async () => {
|
|
366
|
-
const el = await resolveElement(target);
|
|
367
|
-
await el.waitForDisplayed({ timeout: timeoutMs });
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
/**
|
|
373
|
-
* Global singleton instance of `SpectraStatic`.
|
|
374
|
-
*/
|
|
375
|
-
export const Spectra = new SpectraStatic();
|
|
376
|
-
|