playwright-json-runner
Version:
Extends Playwright to run tests using JSON-based test definitions.
510 lines (508 loc) • 14.9 kB
JavaScript
import { z } from 'zod';
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
var withLabelSchema = z.object({
label: z.string().optional()
});
var withDescriptionSchema = z.object({
description: z.string().optional()
});
var testObjectSchema = withLabelSchema.merge(withDescriptionSchema);
var PlaywrightRoleOptionsSchema = z.object({
checked: z.boolean().optional(),
disabled: z.boolean().optional(),
exact: z.boolean().optional(),
expanded: z.boolean().optional(),
includeHidden: z.boolean().optional(),
level: z.number().optional(),
// For name, accept string or RegExp.
// If you strictly need to parse only real RegExp objects at runtime, keep it like this.
// If you want to accept a "string that might be a pattern," consider a string-based approach.
name: z.union([z.string(), z.instanceof(RegExp)]).optional(),
pressed: z.boolean().optional(),
selected: z.boolean().optional()
}).optional();
var PlaywrightRoleSchema = z.enum([
"alert",
"alertdialog",
"application",
"article",
"banner",
"blockquote",
"button",
"caption",
"cell",
"checkbox",
"code",
"columnheader",
"combobox",
"complementary",
"contentinfo",
"definition",
"deletion",
"dialog",
"directory",
"document",
"emphasis",
"feed",
"figure",
"form",
"generic",
"grid",
"gridcell",
"group",
"heading",
"img",
"insertion",
"link",
"list",
"listbox",
"listitem",
"log",
"main",
"marquee",
"math",
"meter",
"menu",
"menubar",
"menuitem",
"menuitemcheckbox",
"menuitemradio",
"navigation",
"none",
"note",
"option",
"paragraph",
"presentation",
"progressbar",
"radio",
"radiogroup",
"region",
"row",
"rowgroup",
"rowheader",
"scrollbar",
"search",
"searchbox",
"separator",
"slider",
"spinbutton",
"status",
"strong",
"subscript",
"superscript",
"switch",
"tab",
"table",
"tablist",
"tabpanel",
"term",
"textbox",
"time",
"timer",
"toolbar",
"tooltip",
"tree",
"treegrid",
"treeitem"
]);
var nthField = { nth: z.number().optional() };
var selectorLocatorSchema = z.object({
by: z.literal("selector"),
value: z.string().describe("CSS selector"),
...nthField
});
var xpathLocatorSchema = z.object({
by: z.literal("xpath"),
value: z.string().describe("XPath expression"),
...nthField
});
var roleLocatorSchema = z.object({
by: z.literal("role"),
role: PlaywrightRoleSchema,
name: z.union([z.string(), z.instanceof(RegExp)]).optional(),
exact: z.boolean().optional(),
checked: z.boolean().optional(),
disabled: z.boolean().optional(),
expanded: z.boolean().optional(),
includeHidden: z.boolean().optional(),
level: z.number().optional(),
pressed: z.boolean().optional(),
selected: z.boolean().optional(),
...nthField
});
var textLocatorSchema = z.object({
by: z.literal("text"),
value: z.string(),
exact: z.boolean().optional(),
...nthField
});
var labelLocatorSchema = z.object({
by: z.literal("label"),
value: z.string(),
exact: z.boolean().optional(),
...nthField
});
var placeholderLocatorSchema = z.object({
by: z.literal("placeholder"),
value: z.string(),
exact: z.boolean().optional(),
...nthField
});
var altTextLocatorSchema = z.object({
by: z.literal("altText"),
value: z.string(),
exact: z.boolean().optional(),
...nthField
});
var titleLocatorSchema = z.object({
by: z.literal("title"),
value: z.string(),
exact: z.boolean().optional(),
...nthField
});
var testIdLocatorSchema = z.object({
by: z.literal("testId"),
value: z.string(),
...nthField
});
var locatorParamsSchema;
var nestedLocatorSchema = z.lazy(
() => z.object({
by: z.literal("nested"),
parent: locatorParamsSchema,
child: locatorParamsSchema,
...nthField
})
);
var customLocatorSchema = z.object({
by: z.string(),
value: z.string().optional(),
...nthField
});
locatorParamsSchema = z.union([
z.discriminatedUnion("by", [
selectorLocatorSchema,
xpathLocatorSchema,
roleLocatorSchema,
textLocatorSchema,
labelLocatorSchema,
placeholderLocatorSchema,
altTextLocatorSchema,
titleLocatorSchema,
testIdLocatorSchema
]),
nestedLocatorSchema,
customLocatorSchema
]);
var timeoutOpts = z.object({ timeout: z.number().optional() }).optional();
var interactOpts = z.object({
timeout: z.number().optional(),
force: z.boolean().optional(),
trial: z.boolean().optional()
}).optional();
var waitUntilEnum = z.enum(["commit", "domcontentloaded", "load", "networkidle"]);
var loadStateEnum = z.enum(["domcontentloaded", "load", "networkidle"]);
var waitForStateEnum = z.enum(["attached", "detached", "visible", "hidden"]);
var base = testObjectSchema;
var withLocator = base.extend({ locator: locatorParamsSchema });
var navigateActionSchema = base.extend({
action: z.literal("navigate"),
url: z.string(),
options: z.object({ timeout: z.number().optional(), waitUntil: waitUntilEnum.optional() }).optional()
});
var sleepActionSchema = base.extend({
action: z.literal("sleep"),
duration: z.number().describe("milliseconds to wait")
});
var waitForURLActionSchema = base.extend({
action: z.literal("waitForURL"),
url: z.string(),
options: z.object({ timeout: z.number().optional(), waitUntil: waitUntilEnum.optional() }).optional()
});
var goBackActionSchema = base.extend({
action: z.literal("goBack"),
options: z.object({ timeout: z.number().optional(), waitUntil: waitUntilEnum.optional() }).optional()
});
var goForwardActionSchema = base.extend({
action: z.literal("goForward"),
options: z.object({ timeout: z.number().optional(), waitUntil: waitUntilEnum.optional() }).optional()
});
var waitForLoadStateActionSchema = base.extend({
action: z.literal("waitForLoadState"),
state: loadStateEnum.optional(),
options: timeoutOpts
});
var assertURLActionSchema = base.extend({
action: z.literal("assertURL"),
value: z.string(),
options: timeoutOpts
});
var assertTitleActionSchema = base.extend({
action: z.literal("assertTitle"),
value: z.string(),
options: timeoutOpts
});
var scrollActionSchema = base.extend({
action: z.literal("scroll"),
deltaX: z.number().describe("Horizontal scroll pixels"),
deltaY: z.number().describe("Vertical scroll pixels")
});
var waitForTextActionSchema = base.extend({
action: z.literal("waitForText"),
value: z.string(),
options: z.object({
timeout: z.number().optional(),
state: waitForStateEnum.optional()
}).optional()
});
var clickCoordinatesActionSchema = base.extend({
action: z.literal("clickCoordinates"),
x: z.number(),
y: z.number(),
options: z.object({
button: z.enum(["left", "middle", "right"]).optional(),
clickCount: z.number().optional(),
delay: z.number().optional()
}).optional()
});
var screenshotActionSchema = base.extend({
action: z.literal("screenshot"),
locator: locatorParamsSchema.optional(),
path: z.string().optional(),
options: z.object({ fullPage: z.boolean().optional(), timeout: z.number().optional() }).optional()
});
var assertSnapshotActionSchema = base.extend({
action: z.literal("assertSnapshot"),
locator: locatorParamsSchema.optional(),
name: z.string().optional().describe("Baseline snapshot filename"),
options: z.object({
timeout: z.number().optional(),
maxDiffPixels: z.number().optional(),
maxDiffPixelRatio: z.number().optional(),
threshold: z.number().optional()
}).optional()
});
var clickActionSchema = withLocator.extend({
action: z.literal("click"),
options: z.object({
button: z.enum(["left", "middle", "right"]).optional(),
clickCount: z.number().optional(),
delay: z.number().optional(),
force: z.boolean().optional(),
timeout: z.number().optional(),
trial: z.boolean().optional()
}).optional()
});
var dblclickActionSchema = withLocator.extend({
action: z.literal("dblclick"),
options: interactOpts
});
var fillActionSchema = withLocator.extend({
action: z.literal("fill"),
value: z.string(),
options: z.object({
force: z.boolean().optional(),
timeout: z.number().optional(),
noWaitAfter: z.boolean().optional()
}).optional()
});
var typeActionSchema = withLocator.extend({
action: z.literal("type"),
value: z.string(),
options: z.object({ delay: z.number().optional(), timeout: z.number().optional() }).optional()
});
var pressActionSchema = withLocator.extend({
action: z.literal("press"),
key: z.string().describe("Key or chord, e.g. 'Enter', 'Tab', 'Control+a'"),
options: z.object({ delay: z.number().optional(), timeout: z.number().optional() }).optional()
});
var checkActionSchema = withLocator.extend({
action: z.literal("check"),
options: interactOpts
});
var uncheckActionSchema = withLocator.extend({
action: z.literal("uncheck"),
options: interactOpts
});
var selectOptionActionSchema = withLocator.extend({
action: z.literal("selectOption"),
value: z.union([z.string(), z.array(z.string())]),
options: z.object({ force: z.boolean().optional(), timeout: z.number().optional() }).optional()
});
var hoverActionSchema = withLocator.extend({
action: z.literal("hover"),
options: interactOpts
});
var focusActionSchema = withLocator.extend({
action: z.literal("focus"),
options: timeoutOpts
});
var blurActionSchema = withLocator.extend({
action: z.literal("blur"),
options: timeoutOpts
});
var clearActionSchema = withLocator.extend({
action: z.literal("clear"),
options: interactOpts
});
var scrollIntoViewActionSchema = withLocator.extend({
action: z.literal("scrollIntoView"),
options: timeoutOpts
});
var waitForActionSchema = withLocator.extend({
action: z.literal("waitFor"),
state: waitForStateEnum.optional(),
options: timeoutOpts
});
var waitForHiddenActionSchema = withLocator.extend({
action: z.literal("waitForHidden"),
options: timeoutOpts
});
var waitForSelectorActionSchema = withLocator.extend({
action: z.literal("waitForSelector"),
options: timeoutOpts
});
var setFieldValueActionSchema = withLocator.extend({
action: z.literal("setFieldValue"),
value: z.string(),
options: timeoutOpts
});
var assertFieldValueEqualsActionSchema = withLocator.extend({
action: z.literal("assertFieldValueEquals"),
value: z.string(),
options: timeoutOpts
});
var assertFieldValueContainsActionSchema = withLocator.extend({
action: z.literal("assertFieldValueContains"),
value: z.string(),
options: timeoutOpts
});
var assertVisibleSchema = withLocator.extend({
action: z.literal("assertVisible"),
options: timeoutOpts
});
var assertHiddenSchema = withLocator.extend({
action: z.literal("assertHidden"),
options: timeoutOpts
});
var assertEnabledSchema = withLocator.extend({
action: z.literal("assertEnabled"),
options: timeoutOpts
});
var assertDisabledSchema = withLocator.extend({
action: z.literal("assertDisabled"),
options: timeoutOpts
});
var assertCheckedSchema = withLocator.extend({
action: z.literal("assertChecked"),
checked: z.boolean().optional().describe("Default true; set false to assert unchecked"),
options: timeoutOpts
});
var assertTextSchema = withLocator.extend({
action: z.literal("assertText"),
value: z.string(),
options: z.object({ timeout: z.number().optional(), ignoreCase: z.boolean().optional() }).optional()
});
var assertContainsTextSchema = withLocator.extend({
action: z.literal("assertContainsText"),
value: z.string(),
options: z.object({ timeout: z.number().optional(), ignoreCase: z.boolean().optional() }).optional()
});
var assertValueSchema = withLocator.extend({
action: z.literal("assertValue"),
value: z.string(),
options: timeoutOpts
});
var assertCountSchema = withLocator.extend({
action: z.literal("assertCount"),
count: z.number(),
options: timeoutOpts
});
var assertAttributeSchema = withLocator.extend({
action: z.literal("assertAttribute"),
attribute: z.string(),
value: z.string(),
options: timeoutOpts
});
var customActionSchema = base.extend({
action: z.string(),
locator: locatorParamsSchema.optional(),
value: z.string().optional()
}).passthrough();
var knownActionsSchema = z.discriminatedUnion("action", [
navigateActionSchema,
sleepActionSchema,
goBackActionSchema,
goForwardActionSchema,
scrollActionSchema,
waitForURLActionSchema,
waitForLoadStateActionSchema,
waitForTextActionSchema,
clickCoordinatesActionSchema,
assertURLActionSchema,
assertTitleActionSchema,
screenshotActionSchema,
assertSnapshotActionSchema,
clickActionSchema,
dblclickActionSchema,
fillActionSchema,
typeActionSchema,
pressActionSchema,
checkActionSchema,
uncheckActionSchema,
selectOptionActionSchema,
hoverActionSchema,
focusActionSchema,
blurActionSchema,
clearActionSchema,
scrollIntoViewActionSchema,
waitForActionSchema,
waitForHiddenActionSchema,
waitForSelectorActionSchema,
assertVisibleSchema,
assertHiddenSchema,
assertEnabledSchema,
assertDisabledSchema,
assertCheckedSchema,
assertTextSchema,
assertContainsTextSchema,
assertValueSchema,
assertCountSchema,
assertAttributeSchema,
setFieldValueActionSchema,
assertFieldValueEqualsActionSchema,
assertFieldValueContainsActionSchema
]);
var testActionSchema = z.union([knownActionsSchema, customActionSchema]);
var testStepSchema = testObjectSchema.extend({
description: z.string(),
actions: z.array(testActionSchema)
});
var testScenarioSchema = testObjectSchema.extend({
name: z.string(),
steps: z.array(testStepSchema)
});
var testRunSchema = testObjectSchema.extend({
browser: z.enum(["chrome", "firefox", "webkit"]),
host: z.string(),
scenarios: z.array(testScenarioSchema)
});
export { PlaywrightRoleOptionsSchema, PlaywrightRoleSchema, __export, __reExport, altTextLocatorSchema, labelLocatorSchema, locatorParamsSchema, nestedLocatorSchema, placeholderLocatorSchema, roleLocatorSchema, selectorLocatorSchema, testActionSchema, testIdLocatorSchema, testObjectSchema, testRunSchema, testScenarioSchema, testStepSchema, textLocatorSchema, titleLocatorSchema, xpathLocatorSchema };
//# sourceMappingURL=chunk-KTR6D2I2.mjs.map
//# sourceMappingURL=chunk-KTR6D2I2.mjs.map