feat: initial Playwright smoke suite
20 tests across 5 files covering all plugin surfaces on staging: - Homepage load and PHP fatal detection - Reconstitution Calculator shortcode + math - Peptide Search AI widget + AJAX response - Admin: all plugins active, PSA + PRAutoBlogger settings pages - REST API: prc/v1/presets, peptides/v1/search, compounds, CPT types Staging shortcode pages: /reconstitution-calculator/ - [prc_calculator] /search-peptides/ - [peptide_search] /peptide-directory/ - [peptide_directory] GHA workflow: smoke.yml supports manual dispatch + workflow_call for use as a deploy gate from plugin repos.
This commit is contained in:
42
global.setup.ts
Executable file
42
global.setup.ts
Executable file
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* global.setup.ts
|
||||
*
|
||||
* What: Authenticates to WordPress admin once and persists the session to disk.
|
||||
* Who triggers it: Playwright "setup" project, runs before all smoke tests.
|
||||
* Dependencies: WP_ADMIN_USER and WP_ADMIN_PASSWORD env vars.
|
||||
*
|
||||
* The saved auth state (playwright/.auth/admin.json) is reused by the
|
||||
* "chromium" project so individual tests don't each incur a login round-trip.
|
||||
*/
|
||||
|
||||
import { test as setup, expect } from '@playwright/test';
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
|
||||
const AUTH_FILE = path.join(__dirname, 'playwright/.auth/admin.json');
|
||||
|
||||
setup('authenticate as WP admin', async ({ page }) => {
|
||||
const user = process.env.WP_ADMIN_USER;
|
||||
const password = process.env.WP_ADMIN_PASSWORD;
|
||||
|
||||
if (!user || !password) {
|
||||
throw new Error(
|
||||
'WP_ADMIN_USER and WP_ADMIN_PASSWORD must be set in .env or CI secrets'
|
||||
);
|
||||
}
|
||||
|
||||
// Ensure directory exists
|
||||
fs.mkdirSync(path.dirname(AUTH_FILE), { recursive: true });
|
||||
|
||||
await page.goto('/wp-login.php');
|
||||
await page.fill('#user_login', user);
|
||||
await page.fill('#user_pass', password);
|
||||
await page.click('#wp-submit');
|
||||
|
||||
// Wait for successful redirect to wp-admin dashboard
|
||||
await expect(page).toHaveURL(/wp-admin/, { timeout: 20_000 });
|
||||
await expect(page.locator('#wpadminbar')).toBeVisible();
|
||||
|
||||
// Persist session cookies + localStorage to disk
|
||||
await page.context().storageState({ path: AUTH_FILE });
|
||||
});
|
||||
Reference in New Issue
Block a user