Add Playwright tests for live site authentication and race page loading
- Introduced `auth.setup.js` to handle authentication against the live site and store the session state. - Created `live-race.spec.js` to test loading a live race page with an authenticated session, including cookie validation. - Added utility functions in `live-site-test-utils.js` for managing authentication, dismissing cookie banners, and checking UI states. - Included a temporary JSON file for live state inspection. - Updated deployment manifest to reflect new and modified files. - Implemented `_inc_faceai_identity.jsp` for managing FaceAI identity cookies and included it in relevant JSP files. - Added language management JavaScript in `lang.js`. - Adjusted `fotoCR-en.jsp` and `fotoCR.jsp` to include the FaceAI identity logic. - Created a tarball for staging deployment.
This commit is contained in:
parent
9f56dfba1d
commit
1d1bccdae6
23 changed files with 4358 additions and 11 deletions
12
faceai/tests/live-site/auth.setup.js
Normal file
12
faceai/tests/live-site/auth.setup.js
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
const { test } = require('@playwright/test');
|
||||
const {
|
||||
AUTH_FILE,
|
||||
ensureAuthDirectory,
|
||||
performLiveLogin
|
||||
} = require('./live-site-test-utils');
|
||||
|
||||
test('authenticate against the live site', async ({ page }) => {
|
||||
ensureAuthDirectory();
|
||||
await performLiveLogin(page);
|
||||
await page.context().storageState({ path: AUTH_FILE });
|
||||
});
|
||||
33
faceai/tests/live-site/live-race.spec.js
Normal file
33
faceai/tests/live-site/live-race.spec.js
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
const { test, expect } = require('@playwright/test');
|
||||
const {
|
||||
LIVE_SITE_RACE_URL,
|
||||
dismissCookieBanner,
|
||||
expectRacePageLoaded,
|
||||
performLiveLogin,
|
||||
waitForLoggedInUi
|
||||
} = require('./live-site-test-utils');
|
||||
|
||||
test('loads a live race page with an authenticated session', async ({ page }) => {
|
||||
await page.goto(LIVE_SITE_RACE_URL, { waitUntil: 'domcontentloaded' });
|
||||
await dismissCookieBanner(page);
|
||||
|
||||
try {
|
||||
await waitForLoggedInUi(page);
|
||||
} catch (error) {
|
||||
await performLiveLogin(page);
|
||||
await page.goto(LIVE_SITE_RACE_URL, { waitUntil: 'domcontentloaded' });
|
||||
await dismissCookieBanner(page);
|
||||
await waitForLoggedInUi(page);
|
||||
}
|
||||
|
||||
await expectRacePageLoaded(page);
|
||||
await expect(page.locator('h1')).toContainText(/HALF MARATHON FIRENZE|Competitions|Gare/i);
|
||||
|
||||
const cookies = await page.context().cookies(LIVE_SITE_RACE_URL);
|
||||
const faceAiIdentityCookie = cookies.find((cookie) => cookie.name === 'rus_faceai_identity');
|
||||
|
||||
expect(faceAiIdentityCookie, 'Expected the race page to mint the FaceAI identity cookie for the authenticated session.').toBeTruthy();
|
||||
expect(faceAiIdentityCookie.httpOnly).toBe(true);
|
||||
expect(faceAiIdentityCookie.secure).toBe(true);
|
||||
expect(faceAiIdentityCookie.value).toMatch(/\./);
|
||||
});
|
||||
92
faceai/tests/live-site/live-site-test-utils.js
Normal file
92
faceai/tests/live-site/live-site-test-utils.js
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { expect } = require('@playwright/test');
|
||||
|
||||
const LIVE_SITE_BASE_URL = process.env.LIVE_SITE_BASE_URL || 'https://www.regalamiunsorriso.it';
|
||||
const LIVE_SITE_LOGIN_URL = process.env.LIVE_SITE_LOGIN_URL || `${LIVE_SITE_BASE_URL}/login_clienti-it.html`;
|
||||
const LIVE_SITE_RACE_URL = process.env.LIVE_SITE_RACE_URL || `${LIVE_SITE_BASE_URL}/42%20HALF%20MARATHON%20FIRENZE_gara-1018545---96-1.html`;
|
||||
const LIVE_SITE_USERNAME = process.env.LIVE_SITE_USERNAME || '';
|
||||
const LIVE_SITE_PASSWORD = process.env.LIVE_SITE_PASSWORD || '';
|
||||
const AUTH_FILE = path.join(__dirname, '.auth', 'user.json');
|
||||
|
||||
function ensureAuthDirectory() {
|
||||
fs.mkdirSync(path.dirname(AUTH_FILE), { recursive: true });
|
||||
}
|
||||
|
||||
function requireCredentials() {
|
||||
if (!LIVE_SITE_USERNAME || !LIVE_SITE_PASSWORD) {
|
||||
throw new Error('LIVE_SITE_USERNAME and LIVE_SITE_PASSWORD must be set before running the live-site Playwright suite.');
|
||||
}
|
||||
}
|
||||
|
||||
async function dismissCookieBanner(page) {
|
||||
const cookieButton = page.getByRole('button', { name: /^(Accetto|Accept)$/i });
|
||||
if (await cookieButton.count()) {
|
||||
await cookieButton.first().click({ timeout: 5000 }).catch(() => {});
|
||||
return;
|
||||
}
|
||||
|
||||
const fallbackButton = page.locator('.cc-btn, .cc-dismiss, .cc-allow').filter({ hasText: /Accetto|Accept/i });
|
||||
if (await fallbackButton.count()) {
|
||||
await fallbackButton.first().click({ timeout: 5000 }).catch(() => {});
|
||||
}
|
||||
}
|
||||
|
||||
function loginSubmitLocator(page) {
|
||||
return page.locator('a.btn').filter({ hasText: /Accedi|Sign in/i }).first();
|
||||
}
|
||||
|
||||
async function performLiveLogin(page) {
|
||||
requireCredentials();
|
||||
|
||||
await page.goto(LIVE_SITE_LOGIN_URL, { waitUntil: 'domcontentloaded' });
|
||||
await dismissCookieBanner(page);
|
||||
await page.locator('#login').fill(LIVE_SITE_USERNAME);
|
||||
await page.locator('#pwd').fill(LIVE_SITE_PASSWORD);
|
||||
await loginSubmitLocator(page).click();
|
||||
await waitForLoggedInUi(page);
|
||||
}
|
||||
|
||||
async function waitForLoggedInUi(page) {
|
||||
const accountMenu = page.locator('#navbarDropdownMenuLink');
|
||||
const accountLink = page.locator('a[href*="dettaglio_clienti"]');
|
||||
const logoutLink = page.locator('a[href*="user_logout"]');
|
||||
|
||||
await expect.poll(async () => {
|
||||
if (await accountMenu.count() && await accountMenu.first().isVisible().catch(() => false)) {
|
||||
return 'account-menu';
|
||||
}
|
||||
if (await accountLink.count() && await accountLink.first().isVisible().catch(() => false)) {
|
||||
return 'account-link';
|
||||
}
|
||||
if (await logoutLink.count() && await logoutLink.first().isVisible().catch(() => false)) {
|
||||
return 'logout-link';
|
||||
}
|
||||
return '';
|
||||
}, {
|
||||
timeout: 30 * 1000,
|
||||
message: 'Expected the logged-in account UI to appear after authenticating.'
|
||||
}).not.toBe('');
|
||||
}
|
||||
|
||||
async function expectRacePageLoaded(page) {
|
||||
await expect(page.locator('form[onsubmit="return searching()"]')).toBeVisible();
|
||||
await expect(page.locator('#id_gara')).toHaveValue(/\d+/);
|
||||
await expect(page.locator('script[src*="_js/rus-ecom-240621.js"]')).toHaveCount(1);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
AUTH_FILE,
|
||||
LIVE_SITE_BASE_URL,
|
||||
LIVE_SITE_LOGIN_URL,
|
||||
LIVE_SITE_PASSWORD,
|
||||
LIVE_SITE_RACE_URL,
|
||||
LIVE_SITE_USERNAME,
|
||||
dismissCookieBanner,
|
||||
ensureAuthDirectory,
|
||||
expectRacePageLoaded,
|
||||
loginSubmitLocator,
|
||||
performLiveLogin,
|
||||
requireCredentials,
|
||||
waitForLoggedInUi
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue