mirror of
https://github.com/inventree/InvenTree.git
synced 2026-03-25 05:38:41 +00:00
[bug] Playwright fixes (#9933)
* Fixes for playwright testing - Ensure cookies are completely cleaned between sessions - Fix base URL based on vite command - Fix samesite cookie mode - Prevent /static/ files being served by web server on :8000 * Remove gunicorn option * Readjust base URL * Simplify doCachedLogin * Fix logic func * Revert webserver cmd * Set base URL in playwrightconfig file * Fix URL checks * Fix URL definitions * adjust playwright base URL * Tweak for URL helper * Further login tweaks * Tweak test * wait for API before starting tests * Handle error * Adjust login functions * Don't use gunicorn - But still use the webserver to serve static files in CI * Enhanced login functions * Tweak login tests * Fix broken test * Flipped the flippies
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { type FullConfig, chromium } from '@playwright/test';
|
||||
import { type FullConfig, chromium, request } from '@playwright/test';
|
||||
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { apiUrl } from '../tests/defaults';
|
||||
import { doCachedLogin } from '../tests/login';
|
||||
|
||||
async function globalSetup(config: FullConfig) {
|
||||
@@ -18,27 +19,53 @@ async function globalSetup(config: FullConfig) {
|
||||
});
|
||||
}
|
||||
|
||||
// Perform login for each user
|
||||
const browser = await chromium.launch();
|
||||
const baseUrl = config.projects[0].use?.baseURL || 'http://localhost:5173';
|
||||
const apiContext = await request.newContext();
|
||||
|
||||
await doCachedLogin(browser, {
|
||||
let tries = 100;
|
||||
let success = false;
|
||||
|
||||
// Wait for the web server to actually be started
|
||||
while (tries--) {
|
||||
// Perform GET request to the API URL
|
||||
const response = await apiContext
|
||||
.get(apiUrl, { timeout: 5000 })
|
||||
.catch(() => {});
|
||||
|
||||
if (!!response && response?.ok() && response?.status() === 200) {
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
console.log(`... waiting for API to be available at ${apiUrl}`);
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
throw new Error(`Failed to connect to API at ${apiUrl} after 100 attempts`);
|
||||
}
|
||||
|
||||
// Perform login for each user (each in a separate browser instance)
|
||||
await doCachedLogin(await chromium.launch(), {
|
||||
username: 'admin',
|
||||
password: 'inventree'
|
||||
password: 'inventree',
|
||||
baseUrl: baseUrl
|
||||
});
|
||||
|
||||
await doCachedLogin(browser, {
|
||||
await doCachedLogin(await chromium.launch(), {
|
||||
username: 'allaccess',
|
||||
password: 'nolimits'
|
||||
password: 'nolimits',
|
||||
baseUrl: baseUrl
|
||||
});
|
||||
|
||||
await doCachedLogin(browser, {
|
||||
await doCachedLogin(await chromium.launch(), {
|
||||
username: 'reader',
|
||||
password: 'readonly'
|
||||
password: 'readonly',
|
||||
baseUrl: baseUrl
|
||||
});
|
||||
|
||||
await doCachedLogin(browser, {
|
||||
await doCachedLogin(await chromium.launch(), {
|
||||
username: 'steven',
|
||||
password: 'wizardstaff'
|
||||
password: 'wizardstaff',
|
||||
baseUrl: baseUrl
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user