Skip to content
This repository has been archived by the owner on Jul 21, 2022. It is now read-only.

Commit

Permalink
Expose more functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ericnewcomer committed Dec 15, 2020
1 parent 55d8aa1 commit dddbf36
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,33 @@ var PuppeteerBrowser = function (baseBrowserDecorator, args) {
await page.waitForNavigation(options);
});

await page.exposeFunction("waitForFunction", async (options) => {
await page.waitForFunction(options);
});

await page.exposeFunction("pressKey", async (key, times, options) => {
for (let i=0; i<times; i++) {
await page.keyboard.press(key, options);
}
});

await page.exposeFunction("typeInto", async (selector, text, replace=false) => {
const frame = await page.frames().find((f) => f.name() === "context");
const element = await frame.$(selector);
await element.click({clickCount: replace ? 3 : 1});
await page.keyboard.type(text);
});

await page.exposeFunction("type", async (text) => {
await page.keyboard.type(text);
});

await page.exposeFunction("click", async (selector) => {
const frame = await page.frames().find((f) => f.name() === "context");
const element = await frame.$(selector);
await element.click({});
});

await page.exposeFunction("waitForSelector", async (selector, options) => {
await page.waitForSelector(selector, options);
});
Expand All @@ -221,6 +248,7 @@ var PuppeteerBrowser = function (baseBrowserDecorator, args) {
await page.exposeFunction("setViewport", async (options) => {
await page.setViewport(options);
});

await page.exposeFunction("captureElement", async (name, selector) => {
const filename = path.resolve(
"./",
Expand Down Expand Up @@ -286,6 +314,13 @@ var PuppeteerBrowser = function (baseBrowserDecorator, args) {
});
});

await page.exposeFunction("addStyleTag", (content) => {
return new Promise(async (resolve, reject) => {
await page.addStyleTag({content});
resolve();
});
});

await page.exposeFunction(
"matchPageSnapshot",
(paths, clip, excluded, threshold) => {
Expand Down

0 comments on commit dddbf36

Please sign in to comment.