Repository: apache/airflow
File: airflow-core/src/airflow/ui/tests/e2e/specs/backfill.spec.ts (TypeScript)

Code before:
  test("verify date range selection (start date, end date)", async ({ page }) => {
    const fromDate = getPastDate(1);
    const toDate = getPastDate(7);
    const backfillPage = new BackfillPage(page);

    await backfillPage.navigateToDagDetail(testDagId);
    await backfillPage.openBackfillDialog();
    await backfillPage.backfillFromDateInput.fill(fromDate);
    await backfillPage.backfillToDateInput.fill(toDate);
    await expect(backfillPage.backfillDateError).toBeVisible();
  });
});

test.describe("Backfill pause, resume, and cancel controls", () => {
  test.describe.configure({ mode: "serial" });
  test.setTimeout(180_000);

  const testDagId = testConfig.testDag.id;
  const controlFromDate = getPastDate(15);
  const controlToDate = getPastDate(14);

  let backfillPage: BackfillPage;

  test.beforeEach(async ({ page }) => {
    backfillPage = new BackfillPage(page);

    // Cancel any existing backfill before creating a new one
    await backfillPage.navigateToDagDetail(testDagId);
    try {
      await backfillPage.clickCancelButton();
    } catch {
      // No active backfill to cancel
    }

    await backfillPage.createBackfill(testDagId, {
      fromDate: controlFromDate,
      reprocessBehavior: "All Runs",
      toDate: controlToDate,
    });

    await backfillPage.navigateToBackfillsTab(testDagId);
  });

  test.afterEach(async () => {
    try {
      await backfillPage.clickCancelButton();
    } catch {
    }
  });

  test("verify pause and resume backfill", async () => {

Review comment (suggestion):
Instead of empty try catch should we check visibility before clicking.
```suggestion
test.beforeEach(async ({ page }) => {
  backfillPage = new BackfillPage(page);
  await backfillPage.navigateToDagDetail(testDagId);
  
  // Cancel any existing backfill if visible
  if (await backfillPage.cancelButton.isVisible()) {
    await backfillPage.clickCancelButton();
  }
```

Code after:

    await backfillPage.navigateToDagDetail(testDagId);
    await backfillPage.openBackfillDialog();
    await backfillPage.backfillFromDateInput.fill(fromDate);
    await backfillPage.backfillToDateInput.fill(toDate);
    await expect(backfillPage.backfillDateError).toBeVisible();
  });
});

test.describe("Backfill pause, resume, and cancel controls", () => {
  test.describe.configure({ mode: "serial" });
  test.setTimeout(180_000);

  const testDagId = testConfig.testDag.id;
  const controlFromDate = getPastDate(90);
  const controlToDate = getPastDate(30);

  let backfillPage: BackfillPage;

  test.beforeEach(async ({ page }) => {
    backfillPage = new BackfillPage(page);
    await backfillPage.navigateToDagDetail(testDagId);

    if (await backfillPage.cancelButton.isVisible({ timeout: 5000 }).catch(() => false)) {
      await backfillPage.clickCancelButton();
    }

    await backfillPage.createBackfill(testDagId, {
      fromDate: controlFromDate,
      reprocessBehavior: "All Runs",
      toDate: controlToDate,
    });

    await expect(async () => {
      await backfillPage.page.reload();
      await expect(backfillPage.triggerButton).toBeVisible({ timeout: 10_000 });
      await expect(backfillPage.pauseButton).toBeVisible({ timeout: 5000 });
    }).toPass({ timeout: 60_000 });
  });

  test.afterEach(async () => {
    await backfillPage.navigateToDagDetail(testDagId);
    if (await backfillPage.cancelButton.isVisible({ timeout: 5000 }).catch(() => false)) {
      await backfillPage.clickCancelButton();
    }
  });

  test("verify pause and resume backfill", async () => {
    await backfillPage.clickPauseButton();
    expect(await backfillPage.isBackfillPaused()).toBe(true);