mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-08-09 17:29:08 +08:00
Playwright + Native Node Test Runner (#3893)
This commit is contained in:
43
test/e2e/setup.spec.js
Normal file
43
test/e2e/setup.spec.js
Normal file
@@ -0,0 +1,43 @@
|
||||
import { test } from "@playwright/test";
|
||||
import { login, screenshot } from "./util-test";
|
||||
|
||||
/*
|
||||
* Setup
|
||||
*/
|
||||
|
||||
test("setup sqlite", async ({ page }, testInfo) => {
|
||||
await page.goto("./");
|
||||
await page.getByText("SQLite").click();
|
||||
await page.getByRole("button", { name: "Next" }).click();
|
||||
await screenshot(testInfo, page);
|
||||
});
|
||||
|
||||
test("setup admin", async ({ page }, testInfo) => {
|
||||
await page.goto("./");
|
||||
await page.getByPlaceholder("Username").click();
|
||||
await page.getByPlaceholder("Username").fill("admin");
|
||||
await page.getByPlaceholder("Username").press("Tab");
|
||||
await page.getByPlaceholder("Password", { exact: true }).fill("admin123");
|
||||
await page.getByPlaceholder("Password", { exact: true }).press("Tab");
|
||||
await page.getByPlaceholder("Repeat Password").fill("admin123");
|
||||
await page.getByRole("button", { name: "Create" }).click();
|
||||
await screenshot(testInfo, page);
|
||||
});
|
||||
|
||||
/*
|
||||
* All other tests should be run after setup
|
||||
*/
|
||||
|
||||
test("login", async ({ page }, testInfo) => {
|
||||
await page.goto("./dashboard");
|
||||
await login(page);
|
||||
await screenshot(testInfo, page);
|
||||
});
|
||||
|
||||
test("logout", async ({ page }, testInfo) => {
|
||||
await page.goto("./dashboard");
|
||||
await login(page);
|
||||
await page.getByText("A", { exact: true }).click();
|
||||
await page.getByRole("button", { name: "Logout" }).click();
|
||||
await screenshot(testInfo, page);
|
||||
});
|
27
test/e2e/util-test.js
Normal file
27
test/e2e/util-test.js
Normal file
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* @param {TestInfo} testInfo Test info
|
||||
* @param {Page} page Page
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function screenshot(testInfo, page) {
|
||||
const screenshot = await page.screenshot();
|
||||
await testInfo.attach("screenshot", {
|
||||
body: screenshot,
|
||||
contentType: "image/png"
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Page} page Page
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function login(page) {
|
||||
// Login
|
||||
await page.getByPlaceholder("Username").click();
|
||||
await page.getByPlaceholder("Username").fill("admin");
|
||||
await page.getByPlaceholder("Username").press("Tab");
|
||||
await page.getByPlaceholder("Password").fill("admin123");
|
||||
await page.getByLabel("Remember me").check();
|
||||
await page.getByRole("button", { name: "Login" }).click();
|
||||
await page.isVisible("text=Add New Monitor");
|
||||
}
|
Reference in New Issue
Block a user