Skip to content

Commit

Permalink
chore(page): add dialog handling
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mendez committed Mar 24, 2024
1 parent 8aa3ca4 commit b1c84c3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 19 deletions.
31 changes: 16 additions & 15 deletions kayle/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,18 @@ export type WaitForOptions = {
};

// playwright mouse actions
type DefaultMouseActions = {
delay?: number;
clickCount?: number;
button?: "left"|"right"|"middle"
} | number;
type DefaultMouseActions =
| {
delay?: number;
clickCount?: number;
button?: "left" | "right" | "middle";
}
| number;

type Point = {
x?: number
y?: number
}
x?: number;
y?: number;
};

// puppeteer mouse events
type MouseActions = {
Expand All @@ -110,12 +112,9 @@ type MouseActions = {
source: number | Readonly<DefaultMouseActions> | unknown,
target?: number,
): Promise<void>;
move?(
source: number,
target: number,
): Promise<void>;
move?(source: number, target: number): Promise<void>;
wheel?(
deltaX: number | Readonly<{x: number, y: number}> | unknown,
deltaX: number | Readonly<{ x: number; y: number }> | unknown,
deltaY?: number,
): Promise<void>;
reset?(): Promise<void>;
Expand All @@ -125,7 +124,7 @@ type MouseActions = {
options?: {
delay?: number;
clickCount?: number;
button?: "left"|"right"|"middle"
button?: "left" | "right" | "middle";
},
): Promise<void>;
dblclick?(
Expand All @@ -134,7 +133,7 @@ type MouseActions = {
options?: {
delay?: number;
clickCount?: number;
button?: "left"|"right"|"middle"
button?: "left" | "right" | "middle";
},
): Promise<void>;
};
Expand Down Expand Up @@ -278,6 +277,8 @@ export type RunnerConfig = {
noIntercept?: boolean;
// run as accesibility extension: Experimental. Must setup extensions with the browser before hand.
browserExtension?: boolean;
/// Dismiss all dialogs that appear. By default it will dismiss all dialogs.
dialogHandle?: { action?: "dismiss" | "accept"; promptText?: string };
// watch config
_watcher?: Watcher;
// initial fake request ran to enable Js
Expand Down
14 changes: 14 additions & 0 deletions kayle/lib/kayle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,20 @@ export const kayle = async (
const config = extractArgs(o, watcher);
let validPage = true;

if (o.dialogHandle) {
o.page.on("dialog", async (dialog) => {
try {
if (o.dialogHandle.action === "accept") {
await dialog.accept(o.dialogHandle.promptText);
} else {
await dialog.dismiss();
}
} catch(e) {
// memory could be full - simply ignore the log
}
});
}

if (navigate) {
validPage = await goToPage(o);
} else if (!o.noIntercept) {
Expand Down
4 changes: 1 addition & 3 deletions kayle/lib/rules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ export const importRules = async (
baseDir?: "string",
): Promise<Rule[]> => {
const rules = await import(
`${baseDir || "./"}${locale.replace("-", "_")}/${
runner === "htmlcs" ? "htmlcs" : "axe"
}-rules`
`${baseDir || "./"}${locale.replace("-", "_")}/${runner === "htmlcs" ? "htmlcs" : "axe"}-rules`
);

return rules.axeRules || rules.htmlcsRules;
Expand Down
2 changes: 1 addition & 1 deletion kayle/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kayle",
"version": "0.8.50",
"version": "0.8.51",
"description": "Extremely fast and accurate accessibility engine built for any headless tool like playwright or puppeteer.",
"main": "./build/index.js",
"keywords": [
Expand Down

0 comments on commit b1c84c3

Please sign in to comment.