@tecgovtnzwebdev/puppeteer 3.0.1
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/README.md +26 -0
- package/checkbox.ts +54 -0
- package/cjs/checkbox.d.ts +20 -0
- package/cjs/checkbox.js +67 -0
- package/cjs/click-helper.d.ts +11 -0
- package/cjs/click-helper.js +46 -0
- package/cjs/find-element-with-text.d.ts +8 -0
- package/cjs/find-element-with-text.js +33 -0
- package/cjs/get-attribute.d.ts +8 -0
- package/cjs/get-attribute.js +38 -0
- package/cjs/get-text.d.ts +7 -0
- package/cjs/get-text.js +33 -0
- package/cjs/index.d.ts +11 -0
- package/cjs/index.js +23 -0
- package/cjs/input.d.ts +12 -0
- package/cjs/input.js +48 -0
- package/cjs/is-visible.d.ts +2 -0
- package/cjs/is-visible.js +28 -0
- package/cjs/mail-hog.d.ts +10 -0
- package/cjs/mail-hog.js +35 -0
- package/cjs/select.d.ts +28 -0
- package/cjs/select.js +93 -0
- package/cjs/throw-helper.d.ts +2 -0
- package/cjs/throw-helper.js +10 -0
- package/cjs/wait-until.d.ts +16 -0
- package/cjs/wait-until.js +56 -0
- package/cjs/wait.d.ts +7 -0
- package/cjs/wait.js +22 -0
- package/click-helper.ts +31 -0
- package/find-element-with-text.ts +19 -0
- package/get-attribute.ts +25 -0
- package/get-text.ts +21 -0
- package/index.ts +11 -0
- package/input.ts +35 -0
- package/is-visible.ts +17 -0
- package/mail-hog.ts +23 -0
- package/package.json +21 -0
- package/pipelines/artifact-publish-pipeline.yml +16 -0
- package/select.ts +82 -0
- package/throw-helper.ts +8 -0
- package/tsconfig.json +71 -0
- package/wait-until.ts +48 -0
- package/wait.ts +9 -0
package/wait-until.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as puppeteer from 'puppeteer';
|
|
2
|
+
import { wait } from './wait';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated Use `repeatUntil` instead.
|
|
6
|
+
*/
|
|
7
|
+
export async function waitUntil(page: puppeteer.Page, waitFunction: () => Promise<boolean>, errorMessage = 'Timed out waiting for something', timeOut = 5000, pollInterval = 100) {
|
|
8
|
+
const endTime = Date.now() + timeOut;
|
|
9
|
+
let conditionMet = await waitFunction();
|
|
10
|
+
while (!conditionMet && Date.now() < endTime) {
|
|
11
|
+
await new Promise(resolve => setTimeout(resolve, pollInterval));
|
|
12
|
+
conditionMet = await waitFunction();
|
|
13
|
+
}
|
|
14
|
+
if (!conditionMet) {
|
|
15
|
+
throw new Error(errorMessage);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Repeats an operation until a specified condition is met or a timeout occurs.
|
|
21
|
+
*
|
|
22
|
+
* @param page - The Puppeteer `Page` instance to operate on.
|
|
23
|
+
* @param operation - An asynchronous function that returns a boolean indicating whether the condition is met.
|
|
24
|
+
* @param errorMessage - The error message to throw if the timeout is reached before the condition is met. Defaults to 'Timed out waiting for something'.
|
|
25
|
+
* @param timeOut - The maximum time to wait (in milliseconds) before throwing an error. Defaults to 5000 ms.
|
|
26
|
+
* @param pollInterval - The interval (in milliseconds) at which the condition is checked. Defaults to 100 ms.
|
|
27
|
+
* @throws Will throw an error with the provided `errorMessage` if the condition is not met within the timeout period.
|
|
28
|
+
*/
|
|
29
|
+
export async function repeatUntil(
|
|
30
|
+
operation: () => Promise<boolean | undefined>,
|
|
31
|
+
errorMessage = 'Timed out waiting for something',
|
|
32
|
+
timeOut = 5000,
|
|
33
|
+
pollInterval = 100) {
|
|
34
|
+
// The absolute end time this operation should run until (in milliseconds)
|
|
35
|
+
const endTime = Date.now() + timeOut;
|
|
36
|
+
|
|
37
|
+
do {
|
|
38
|
+
// Call the operation and check if it returns true
|
|
39
|
+
if (await operation()) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Wait for the specified poll interval before checking again
|
|
44
|
+
await wait(pollInterval);
|
|
45
|
+
} while (Date.now() < endTime);
|
|
46
|
+
|
|
47
|
+
throw new Error(errorMessage);
|
|
48
|
+
}
|
package/wait.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Waits for a specified period of time.
|
|
3
|
+
*
|
|
4
|
+
* @param period - The time to wait in milliseconds.
|
|
5
|
+
* @returns A promise that resolves after the specified period.
|
|
6
|
+
*/
|
|
7
|
+
export const wait = async (period: number) => {
|
|
8
|
+
await new Promise(resolve => setTimeout(resolve, period));
|
|
9
|
+
}
|