2024-08-28 14:18:04 -07:00
|
|
|
const fs = require("fs");
|
|
|
|
const path = require("path");
|
|
|
|
const serverUrl = require("../../config/playwright.config.js").url;
|
|
|
|
|
|
|
|
const dbPath = "./../../data/playwright-test/kuma.db";
|
|
|
|
|
2023-12-17 03:02:22 -08:00
|
|
|
/**
|
|
|
|
* @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();
|
2024-01-13 13:35:11 -08:00
|
|
|
await page.getByRole("button", { name: "Log in" }).click();
|
2023-12-17 03:02:22 -08:00
|
|
|
await page.isVisible("text=Add New Monitor");
|
|
|
|
}
|
2024-08-28 14:18:04 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines if the SQLite database has been created. This indicates setup has completed.
|
|
|
|
* @returns {boolean} True if exists
|
|
|
|
*/
|
|
|
|
export function getSqliteDatabaseExists() {
|
|
|
|
return fs.existsSync(path.resolve(__dirname, dbPath));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Makes a request to the server to take a snapshot of the SQLite database.
|
|
|
|
* @param {Page|null} page Page
|
|
|
|
* @returns {Promise<Response>} Promise of response from snapshot request.
|
|
|
|
*/
|
|
|
|
export async function takeSqliteSnapshot(page = null) {
|
|
|
|
if (page) {
|
|
|
|
return page.goto("./_e2e/take-sqlite-snapshot");
|
|
|
|
} else {
|
|
|
|
return fetch(`${serverUrl}/_e2e/take-sqlite-snapshot`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Makes a request to the server to restore the snapshot of the SQLite database.
|
|
|
|
* @returns {Promise<Response>} Promise of response from restoration request.
|
|
|
|
*/
|
|
|
|
export async function restoreSqliteSnapshot() {
|
|
|
|
return fetch(`${serverUrl}/_e2e/restore-sqlite-snapshot`);
|
|
|
|
}
|