Skip to content

Commit ea64fca

Browse files
committed
Tests
1 parent b36fb74 commit ea64fca

File tree

3 files changed

+41
-18
lines changed

3 files changed

+41
-18
lines changed

tests/example.spec.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/helpers/login.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Browser, Page, BrowserContext } from "@playwright/test";
2+
import * as fs from "node:fs";
3+
4+
export async function loginToWordPress(browser: Browser, storagePath = "tests-browser-state.json") {
5+
// Skip login if state already exists
6+
if (fs.existsSync(storagePath)) return;
7+
8+
const context = await browser.newContext();
9+
const page = await context.newPage();
10+
11+
await page.goto("/wp-login.php");
12+
await page.fill("#user_login", "your-username");
13+
await page.fill("#user_pass", "your-password");
14+
await page.click("#wp-submit");
15+
16+
await page.waitForURL("**/wp-admin/**");
17+
18+
await context.storageState({ path: storagePath });
19+
await context.close();
20+
}
21+
22+
export async function createLoggedInPage(
23+
browser: Browser,
24+
storagePath = "storage/wordpress-auth.json"
25+
): Promise<{ context: BrowserContext; page: Page }> {
26+
const context = await browser.newContext({ storageState: storagePath });
27+
const page = await context.newPage();
28+
return { context, page };
29+
}

tests/wordpress-spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { test, expect } from "@playwright/test";
2+
3+
test.beforeAll(async ({ browser }) => {
4+
await loginToWordPress(browser);
5+
});
6+
7+
test("Access dashboard", async ({ browser }) => {
8+
const { page } = await createLoggedInPage(browser);
9+
10+
await page.goto("/wp-admin/");
11+
await expect(page).toHaveURL(/wp-admin/);
12+
});

0 commit comments

Comments
 (0)