diff --git a/frontend/e2e/random-jobs.spec.ts b/frontend/e2e/random-jobs.spec.ts index fe06d5f..363f665 100644 --- a/frontend/e2e/random-jobs.spec.ts +++ b/frontend/e2e/random-jobs.spec.ts @@ -18,9 +18,6 @@ test.describe("Random Jobs - E2E", () => { const counterValue = await page.locator("h1").textContent(); expect(counterValue).toMatch(/^\d+$/); - // Give the worker a moment to process the job - await page.waitForTimeout(1000); - // Step 3: Logout await page.click("text=Sign out"); await expect(page).toHaveURL("/login"); @@ -35,13 +32,12 @@ test.describe("Random Jobs - E2E", () => { await page.click('a[href="/admin/random-jobs"]'); await expect(page).toHaveURL("/admin/random-jobs"); - // Step 6: Verify the table contains at least one row - // Wait for table to load and have data - await expect(page.locator("table tbody tr")).toHaveCount(1, { timeout: 10000 }); - - // Verify the row has the regular user's email - const tableContent = await page.locator("table tbody").textContent(); - expect(tableContent).toContain(REGULAR_USER.email); + // Step 6: Poll for job outcome to appear (worker may take time to process) + // Keep refreshing until we see the regular user's email in the table + await expect(async () => { + await page.reload(); + await expect(page.locator("table tbody")).toContainText(REGULAR_USER.email); + }).toPass({ timeout: 15000, intervals: [500, 1000, 2000] }); // Verify the outcome has expected fields // Value should be a number 0-100