playwright-json-runner
Version:
Extends Playwright to run tests using JSON-based test definitions.
198 lines (193 loc) • 5.12 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"
]);
// src/schemas/locators/locator-parameters.ts
var selectorStrategyParamsSchema = z.object({
type: z.literal("selector"),
value: z.string()
});
var roleStrategyParamsSchema = z.object({
type: z.literal("role"),
value: z.object({
role: PlaywrightRoleSchema,
options: PlaywrightRoleOptionsSchema
}).describe("the values for role are role name and then optiosn object e.g. {value: {role: 'link', options: {name: 'sign on'}}}")
});
var testIdStrategyParamsSchema = z.object({
type: z.literal("testId"),
value: z.string()
});
var textStrategyParamsSchema = z.object({
type: z.literal("text"),
value: z.string()
});
var locatorParamsSchema;
var nestedStrategyParamsSchema = z.lazy(
() => z.object({
type: z.literal("nested"),
parent: locatorParamsSchema,
child: locatorParamsSchema
})
);
locatorParamsSchema = z.union([
selectorStrategyParamsSchema,
roleStrategyParamsSchema,
testIdStrategyParamsSchema,
textStrategyParamsSchema,
nestedStrategyParamsSchema
]);
var actionTypeSchema = z.enum([
"setfieldvalue",
"click",
"navigate",
"expect",
"assertFieldValueEquals",
"assertFieldValueContains",
"assertElementExists",
"sleep"
]).describe("The type of action to perform");
var testActionSchema = testObjectSchema.extend({
type: actionTypeSchema,
value: z.string().optional(),
playwrightFunction: z.string().optional().describe("on verify steps, the expect function to use (e.g. toBe is the playwright equivalent to: expect(locator).toBe(value)"),
locator: locatorParamsSchema.optional().describe("Locator to use for the action"),
selector: z.string().optional().describe("Selector to use for the action (replaces locator)")
});
var testStepSchema = testObjectSchema.extend({
description: z.string(),
actions: z.array(testActionSchema)
});
// src/schemas/test-scenario.ts
var testScenarioSchema = testObjectSchema.extend({
name: z.string(),
steps: z.array(testStepSchema)
});
// src/schemas/test-run.ts
var testRunSchema = testObjectSchema.extend({
browser: z.enum(["chrome", "firefox", "webkit"]),
host: z.string(),
scenarios: z.array(testScenarioSchema)
});
export { __export, __reExport, testRunSchema };
//# sourceMappingURL=chunk-JCIGD4K4.mjs.map
//# sourceMappingURL=chunk-JCIGD4K4.mjs.map