@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/package.json
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@testspectra/matchers",
|
|
3
|
-
"version": "1.0
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Canonical TypeScript contracts and ambient type definitions for TestSpectra",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
11
13
|
},
|
|
12
14
|
"devDependencies": {
|
|
13
15
|
"@types/node": "^20.14.0",
|
|
14
|
-
"
|
|
15
|
-
"@wdio/mocha-framework": "^9.2.8",
|
|
16
|
-
"webdriverio": "^9.2.8",
|
|
17
|
-
"typescript": "^5.4.5"
|
|
16
|
+
"typescript": "^5.6.3"
|
|
18
17
|
},
|
|
19
18
|
"type": "module",
|
|
20
|
-
"license": "
|
|
21
|
-
|
|
19
|
+
"license": "SEE LICENSE IN LICENSE.md",
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc",
|
|
22
|
+
"watch": "tsc -w",
|
|
23
|
+
"typecheck": "tsc --noEmit"
|
|
24
|
+
}
|
|
25
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -2,27 +2,8 @@
|
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
* # @testspectra/matchers
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* ## Features:
|
|
8
|
-
* - **`Spectra`**: Unified automation API (`Spectra.get()`, `Spectra.getAll()`, `Spectra.click()`, `Spectra.type()`, etc.)
|
|
9
|
-
* - **`SingleElementRunner`**: Fluent interaction & assertion runner for single element targets
|
|
10
|
-
* - **`MultiElementRunner`**: Fluent assertion & traversal runner for multi-element collections
|
|
11
|
-
* - **Callable Matchers**: Ambient prototypes for WebdriverIO Element & Browser (`.shouldBeVisible()`, `.shouldHaveText()`, etc.)
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```ts
|
|
15
|
-
* import { Spectra } from "@testspectra/matchers";
|
|
16
|
-
*
|
|
17
|
-
* await Spectra.get("#login-btn").click().should("not.be.visible");
|
|
18
|
-
* await Spectra.getAll(".list-item").should("have.length.greaterThan", 0);
|
|
19
|
-
* ```
|
|
5
|
+
* Canonical TypeScript contracts, action/assertion types, and ambient type definitions for TestSpectra.
|
|
20
6
|
*/
|
|
21
7
|
|
|
22
|
-
export * from
|
|
23
|
-
export * from
|
|
24
|
-
export * from "./runner/single.js";
|
|
25
|
-
export * from "./runner/collection.js";
|
|
26
|
-
export * from "./spectra.js";
|
|
27
|
-
export * from "./proto.js";
|
|
28
|
-
|
|
8
|
+
export * from './types.js';
|
|
9
|
+
export * from './proto.js';
|
package/src/proto.ts
CHANGED
|
@@ -1,438 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { resolveElement } from "./matchers.js";
|
|
1
|
+
import type { SpectraBrowserBridge, SpectraStatic } from './types.js';
|
|
3
2
|
|
|
4
3
|
declare global {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
* ```
|
|
25
|
-
* @returns The element instance for chaining.
|
|
26
|
-
*/
|
|
27
|
-
shouldNotBeVisible(): Promise<Element>;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Asserts that the element exists in the DOM/UI hierarchy.
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```ts
|
|
34
|
-
* await LoginPage.rememberMeCheckbox.shouldExist();
|
|
35
|
-
* ```
|
|
36
|
-
* @returns The element instance for chaining.
|
|
37
|
-
*/
|
|
38
|
-
shouldExist(): Promise<Element>;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Asserts that the element does NOT exist in the DOM/UI hierarchy.
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* ```ts
|
|
45
|
-
* await LoginPage.loadingSpinner.shouldNotExist();
|
|
46
|
-
* ```
|
|
47
|
-
* @returns The element instance for chaining.
|
|
48
|
-
*/
|
|
49
|
-
shouldNotExist(): Promise<Element>;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Asserts that the element is enabled for interaction.
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* ```ts
|
|
56
|
-
* await LoginPage.loginButton.shouldBeEnabled();
|
|
57
|
-
* ```
|
|
58
|
-
* @returns The element instance for chaining.
|
|
59
|
-
*/
|
|
60
|
-
shouldBeEnabled(): Promise<Element>;
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Asserts that the element is disabled (cannot be interacted with).
|
|
64
|
-
*
|
|
65
|
-
* @example
|
|
66
|
-
* ```ts
|
|
67
|
-
* await LoginPage.disabledSubmit.shouldBeDisabled();
|
|
68
|
-
* ```
|
|
69
|
-
* @returns The element instance for chaining.
|
|
70
|
-
*/
|
|
71
|
-
shouldBeDisabled(): Promise<Element>;
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Asserts that the form element (radio button, checkbox, option) is selected.
|
|
75
|
-
*
|
|
76
|
-
* @example
|
|
77
|
-
* ```ts
|
|
78
|
-
* await SettingsPage.darkModeRadio.shouldBeSelected();
|
|
79
|
-
* ```
|
|
80
|
-
* @returns The element instance for chaining.
|
|
81
|
-
*/
|
|
82
|
-
shouldBeSelected(): Promise<Element>;
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Asserts that the checkbox or radio element is checked.
|
|
86
|
-
*
|
|
87
|
-
* @example
|
|
88
|
-
* ```ts
|
|
89
|
-
* await SettingsPage.termsCheckbox.shouldBeChecked();
|
|
90
|
-
* ```
|
|
91
|
-
* @returns The element instance for chaining.
|
|
92
|
-
*/
|
|
93
|
-
shouldBeChecked(): Promise<Element>;
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Asserts that the input element has the exact given value.
|
|
97
|
-
*
|
|
98
|
-
* @param expectedValue - The exact expected value.
|
|
99
|
-
* @example
|
|
100
|
-
* ```ts
|
|
101
|
-
* await LoginPage.usernameInput.shouldHaveValue("admin@test.com");
|
|
102
|
-
* ```
|
|
103
|
-
* @returns The element instance for chaining.
|
|
104
|
-
*/
|
|
105
|
-
shouldHaveValue(expectedValue: string): Promise<Element>;
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Asserts that the input element's value contains the given substring.
|
|
109
|
-
*
|
|
110
|
-
* @param expectedValue - Substring expected to be present in the value.
|
|
111
|
-
* @example
|
|
112
|
-
* ```ts
|
|
113
|
-
* await LoginPage.tokenInput.shouldContainValue("JWT_");
|
|
114
|
-
* ```
|
|
115
|
-
* @returns The element instance for chaining.
|
|
116
|
-
*/
|
|
117
|
-
shouldContainValue(expectedValue: string): Promise<Element>;
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Asserts that the element's text content matches the exact expected text.
|
|
121
|
-
*
|
|
122
|
-
* @param expectedText - The exact expected text content.
|
|
123
|
-
* @example
|
|
124
|
-
* ```ts
|
|
125
|
-
* await LoginPage.headerTitle.shouldHaveText("Welcome to TestSpectra");
|
|
126
|
-
* ```
|
|
127
|
-
* @returns The element instance for chaining.
|
|
128
|
-
*/
|
|
129
|
-
shouldHaveText(expectedText: string): Promise<Element>;
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Asserts that the element's text content contains the expected substring.
|
|
133
|
-
*
|
|
134
|
-
* @param expectedText - Substring expected to be within the element text.
|
|
135
|
-
* @example
|
|
136
|
-
* ```ts
|
|
137
|
-
* await LoginPage.welcomeBanner.shouldContainText("Welcome");
|
|
138
|
-
* ```
|
|
139
|
-
* @returns The element instance for chaining.
|
|
140
|
-
*/
|
|
141
|
-
shouldContainText(expectedText: string): Promise<Element>;
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Asserts that the element has the specified CSS class.
|
|
145
|
-
*
|
|
146
|
-
* @param className - Expected CSS class name.
|
|
147
|
-
* @example
|
|
148
|
-
* ```ts
|
|
149
|
-
* await NavigationBar.homeTab.shouldHaveClass("is-active");
|
|
150
|
-
* ```
|
|
151
|
-
* @returns The element instance for chaining.
|
|
152
|
-
*/
|
|
153
|
-
shouldHaveClass(className: string): Promise<Element>;
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Asserts that the element has the specified attribute, optionally checking its exact value.
|
|
157
|
-
*
|
|
158
|
-
* @param attributeName - Name of the attribute (e.g. `aria-label`, `disabled`, `href`).
|
|
159
|
-
* @param expectedValue - Optional expected value of the attribute.
|
|
160
|
-
* @example
|
|
161
|
-
* ```ts
|
|
162
|
-
* await NavigationBar.logoLink.shouldHaveAttribute("href", "/dashboard");
|
|
163
|
-
* await NavigationBar.cartButton.shouldHaveAttribute("aria-expanded");
|
|
164
|
-
* ```
|
|
165
|
-
* @returns The element instance for chaining.
|
|
166
|
-
*/
|
|
167
|
-
shouldHaveAttribute(attributeName: string, expectedValue?: string): Promise<Element>;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Optional settings for HTTP network interception responses.
|
|
172
|
-
*/
|
|
173
|
-
export interface InterceptFixtureOptions {
|
|
174
|
-
/** HTTP status code to return in the mocked response (default: 200) */
|
|
175
|
-
statusCode?: number;
|
|
176
|
-
/** Custom HTTP response headers */
|
|
177
|
-
headers?: Record<string, string>;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Structured mock payload object with optional status code and headers.
|
|
182
|
-
*/
|
|
183
|
-
export interface InterceptFixtureObject<TData = unknown> {
|
|
184
|
-
/** HTTP status code */
|
|
185
|
-
statusCode?: number;
|
|
186
|
-
/** Response body payload */
|
|
187
|
-
body: TData;
|
|
188
|
-
/** Custom HTTP response headers */
|
|
189
|
-
headers?: Record<string, string>;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Input payload for API mocking: JSON object, string, or structured fixture object.
|
|
194
|
-
*/
|
|
195
|
-
export type InterceptInput<TData = unknown> =
|
|
196
|
-
| InterceptFixtureObject<TData>
|
|
197
|
-
| TData
|
|
198
|
-
| string;
|
|
4
|
+
/**
|
|
5
|
+
* The global TestSpectra static automation and assertion instance.
|
|
6
|
+
*/
|
|
7
|
+
var Spectra: SpectraStatic;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The global TestSpectra browser bridge instance.
|
|
11
|
+
*/
|
|
12
|
+
var browser: SpectraBrowserBridge;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Global fixture store injected by TestSpectra runner.
|
|
16
|
+
*/
|
|
17
|
+
var Fixture: Record<string, any>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Global step library injected by TestSpectra runner.
|
|
21
|
+
*/
|
|
22
|
+
var Step: Record<string, any>;
|
|
199
23
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
* Dynamically set or change the fixture response for this mock instance.
|
|
203
|
-
* Supports fixture file paths, structured `{ statusCode, body, headers }` objects, or raw data.
|
|
204
|
-
*
|
|
205
|
-
* @param fixture - Data payload or Fixture reference.
|
|
206
|
-
* @param options - Optional status code and header overrides.
|
|
207
|
-
* @example
|
|
208
|
-
* ```ts
|
|
209
|
-
* const mock = await browser.intercept("/api/user", "GET");
|
|
210
|
-
* await mock.respondWith({ name: "Admin", role: "superadmin" });
|
|
211
|
-
* ```
|
|
212
|
-
*/
|
|
213
|
-
respondWith<TData = unknown>(
|
|
214
|
-
fixture: InterceptInput<TData>,
|
|
215
|
-
options?: InterceptFixtureOptions
|
|
216
|
-
): Promise<void>;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
interface Browser {
|
|
220
|
-
/**
|
|
221
|
-
* Intercepts and mocks network API requests matching the specified endpoint.
|
|
222
|
-
* Supports automatic base URL resolution and TestSpectra JSON Fixtures.
|
|
223
|
-
*
|
|
224
|
-
* @param path - URL path or route to intercept (e.g. `"/api/users"` or `"https://api.example.com/v1/*"`).
|
|
225
|
-
* @param method - HTTP request method (`"GET"`, `"POST"`, `"PUT"`, `"DELETE"`, `"PATCH"`).
|
|
226
|
-
* @param fixture - Optional initial response payload or Fixture object.
|
|
227
|
-
* @param options - Optional status code and header configuration.
|
|
228
|
-
* @example
|
|
229
|
-
* ```ts
|
|
230
|
-
* // Intercept with JSON Fixture
|
|
231
|
-
* await browser.intercept("/api/status", "GET", Fixture.userData);
|
|
232
|
-
*
|
|
233
|
-
* // Intercept with custom payload & status code
|
|
234
|
-
* await browser.intercept("/api/auth/login", "POST", { token: "xyz" }, { statusCode: 200 });
|
|
235
|
-
* ```
|
|
236
|
-
* @returns `Mock` instance allowing dynamic response modification.
|
|
237
|
-
*/
|
|
238
|
-
intercept<TData = unknown>(
|
|
239
|
-
path: string,
|
|
240
|
-
method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH",
|
|
241
|
-
fixture?: InterceptInput<TData>,
|
|
242
|
-
options?: InterceptFixtureOptions
|
|
243
|
-
): Promise<Mock>;
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Asserts that the current browser page URL exactly matches the expected URL.
|
|
247
|
-
*
|
|
248
|
-
* @param expectedUrl - The exact URL expected.
|
|
249
|
-
* @example
|
|
250
|
-
* ```ts
|
|
251
|
-
* await browser.shouldHaveUrl("https://app.example.com/dashboard");
|
|
252
|
-
* ```
|
|
253
|
-
*/
|
|
254
|
-
shouldHaveUrl(expectedUrl: string): Promise<void>;
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Asserts that the current browser page URL contains the given substring.
|
|
258
|
-
*
|
|
259
|
-
* @param expectedUrl - Substring expected in the current URL.
|
|
260
|
-
* @example
|
|
261
|
-
* ```ts
|
|
262
|
-
* await browser.shouldContainUrl("/dashboard");
|
|
263
|
-
* ```
|
|
264
|
-
*/
|
|
265
|
-
shouldContainUrl(expectedUrl: string): Promise<void>;
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* Asserts that the current browser page title matches the expected title.
|
|
269
|
-
*
|
|
270
|
-
* @param expectedTitle - The exact title expected.
|
|
271
|
-
* @example
|
|
272
|
-
* ```ts
|
|
273
|
-
* await browser.shouldHaveTitle("Dashboard - TestSpectra");
|
|
274
|
-
* ```
|
|
275
|
-
*/
|
|
276
|
-
shouldHaveTitle(expectedTitle: string): Promise<void>;
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* Asserts that the current browser page title contains the expected substring.
|
|
280
|
-
*
|
|
281
|
-
* @param expectedTitle - Substring expected in the title.
|
|
282
|
-
* @example
|
|
283
|
-
* ```ts
|
|
284
|
-
* await browser.shouldContainTitle("Dashboard");
|
|
285
|
-
* ```
|
|
286
|
-
*/
|
|
287
|
-
shouldContainTitle(expectedTitle: string): Promise<void>;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
interface Promise<T> {
|
|
292
|
-
/** Asserts that the element promise resolves to a visible element. */
|
|
293
|
-
shouldBeVisible(this: Promise<WebdriverIO.Element>): Promise<WebdriverIO.Element>;
|
|
294
|
-
/** Asserts that the element promise resolves to a hidden/non-visible element. */
|
|
295
|
-
shouldNotBeVisible(this: Promise<WebdriverIO.Element>): Promise<WebdriverIO.Element>;
|
|
296
|
-
/** Asserts that the element promise resolves to an existing element in the DOM. */
|
|
297
|
-
shouldExist(this: Promise<WebdriverIO.Element>): Promise<WebdriverIO.Element>;
|
|
298
|
-
/** Asserts that the element promise resolves to an element that does not exist in the DOM. */
|
|
299
|
-
shouldNotExist(this: Promise<WebdriverIO.Element>): Promise<WebdriverIO.Element>;
|
|
300
|
-
/** Asserts that the element promise resolves to an enabled element. */
|
|
301
|
-
shouldBeEnabled(this: Promise<WebdriverIO.Element>): Promise<WebdriverIO.Element>;
|
|
302
|
-
/** Asserts that the element promise resolves to a disabled element. */
|
|
303
|
-
shouldBeDisabled(this: Promise<WebdriverIO.Element>): Promise<WebdriverIO.Element>;
|
|
304
|
-
/** Asserts that the element promise resolves to a selected element. */
|
|
305
|
-
shouldBeSelected(this: Promise<WebdriverIO.Element>): Promise<WebdriverIO.Element>;
|
|
306
|
-
/** Asserts that the element promise resolves to a checked checkbox or radio. */
|
|
307
|
-
shouldBeChecked(this: Promise<WebdriverIO.Element>): Promise<WebdriverIO.Element>;
|
|
308
|
-
/** Asserts that the element promise resolves to an element with the exact value. */
|
|
309
|
-
shouldHaveValue(this: Promise<WebdriverIO.Element>, expectedValue: string): Promise<WebdriverIO.Element>;
|
|
310
|
-
/** Asserts that the element promise resolves to an element whose value contains the substring. */
|
|
311
|
-
shouldContainValue(this: Promise<WebdriverIO.Element>, expectedValue: string): Promise<WebdriverIO.Element>;
|
|
312
|
-
/** Asserts that the element promise resolves to an element with the exact text content. */
|
|
313
|
-
shouldHaveText(this: Promise<WebdriverIO.Element>, expectedText: string): Promise<WebdriverIO.Element>;
|
|
314
|
-
/** Asserts that the element promise resolves to an element whose text contains the substring. */
|
|
315
|
-
shouldContainText(this: Promise<WebdriverIO.Element>, expectedText: string): Promise<WebdriverIO.Element>;
|
|
316
|
-
/** Asserts that the element promise resolves to an element having the CSS class. */
|
|
317
|
-
shouldHaveClass(this: Promise<WebdriverIO.Element>, className: string): Promise<WebdriverIO.Element>;
|
|
318
|
-
/** Asserts that the element promise resolves to an element having the attribute. */
|
|
319
|
-
shouldHaveAttribute(this: Promise<WebdriverIO.Element>, attributeName: string, expectedValue?: string): Promise<WebdriverIO.Element>;
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
/**
|
|
325
|
-
* Install direct callable assertion methods onto WebdriverIO browser/element and Promise prototypes.
|
|
326
|
-
*/
|
|
327
|
-
export function installPrototypes() {
|
|
328
|
-
const elementCommands: Record<string, Function> = {
|
|
329
|
-
async shouldBeVisible(this: any) {
|
|
330
|
-
const el = await resolveElement(this);
|
|
331
|
-
await expect(el).toBeDisplayed();
|
|
332
|
-
return el;
|
|
333
|
-
},
|
|
334
|
-
async shouldNotBeVisible(this: any) {
|
|
335
|
-
const el = await resolveElement(this);
|
|
336
|
-
await expect(el).not.toBeDisplayed();
|
|
337
|
-
return el;
|
|
338
|
-
},
|
|
339
|
-
async shouldExist(this: any) {
|
|
340
|
-
const el = await resolveElement(this);
|
|
341
|
-
await expect(el).toExist();
|
|
342
|
-
return el;
|
|
343
|
-
},
|
|
344
|
-
async shouldNotExist(this: any) {
|
|
345
|
-
const el = await resolveElement(this);
|
|
346
|
-
await expect(el).not.toExist();
|
|
347
|
-
return el;
|
|
348
|
-
},
|
|
349
|
-
async shouldBeEnabled(this: any) {
|
|
350
|
-
const el = await resolveElement(this);
|
|
351
|
-
await expect(el).toBeEnabled();
|
|
352
|
-
return el;
|
|
353
|
-
},
|
|
354
|
-
async shouldBeDisabled(this: any) {
|
|
355
|
-
const el = await resolveElement(this);
|
|
356
|
-
await expect(el).toBeDisabled();
|
|
357
|
-
return el;
|
|
358
|
-
},
|
|
359
|
-
async shouldBeSelected(this: any) {
|
|
360
|
-
const el = await resolveElement(this);
|
|
361
|
-
await expect(el).toBeSelected();
|
|
362
|
-
return el;
|
|
363
|
-
},
|
|
364
|
-
async shouldBeChecked(this: any) {
|
|
365
|
-
const el = await resolveElement(this);
|
|
366
|
-
await expect(el).toBeSelected();
|
|
367
|
-
return el;
|
|
368
|
-
},
|
|
369
|
-
async shouldHaveValue(this: any, val: string) {
|
|
370
|
-
const el = await resolveElement(this);
|
|
371
|
-
await expect(el).toHaveValue(val);
|
|
372
|
-
return el;
|
|
373
|
-
},
|
|
374
|
-
async shouldContainValue(this: any, val: string) {
|
|
375
|
-
const el = await resolveElement(this);
|
|
376
|
-
await expect(el).toHaveValue(expect.stringContaining(val));
|
|
377
|
-
return el;
|
|
378
|
-
},
|
|
379
|
-
async shouldHaveText(this: any, text: string) {
|
|
380
|
-
const el = await resolveElement(this);
|
|
381
|
-
await expect(el).toHaveText(text);
|
|
382
|
-
return el;
|
|
383
|
-
},
|
|
384
|
-
async shouldContainText(this: any, text: string) {
|
|
385
|
-
const el = await resolveElement(this);
|
|
386
|
-
await expect(el).toHaveText(expect.stringContaining(text));
|
|
387
|
-
return el;
|
|
388
|
-
},
|
|
389
|
-
async shouldHaveClass(this: any, cls: string) {
|
|
390
|
-
const el = await resolveElement(this);
|
|
391
|
-
await expect(el).toHaveElementClass(cls);
|
|
392
|
-
return el;
|
|
393
|
-
},
|
|
394
|
-
async shouldHaveAttribute(this: any, name: string, val?: string) {
|
|
395
|
-
const el = await resolveElement(this);
|
|
396
|
-
if (val !== undefined) {
|
|
397
|
-
await expect(el).toHaveAttribute(name, val);
|
|
398
|
-
} else {
|
|
399
|
-
await expect(el).toHaveAttribute(name);
|
|
400
|
-
}
|
|
401
|
-
return el;
|
|
402
|
-
},
|
|
403
|
-
};
|
|
404
|
-
|
|
405
|
-
const browserCommands: Record<string, Function> = {
|
|
406
|
-
async shouldHaveUrl(url: string) {
|
|
407
|
-
await expect(browser).toHaveUrl(url);
|
|
408
|
-
},
|
|
409
|
-
async shouldContainUrl(url: string) {
|
|
410
|
-
await expect(browser).toHaveUrl(expect.stringContaining(url));
|
|
411
|
-
},
|
|
412
|
-
async shouldHaveTitle(title: string) {
|
|
413
|
-
await expect(browser).toHaveTitle(title);
|
|
414
|
-
},
|
|
415
|
-
async shouldContainTitle(title: string) {
|
|
416
|
-
await expect(browser).toHaveTitle(expect.stringContaining(title));
|
|
417
|
-
},
|
|
418
|
-
};
|
|
419
|
-
|
|
420
|
-
if (typeof browser !== "undefined" && (browser as any).addCommand) {
|
|
421
|
-
for (const [name, fn] of Object.entries(elementCommands)) {
|
|
422
|
-
(browser as any).addCommand(name, fn, true);
|
|
423
|
-
}
|
|
424
|
-
for (const [name, fn] of Object.entries(browserCommands)) {
|
|
425
|
-
(browser as any).addCommand(name, fn, false);
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
// Attach to Promise.prototype for ChainablePromiseElement unwrapping
|
|
430
|
-
for (const [name, fn] of Object.entries(elementCommands)) {
|
|
431
|
-
if (typeof (Promise.prototype as any)[name] !== "function") {
|
|
432
|
-
(Promise.prototype as any)[name] = async function (this: Promise<any>, ...args: any[]) {
|
|
433
|
-
const el = await this;
|
|
434
|
-
return await fn.call(el, ...args);
|
|
435
|
-
};
|
|
436
|
-
}
|
|
24
|
+
namespace WebdriverIO {
|
|
25
|
+
interface Browser extends SpectraBrowserBridge {}
|
|
437
26
|
}
|
|
438
27
|
}
|