first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
import type { BrowserContext } from '@playwright/test';
|
||||
|
||||
import { setContextSettings } from '../config/intercepts';
|
||||
import type { n8nPage } from '../pages/n8nPage';
|
||||
import { TestError, type TestRequirements } from '../Types';
|
||||
|
||||
export async function setupTestRequirements(
|
||||
n8n: n8nPage,
|
||||
context: BrowserContext,
|
||||
requirements: TestRequirements,
|
||||
): Promise<void> {
|
||||
// 0. Setup browser storage before creating a new page
|
||||
if (requirements.storage) {
|
||||
await context.addInitScript((storage) => {
|
||||
// Set localStorage items
|
||||
for (const [key, value] of Object.entries(storage)) {
|
||||
window.localStorage.setItem(key, value);
|
||||
}
|
||||
}, requirements.storage);
|
||||
}
|
||||
|
||||
// 1. Setup frontend settings override
|
||||
if (requirements.config?.settings) {
|
||||
// Store settings for this context
|
||||
setContextSettings(context, requirements.config.settings);
|
||||
}
|
||||
|
||||
// 2. Setup feature flags
|
||||
if (requirements.config?.features) {
|
||||
for (const [feature, enabled] of Object.entries(requirements.config.features)) {
|
||||
if (enabled) {
|
||||
await n8n.api.enableFeature(feature);
|
||||
} else {
|
||||
await n8n.api.disableFeature(feature);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Setup API intercepts
|
||||
if (requirements.intercepts) {
|
||||
for (const config of Object.values(requirements.intercepts)) {
|
||||
await n8n.page.route(config.url, async (route) => {
|
||||
await route.fulfill({
|
||||
status: config.status ?? 200,
|
||||
contentType: config.contentType ?? 'application/json',
|
||||
body:
|
||||
typeof config.response === 'string' ? config.response : JSON.stringify(config.response),
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Setup workflows
|
||||
if (requirements.workflow) {
|
||||
const entries =
|
||||
typeof requirements.workflow === 'string'
|
||||
? [[requirements.workflow, requirements.workflow]]
|
||||
: Object.entries(requirements.workflow);
|
||||
|
||||
for (const [name, workflowData] of entries) {
|
||||
try {
|
||||
// Import workflow using the n8n page object
|
||||
await n8n.navigate.toWorkflow('new');
|
||||
await n8n.canvas.importWorkflow(name, workflowData);
|
||||
} catch (error) {
|
||||
throw new TestError(`Failed to create workflow ${name}: ${String(error)}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user