@tstdl/base 0.85.25 → 0.85.26
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.
|
@@ -17,12 +17,34 @@ export type ElementControllerOptions = {
|
|
|
17
17
|
};
|
|
18
18
|
type LocatorOptions<K extends keyof Locator, I extends keyof Parameters<Locator[K]>> = NonUndefinable<Parameters<Locator[K]>[I]>;
|
|
19
19
|
type Methods = 'isVisible' | 'isHidden' | 'isEnabled' | 'isDisabled' | 'isChecked' | 'isEditable' | 'fill' | 'type' | 'press' | 'check' | 'uncheck' | 'setChecked' | 'selectOption' | 'setInputFiles' | 'click' | 'hover' | 'focus' | 'tap' | 'selectText' | 'inputValue';
|
|
20
|
+
export type Filter = {
|
|
21
|
+
has?: ElementController;
|
|
22
|
+
hasNot?: ElementController;
|
|
23
|
+
hasText?: string | RegExp;
|
|
24
|
+
hasNotText?: string | RegExp;
|
|
25
|
+
};
|
|
20
26
|
export declare class ElementController<T extends Locator | ElementHandle = Locator | ElementHandle> implements Pick<Locator, Methods> {
|
|
21
27
|
readonly locatorOrHandle: T;
|
|
22
28
|
readonly options: ElementControllerOptions;
|
|
23
29
|
constructor(locatorOrHandle: T, options?: ElementControllerOptions);
|
|
24
30
|
getAll(): Promise<ElementController<Locator>[]>;
|
|
25
31
|
getAllHandles(): Promise<ElementController<ElementHandle>[]>;
|
|
32
|
+
/**
|
|
33
|
+
* Get an controller with elements contained in this and the provided controller.
|
|
34
|
+
* Requires locator based controller
|
|
35
|
+
* @param elementController
|
|
36
|
+
*/
|
|
37
|
+
and(elementController: ElementController): ElementController<Locator>;
|
|
38
|
+
/**
|
|
39
|
+
* Filter out elements with by provided filter.
|
|
40
|
+
* Requires locator based controller.
|
|
41
|
+
*/
|
|
42
|
+
filter(filter: Filter): ElementController<Locator>;
|
|
43
|
+
/**
|
|
44
|
+
* Locate elements in subtree with provided selector/controller and filter.
|
|
45
|
+
* Requires locator based controller.
|
|
46
|
+
*/
|
|
47
|
+
locate(selectorOrController: string | ElementController, filter?: Filter): ElementController<Locator>;
|
|
26
48
|
/**
|
|
27
49
|
* Wait for element state
|
|
28
50
|
* @param state some states may only be usable for either locator or handle
|
|
@@ -25,6 +25,7 @@ var import_timing = require("../utils/timing.js");
|
|
|
25
25
|
var import_type_guards = require("../utils/type-guards.js");
|
|
26
26
|
var import_value_or_provider = require("../utils/value-or-provider.js");
|
|
27
27
|
var import_utils = require("./utils.js");
|
|
28
|
+
const filterNonLocatorErrorMessage = "Requires a locator basesd controller";
|
|
28
29
|
class ElementController {
|
|
29
30
|
locatorOrHandle;
|
|
30
31
|
options;
|
|
@@ -46,6 +47,37 @@ class ElementController {
|
|
|
46
47
|
const handles = await this.locatorOrHandle.elementHandles();
|
|
47
48
|
return handles.map((handle) => new ElementController(handle));
|
|
48
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Get an controller with elements contained in this and the provided controller.
|
|
52
|
+
* Requires locator based controller
|
|
53
|
+
* @param elementController
|
|
54
|
+
*/
|
|
55
|
+
and(elementController) {
|
|
56
|
+
(0, import_utils.assertLocator)(this.locatorOrHandle, filterNonLocatorErrorMessage);
|
|
57
|
+
(0, import_utils.assertLocator)(elementController.locatorOrHandle, filterNonLocatorErrorMessage);
|
|
58
|
+
const locator = this.locatorOrHandle.and(elementController.locatorOrHandle);
|
|
59
|
+
return new ElementController(locator, this.options);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Filter out elements with by provided filter.
|
|
63
|
+
* Requires locator based controller.
|
|
64
|
+
*/
|
|
65
|
+
filter(filter) {
|
|
66
|
+
(0, import_utils.assertLocator)(this.locatorOrHandle, filterNonLocatorErrorMessage);
|
|
67
|
+
const locator = this.locatorOrHandle.filter(convertFilter(filter));
|
|
68
|
+
return new ElementController(locator, this.options);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Locate elements in subtree with provided selector/controller and filter.
|
|
72
|
+
* Requires locator based controller.
|
|
73
|
+
*/
|
|
74
|
+
locate(selectorOrController, filter) {
|
|
75
|
+
(0, import_utils.assertLocator)(this.locatorOrHandle, filterNonLocatorErrorMessage);
|
|
76
|
+
const selector = (0, import_type_guards.isString)(selectorOrController) ? selectorOrController : (0, import_utils.assertLocatorPass)(selectorOrController.locatorOrHandle, filterNonLocatorErrorMessage);
|
|
77
|
+
const convertedFilter = (0, import_type_guards.isDefined)(filter) ? convertFilter(filter) : void 0;
|
|
78
|
+
const locator = this.locatorOrHandle.locator(selector, convertedFilter);
|
|
79
|
+
return new ElementController(locator, this.options);
|
|
80
|
+
}
|
|
49
81
|
/**
|
|
50
82
|
* Wait for element state
|
|
51
83
|
* @param state some states may only be usable for either locator or handle
|
|
@@ -178,3 +210,11 @@ async function delay(milliseconds) {
|
|
|
178
210
|
}
|
|
179
211
|
await (0, import_timing.timeout)((0, import_value_or_provider.resolveValueOrProvider)(milliseconds));
|
|
180
212
|
}
|
|
213
|
+
function convertFilter(filter) {
|
|
214
|
+
return {
|
|
215
|
+
has: (0, import_type_guards.isDefined)(filter.has) ? (0, import_utils.assertLocatorPass)(filter.has.locatorOrHandle, filterNonLocatorErrorMessage) : void 0,
|
|
216
|
+
hasNot: (0, import_type_guards.isDefined)(filter.hasNot) ? (0, import_utils.assertLocatorPass)(filter.hasNot.locatorOrHandle, filterNonLocatorErrorMessage) : void 0,
|
|
217
|
+
hasText: filter.hasText,
|
|
218
|
+
hasNotText: filter.hasNotText
|
|
219
|
+
};
|
|
220
|
+
}
|
package/browser/utils.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export declare function getLaunchOptions(options: NewBrowserOptions): LaunchOpti
|
|
|
6
6
|
export declare function mergeNewBrowserContextOptions(a: NewBrowserContextOptions | undefined, b?: NewBrowserContextOptions, c?: NewBrowserContextOptions): NewBrowserContextOptions;
|
|
7
7
|
export declare function attachLogger(loggable: Page | BrowserContext, logger: Logger): void;
|
|
8
8
|
export declare function isLocator(locatorOrHandle: Locator | ElementHandle): locatorOrHandle is Locator;
|
|
9
|
+
export declare function assertLocator(locatorOrHandle: Locator | ElementHandle, message?: string): asserts locatorOrHandle is Locator;
|
|
10
|
+
export declare function assertLocatorPass(locatorOrHandle: Locator | ElementHandle, message?: string): Locator;
|
|
9
11
|
export declare function isElementHandle(locatorOrHandle: Locator | ElementHandle): locatorOrHandle is ElementHandle;
|
|
10
12
|
export declare function isPage(pageOrFrameOrContext: Page | Frame | BrowserContext): pageOrFrameOrContext is Page;
|
|
11
13
|
export declare function isFrame(pageOrFrameOrContext: Page | Frame | BrowserContext): pageOrFrameOrContext is Frame;
|
package/browser/utils.js
CHANGED
|
@@ -18,6 +18,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var utils_exports = {};
|
|
20
20
|
__export(utils_exports, {
|
|
21
|
+
assertLocator: () => assertLocator,
|
|
22
|
+
assertLocatorPass: () => assertLocatorPass,
|
|
21
23
|
attachLogger: () => attachLogger,
|
|
22
24
|
getLaunchOptions: () => getLaunchOptions,
|
|
23
25
|
isBrowserContext: () => isBrowserContext,
|
|
@@ -104,6 +106,13 @@ function attachLogger(loggable, logger) {
|
|
|
104
106
|
function isLocator(locatorOrHandle) {
|
|
105
107
|
return locatorOrHandle.constructor.name == "Locator";
|
|
106
108
|
}
|
|
109
|
+
function assertLocator(locatorOrHandle, message = "Locator instead of ElementHandle required") {
|
|
110
|
+
(0, import_type_guards.assert)(isLocator(locatorOrHandle), message);
|
|
111
|
+
}
|
|
112
|
+
function assertLocatorPass(locatorOrHandle, message = "Locator instead of ElementHandle required") {
|
|
113
|
+
assertLocator(locatorOrHandle, message);
|
|
114
|
+
return locatorOrHandle;
|
|
115
|
+
}
|
|
107
116
|
function isElementHandle(locatorOrHandle) {
|
|
108
117
|
return locatorOrHandle.constructor.name == "ElementHandle";
|
|
109
118
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tstdl/base",
|
|
3
|
-
"version": "0.85.
|
|
3
|
+
"version": "0.85.26",
|
|
4
4
|
"author": "Patrick Hein",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"koa": "^2.14",
|
|
59
59
|
"minio": "^7.1",
|
|
60
60
|
"mjml": "^4.14",
|
|
61
|
-
"mongodb": "^5.
|
|
61
|
+
"mongodb": "^5.8",
|
|
62
62
|
"nodemailer": "^6.9",
|
|
63
63
|
"playwright": "^1.37",
|
|
64
64
|
"preact": "^10.17",
|