@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 ADDED
@@ -0,0 +1,26 @@
1
+ # Puppeteer helper packages
2
+ ## Getting started
3
+ ```
4
+ npm ci
5
+ ```
6
+ ## Dev
7
+ Helpers are written in typescript and then transpiled out to various formats and module systems (currently only CJS).
8
+
9
+ ### Build
10
+ Run the following command. This will emit the `cjs` directory.
11
+ ```
12
+ npx tsc
13
+ ```
14
+
15
+ ## Use
16
+ `npm` has support for `bitbucket` package sources (https://docs.npmjs.com/cli/v7/commands/npm-install)
17
+
18
+ So to install the `@tecgovtnz/puppeteer` package, run:
19
+ ```
20
+ npm i bitbucket:careersnz/npm-puppeteer
21
+ ```
22
+
23
+ If you are developing a new package and which to test your branch you can use the syntax:
24
+ ```
25
+ npm i bitbucket:careersnz/npm-puppeteer\#BRANCH_NAME
26
+ ```
package/checkbox.ts ADDED
@@ -0,0 +1,54 @@
1
+ import * as puppeteer from 'puppeteer';
2
+ import { repeatUntil } from './wait-until';
3
+
4
+ /**
5
+ * Is a checkbox checked?
6
+ * @param selector The selector for the HTMLInputElement element.
7
+ * @param page The puppeteer page.
8
+ * @returns true if the checkbox is checked, false otherwise.
9
+ */
10
+ export async function isChecked(page: puppeteer.Page, selector: string): Promise<boolean> {
11
+ const isChecked = await page.evaluate((selector_: string) => {
12
+ const checkbox = document.querySelector(selector_) as HTMLInputElement;
13
+ if (!checkbox) {
14
+ return null;
15
+ }
16
+ return checkbox.checked;
17
+ }, selector);
18
+
19
+ if (isChecked === null) {
20
+ throw new Error(`Failed to get the checked value of '${selector}'`);
21
+ }
22
+
23
+ return isChecked;
24
+ }
25
+
26
+ /**
27
+ * Checks a checkbox.
28
+ * @param page The puppeteer page.
29
+ * @param selector The selector for the HTMLInputElement element.
30
+ */
31
+ export async function check(page: puppeteer.Page, selector: string) {
32
+ await repeatUntil(async () => {
33
+ if (await isChecked(page, selector)) {
34
+ return true;
35
+ }
36
+
37
+ await page.click(selector);
38
+ }, `Expected checkbox '${selector}' to be checked`);
39
+ }
40
+
41
+ /**
42
+ * Unchecks a checkbox.
43
+ * @param page The puppeteer page.
44
+ * @param selector The selector for the HTMLInputElement element.
45
+ */
46
+ export async function uncheck(page: puppeteer.Page, selector: string) {
47
+ await repeatUntil(async () => {
48
+ if (!(await isChecked(page, selector))) {
49
+ return true;
50
+ }
51
+
52
+ await page.click(selector);
53
+ }, `Expected checkbox '${selector}' to be unchecked`);
54
+ }
@@ -0,0 +1,20 @@
1
+ import * as puppeteer from 'puppeteer';
2
+ /**
3
+ * Is a checkbox checked?
4
+ * @param selector The selector for the HTMLInputElement element.
5
+ * @param page The puppeteer page.
6
+ * @returns true if the checkbox is checked, false otherwise.
7
+ */
8
+ export declare function isChecked(page: puppeteer.Page, selector: string): Promise<boolean>;
9
+ /**
10
+ * Checks a checkbox.
11
+ * @param page The puppeteer page.
12
+ * @param selector The selector for the HTMLInputElement element.
13
+ */
14
+ export declare function check(page: puppeteer.Page, selector: string): Promise<void>;
15
+ /**
16
+ * Unchecks a checkbox.
17
+ * @param page The puppeteer page.
18
+ * @param selector The selector for the HTMLInputElement element.
19
+ */
20
+ export declare function uncheck(page: puppeteer.Page, selector: string): Promise<void>;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.uncheck = exports.check = exports.isChecked = void 0;
13
+ const wait_until_1 = require("./wait-until");
14
+ /**
15
+ * Is a checkbox checked?
16
+ * @param selector The selector for the HTMLInputElement element.
17
+ * @param page The puppeteer page.
18
+ * @returns true if the checkbox is checked, false otherwise.
19
+ */
20
+ function isChecked(page, selector) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ const isChecked = yield page.evaluate((selector_) => {
23
+ const checkbox = document.querySelector(selector_);
24
+ if (!checkbox) {
25
+ return null;
26
+ }
27
+ return checkbox.checked;
28
+ }, selector);
29
+ if (isChecked === null) {
30
+ throw new Error(`Failed to get the checked value of '${selector}'`);
31
+ }
32
+ return isChecked;
33
+ });
34
+ }
35
+ exports.isChecked = isChecked;
36
+ /**
37
+ * Checks a checkbox.
38
+ * @param page The puppeteer page.
39
+ * @param selector The selector for the HTMLInputElement element.
40
+ */
41
+ function check(page, selector) {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ yield wait_until_1.repeatUntil(() => __awaiter(this, void 0, void 0, function* () {
44
+ if (yield isChecked(page, selector)) {
45
+ return true;
46
+ }
47
+ yield page.click(selector);
48
+ }), `Expected checkbox '${selector}' to be checked`);
49
+ });
50
+ }
51
+ exports.check = check;
52
+ /**
53
+ * Unchecks a checkbox.
54
+ * @param page The puppeteer page.
55
+ * @param selector The selector for the HTMLInputElement element.
56
+ */
57
+ function uncheck(page, selector) {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ yield wait_until_1.repeatUntil(() => __awaiter(this, void 0, void 0, function* () {
60
+ if (!(yield isChecked(page, selector))) {
61
+ return true;
62
+ }
63
+ yield page.click(selector);
64
+ }), `Expected checkbox '${selector}' to be unchecked`);
65
+ });
66
+ }
67
+ exports.uncheck = uncheck;
@@ -0,0 +1,11 @@
1
+ import * as puppeteer from 'puppeteer';
2
+ /**
3
+ * Clicks an element and waits for the page to navigate to a new URL or to reload.
4
+ * @param page The puppeteer page.
5
+ * @param elementOrSelector The HTMLElement or string selector to click.
6
+ * @param waitOptions Optional wait settings.
7
+ * @returns A promise which resolves after the page has navigated.
8
+ */
9
+ export declare function clickAndWaitForNavigation(page: puppeteer.Page, elementOrSelector: string | puppeteer.ElementHandle, waitOptions?: puppeteer.WaitForOptions): Promise<[puppeteer.HTTPResponse | null, void]>;
10
+ export declare function clickSelectorAndWaitForNavigation(page: puppeteer.Page, selector: string, waitOptions?: puppeteer.WaitForOptions): Promise<[puppeteer.HTTPResponse | null, void]>;
11
+ export declare function clickElementAndWaitForNavigation(page: puppeteer.Page, element: puppeteer.ElementHandle, waitOptions?: puppeteer.WaitForOptions): Promise<[puppeteer.HTTPResponse | null, void]>;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.clickElementAndWaitForNavigation = exports.clickSelectorAndWaitForNavigation = exports.clickAndWaitForNavigation = void 0;
13
+ /**
14
+ * Clicks an element and waits for the page to navigate to a new URL or to reload.
15
+ * @param page The puppeteer page.
16
+ * @param elementOrSelector The HTMLElement or string selector to click.
17
+ * @param waitOptions Optional wait settings.
18
+ * @returns A promise which resolves after the page has navigated.
19
+ */
20
+ function clickAndWaitForNavigation(page, elementOrSelector, waitOptions) {
21
+ if (typeof elementOrSelector === 'string') {
22
+ return clickSelectorAndWaitForNavigation(page, elementOrSelector, waitOptions);
23
+ }
24
+ else {
25
+ return clickElementAndWaitForNavigation(page, elementOrSelector, waitOptions);
26
+ }
27
+ }
28
+ exports.clickAndWaitForNavigation = clickAndWaitForNavigation;
29
+ function clickSelectorAndWaitForNavigation(page, selector, waitOptions) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ return Promise.all([
32
+ page.waitForNavigation(waitOptions),
33
+ page.click(selector)
34
+ ]);
35
+ });
36
+ }
37
+ exports.clickSelectorAndWaitForNavigation = clickSelectorAndWaitForNavigation;
38
+ function clickElementAndWaitForNavigation(page, element, waitOptions) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ return Promise.all([
41
+ page.waitForNavigation(waitOptions),
42
+ element.click()
43
+ ]);
44
+ });
45
+ }
46
+ exports.clickElementAndWaitForNavigation = clickElementAndWaitForNavigation;
@@ -0,0 +1,8 @@
1
+ import * as puppeteer from 'puppeteer';
2
+ /**
3
+ * Tries to find an element containing the specified text in its innerText value.
4
+ * @param page The puppeteer page.
5
+ * @param elementSelector The set of elements to search in.
6
+ * @param text The text to search for. This value is case-sensitive.
7
+ */
8
+ export declare function findElementWithText(page: puppeteer.Page, elementSelector: string, text: string): Promise<puppeteer.ElementHandle<HTMLElement> | null>;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.findElementWithText = void 0;
13
+ const get_text_1 = require("./get-text");
14
+ /**
15
+ * Tries to find an element containing the specified text in its innerText value.
16
+ * @param page The puppeteer page.
17
+ * @param elementSelector The set of elements to search in.
18
+ * @param text The text to search for. This value is case-sensitive.
19
+ */
20
+ function findElementWithText(page, elementSelector, text) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ const elements = (yield page.$$(elementSelector));
23
+ for (const element of elements) {
24
+ const textOfElement = yield get_text_1.getText(page, element);
25
+ if (textOfElement && textOfElement.includes(text)) {
26
+ return element;
27
+ }
28
+ }
29
+ return null;
30
+ });
31
+ }
32
+ exports.findElementWithText = findElementWithText;
33
+ ;
@@ -0,0 +1,8 @@
1
+ import * as puppeteer from 'puppeteer';
2
+ /**
3
+ * Get the attirbute value from an element.
4
+ * @param page The puppeteer page.
5
+ * @param elementSelectorOrHandle An element selector or handle to an element.
6
+ * @param attributeName The name of the attribute to get the value for.
7
+ */
8
+ export declare function getAttribute(page: puppeteer.Page, elementSelectorOrHandle: string | puppeteer.ElementHandle<Element>, attributeName: string): Promise<any>;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getAttribute = void 0;
13
+ const throw_helper_1 = require("./throw-helper");
14
+ /**
15
+ * Get the attirbute value from an element.
16
+ * @param page The puppeteer page.
17
+ * @param elementSelectorOrHandle An element selector or handle to an element.
18
+ * @param attributeName The name of the attribute to get the value for.
19
+ */
20
+ function getAttribute(page, elementSelectorOrHandle, attributeName) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ let element;
23
+ switch (typeof elementSelectorOrHandle) {
24
+ case 'string':
25
+ element = (yield page.waitForSelector(elementSelectorOrHandle));
26
+ throw_helper_1.assertSuccessfulSelector(elementSelectorOrHandle, element);
27
+ break;
28
+ case 'object':
29
+ element = elementSelectorOrHandle;
30
+ break;
31
+ default:
32
+ throw new Error(`Unsupported type ${typeof elementSelectorOrHandle}`);
33
+ }
34
+ return yield page.evaluate((el, att) => el.getAttribute(att), element, attributeName);
35
+ });
36
+ }
37
+ exports.getAttribute = getAttribute;
38
+ ;
@@ -0,0 +1,7 @@
1
+ import * as puppeteer from 'puppeteer';
2
+ /**
3
+ * Gets the innerText value of an element.
4
+ * @param page The puppeteer page.
5
+ * @param elementSelectorOrHandle The HTMLElement or string selector to get the innerText value from.
6
+ */
7
+ export declare function getText(page: puppeteer.Page, elementSelectorOrHandle: string | puppeteer.ElementHandle<HTMLElement>): Promise<string | null | undefined>;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getText = void 0;
13
+ const throw_helper_1 = require("./throw-helper");
14
+ /**
15
+ * Gets the innerText value of an element.
16
+ * @param page The puppeteer page.
17
+ * @param elementSelectorOrHandle The HTMLElement or string selector to get the innerText value from.
18
+ */
19
+ function getText(page, elementSelectorOrHandle) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ switch (typeof elementSelectorOrHandle) {
22
+ case 'string':
23
+ const element = (yield page.waitForSelector(elementSelectorOrHandle));
24
+ throw_helper_1.assertSuccessfulSelector(elementSelectorOrHandle, element);
25
+ return (page.evaluate(el => el.innerText, element));
26
+ case 'object':
27
+ return (page.evaluate(el => el.innerText, elementSelectorOrHandle));
28
+ default:
29
+ throw new Error(`Unsupported type ${typeof elementSelectorOrHandle}`);
30
+ }
31
+ });
32
+ }
33
+ exports.getText = getText;
package/cjs/index.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ export * from './checkbox';
2
+ export * from './click-helper';
3
+ export * from './find-element-with-text';
4
+ export * from './get-attribute';
5
+ export * from './get-text';
6
+ export * from './input';
7
+ export * from './is-visible';
8
+ export * from './mail-hog';
9
+ export * from './select';
10
+ export * from './wait-until';
11
+ export * from './wait';
package/cjs/index.js ADDED
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./checkbox"), exports);
14
+ __exportStar(require("./click-helper"), exports);
15
+ __exportStar(require("./find-element-with-text"), exports);
16
+ __exportStar(require("./get-attribute"), exports);
17
+ __exportStar(require("./get-text"), exports);
18
+ __exportStar(require("./input"), exports);
19
+ __exportStar(require("./is-visible"), exports);
20
+ __exportStar(require("./mail-hog"), exports);
21
+ __exportStar(require("./select"), exports);
22
+ __exportStar(require("./wait-until"), exports);
23
+ __exportStar(require("./wait"), exports);
package/cjs/input.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import * as puppeteer from 'puppeteer';
2
+ /**
3
+ * Gets the value from an HTMLInputElement.
4
+ * @param page The puppeteer page.
5
+ * @param elementSelectorOrHandle A selector for a <input /> element, or a handle.
6
+ */
7
+ export declare function getValue(page: puppeteer.Page, elementSelectorOrHandle: string | puppeteer.ElementHandle<HTMLInputElement>): Promise<any>;
8
+ /**
9
+ * @param selector A selector for a <input /> element.
10
+ * @param text The text to type into the <input />.
11
+ */
12
+ export declare function clearAndType(page: puppeteer.Page, selector: string, text: string): Promise<void>;
package/cjs/input.js ADDED
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.clearAndType = exports.getValue = void 0;
13
+ const throw_helper_1 = require("./throw-helper");
14
+ /**
15
+ * Gets the value from an HTMLInputElement.
16
+ * @param page The puppeteer page.
17
+ * @param elementSelectorOrHandle A selector for a <input /> element, or a handle.
18
+ */
19
+ function getValue(page, elementSelectorOrHandle) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ switch (typeof elementSelectorOrHandle) {
22
+ case 'string':
23
+ const element = (yield page.waitForSelector(elementSelectorOrHandle));
24
+ throw_helper_1.assertSuccessfulSelector(elementSelectorOrHandle, element);
25
+ return page.evaluate(el => el.value, element);
26
+ case 'object':
27
+ return page.evaluate(el => el.value, elementSelectorOrHandle);
28
+ default:
29
+ throw new Error(`Unsupported type ${typeof elementSelectorOrHandle}`);
30
+ }
31
+ });
32
+ }
33
+ exports.getValue = getValue;
34
+ /**
35
+ * @param selector A selector for a <input /> element.
36
+ * @param text The text to type into the <input />.
37
+ */
38
+ function clearAndType(page, selector, text) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ const input = (yield page.$(selector));
41
+ throw_helper_1.assertSuccessfulSelector(selector, input);
42
+ yield page.evaluate(i => {
43
+ i.value = '';
44
+ }, input);
45
+ yield page.type(selector, text);
46
+ });
47
+ }
48
+ exports.clearAndType = clearAndType;
@@ -0,0 +1,2 @@
1
+ import * as puppeteer from 'puppeteer';
2
+ export declare function isVisible(page: puppeteer.Page, selectorOrElementHandle: string | puppeteer.ElementHandle): Promise<any>;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.isVisible = void 0;
13
+ function isVisible(page, selectorOrElementHandle) {
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ const element = typeof selectorOrElementHandle === 'string'
16
+ ? yield page.$(selectorOrElementHandle)
17
+ : selectorOrElementHandle;
18
+ if (element === null) {
19
+ throw new Error(`Failed to find object`);
20
+ }
21
+ return page.evaluate((element) => {
22
+ const style = getComputedStyle(element);
23
+ const rect = element.getBoundingClientRect();
24
+ return style.visibility !== 'hidden' && !!(rect.bottom || rect.top || rect.height || rect.width) && style.opacity !== '0';
25
+ }, element);
26
+ });
27
+ }
28
+ exports.isVisible = isVisible;
@@ -0,0 +1,10 @@
1
+ import parseEmail from 'mailparser';
2
+ export declare class MailHog {
3
+ private _mailHogUrl;
4
+ constructor(mailHogUrl: string);
5
+ /**
6
+ * Gets email from the mailhog inbox which match the specified 'to' address.
7
+ * @param addressNeedle A 'to' address filter.
8
+ */
9
+ get(addressNeedle: string): Promise<parseEmail.ParsedMail[]>;
10
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.MailHog = void 0;
16
+ const node_fetch_1 = __importDefault(require("node-fetch"));
17
+ const mailparser_1 = __importDefault(require("mailparser"));
18
+ class MailHog {
19
+ constructor(mailHogUrl) {
20
+ this._mailHogUrl = mailHogUrl;
21
+ }
22
+ /**
23
+ * Gets email from the mailhog inbox which match the specified 'to' address.
24
+ * @param addressNeedle A 'to' address filter.
25
+ */
26
+ get(addressNeedle) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ const response = yield node_fetch_1.default(`${this._mailHogUrl}/api/v2/search?kind=to&query=${encodeURIComponent(addressNeedle)}`);
29
+ const messagesJson = yield response.json();
30
+ const messages = messagesJson.items;
31
+ return Promise.all(messages.map(message => mailparser_1.default.simpleParser(message.Raw.Data)));
32
+ });
33
+ }
34
+ }
35
+ exports.MailHog = MailHog;
@@ -0,0 +1,28 @@
1
+ import * as puppeteer from 'puppeteer';
2
+ /**
3
+ * Selects one (or many) dropdown items by matching their <option /> text values.
4
+ * @param page The puppeteer page.
5
+ * @param selector A selector to a <select /> element.
6
+ * @param texts A set of <option /> innerText values to match on.
7
+ * @returns An array of option values that have been successfully selected.
8
+ */
9
+ export declare function selectWithText(page: puppeteer.Page, selector: string, ...texts: string[]): Promise<string[]>;
10
+ /**
11
+ * Gets the text of the currently selected option of a <select />.
12
+ * @param page The puppeteer page.
13
+ * @param selector A selector to a <select /> element.
14
+ * @returns
15
+ */
16
+ export declare function getTextOfSelectedOption(page: puppeteer.Page, selector: string): Promise<any>;
17
+ /**
18
+ * Gets the set of text of the currently selected options of a <select /> element.
19
+ * @param page The puppeteer page.
20
+ * @param selector A selector to a <select /> element.
21
+ */
22
+ export declare function getTextsOfSelectedOptions(page: puppeteer.Page, selector: string): Promise<any>;
23
+ /**
24
+ * Uncheck all options of a select.
25
+ * @param page The puppeteer page.
26
+ * @param selector A selector to a <select /> element.
27
+ */
28
+ export declare function uncheckAll(page: puppeteer.Page, selector: string): Promise<void>;