Files
prowler/ui/tests/scans/scans.spec.ts
T
StylusFrost f58030f68e test(ui): add scans E2E test suite and enhance scans functionality
- Introduced a new scans test suite to validate the on-demand scan execution flow.
- Added methods in the ScansPage class for selecting providers, filling scan aliases, and verifying scan launches.
- Updated the ProvidersPage class to include a method for adding AWS providers.
- Created comprehensive end-to-end tests for executing scans, including necessary preconditions and environment variable checks.
- Documented the new test cases and flow in the scans markdown file.
2025-11-03 19:06:52 +01:00

71 lines
2.2 KiB
TypeScript

import { test, expect } from "@playwright/test";
import { ScansPage } from "./scans-page";
import { ProvidersPage } from "../providers/providers-page";
// Scans E2E suite scaffold
test.describe("Scans", () => {
test.describe.serial("Execute Scans", () => {
// Scans page object
let scansPage: ScansPage;
// Use scans-specific authenticated user
test.use({ storageState: "playwright/.auth/admin_user.json" });
// Before each scans test, ensure an AWS provider exists using admin context
test.beforeEach(async ({ page }) => {
// Create scans page object
const providersPage = new ProvidersPage(page);
// Test data from environment variables
const accountId = process.env.E2E_AWS_PROVIDER_ACCOUNT_ID;
const accessKey = process.env.E2E_AWS_PROVIDER_ACCESS_KEY;
const secretKey = process.env.E2E_AWS_PROVIDER_SECRET_KEY;
if (!accountId || !accessKey || !secretKey) {
throw new Error(
"E2E_AWS_PROVIDER_ACCOUNT_ID, E2E_AWS_PROVIDER_ACCESS_KEY, and E2E_AWS_PROVIDER_SECRET_KEY environment variables are not set",
);
}
// Clean up existing provider to ensure clean test state
await providersPage.deleteProviderIfExists(accountId);
// Add AWS provider
await providersPage.AddAWSProvider(accountId, accessKey, secretKey);
});
test(
"should execute on demand scan",
{
tag: ["@e2e", "@scans", "@critical", "@serial", "@SCAN-E2E-001"],
},
async ({ page }) => {
const accountId = process.env.E2E_AWS_PROVIDER_ACCOUNT_ID;
if (!accountId) {
throw new Error(
"E2E_AWS_PROVIDER_ACCOUNT_ID environment variable is not set",
);
}
scansPage = new ScansPage(page);
await scansPage.goto();
// Select provider by UID (accountId)
await scansPage.selectProviderByUID(accountId);
// Complete scan alias
await scansPage.fillScanAlias("E2E Test Scan - On Demand");
// Press start now button
await scansPage.clickStartNowButton();
// Verify the scan was launched
await scansPage.verifyScanLaunched("E2E Test Scan - On Demand");
},
);
});
});