pierrejeambrun commented on code in PR #58548:
URL: https://github.com/apache/airflow/pull/58548#discussion_r2571423336


##########
dev/breeze/src/airflow_breeze/commands/common_options.py:
##########
@@ -565,3 +565,110 @@ def _normalize_platform(ctx: click.core.Context, param: 
click.core.Option, value
     callback=_normalize_platform,
     type=BetterChoice(SINGLE_PLATFORMS),
 )
+
+
+# UI E2E Testing Options
+
+option_airflow_ui_base_url = click.option(
+    "--airflow-ui-base-url",
+    help="Base URL for Airflow UI during e2e tests",
+    default="http://localhost:28080";,
+    show_default=True,
+    envvar="AIRFLOW_UI_BASE_URL",
+)
+
+option_browser = click.option(
+    "--browser",
+    help="Browser to use for e2e tests",
+    type=BetterChoice(["chromium", "firefox", "webkit", "all"]),
+    default="chromium",
+    show_default=True,
+)

Review Comment:
   By default, it should run accross all 3 browsers I think. Not just chormium.



##########
airflow-core/src/airflow/ui/tests/e2e/pages/DagsPage.ts:
##########
@@ -0,0 +1,184 @@
+/*!
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import type { Locator, Page } from "@playwright/test";
+import { BasePage } from "tests/e2e/pages/BasePage";
+
+/**
+ * DAGs Page Object
+ */
+export class DagsPage extends BasePage {
+  // Page URLs
+  public static get dagsListUrl(): string {
+    return "/dags";
+  }
+
+  // Core page elements
+  public readonly confirmButton: Locator;
+  public readonly dagsTable: Locator;
+  public readonly stateElement: Locator;
+  public readonly triggerButton: Locator;
+
+  public constructor(page: Page) {
+    super(page);
+    this.dagsTable = page.locator('div:has(a[href*="/dags/"])');
+    this.triggerButton = page.locator('button[aria-label="Trigger 
Dag"]:has-text("Trigger")');
+    this.confirmButton = page.locator('button:has-text("Trigger")').nth(1);
+    this.stateElement = page.locator('*:has-text("State") + *').first();
+  }
+
+  // URL builders for dynamic paths
+  public static getDagDetailUrl(dagName: string): string {
+    return `/dags/${dagName}`;
+  }
+
+  public static getDagRunDetailsUrl(dagName: string, dagRunId: string): string 
{
+    return `/dags/${dagName}/runs/${dagRunId}/details`;
+  }
+
+  /**
+   * Navigate to DAGs list page
+   */
+  public async navigate(): Promise<void> {
+    await this.navigateTo(DagsPage.dagsListUrl);
+  }
+
+  /**
+   * Navigate to DAG detail page
+   */
+  public async navigateToDagDetail(dagName: string): Promise<void> {
+    await this.navigateTo(DagsPage.getDagDetailUrl(dagName));
+  }
+
+  /**
+   * Trigger a DAG run
+   */
+  public async triggerDag(dagName: string): Promise<string | null> {
+    await this.navigateToDagDetail(dagName);
+    await this.triggerButton.waitFor({ state: "visible", timeout: 10_000 });
+    await this.triggerButton.click();
+    const dagRunId = await this.handleTriggerDialog();
+
+    return dagRunId;
+  }
+
+  public async verifyDagRunStatus(dagName: string, dagRunId: string | null): 
Promise<void> {
+    // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
+    if (dagRunId === null || dagRunId === undefined || dagRunId === "") {
+      return;
+    }
+
+    await this.page.goto(DagsPage.getDagRunDetailsUrl(dagName, dagRunId), {
+      timeout: 15_000,
+      waitUntil: "domcontentloaded",
+    });
+
+    await this.page.waitForTimeout(2000);
+
+    const maxWaitTime = 5 * 60 * 1000;
+    const checkInterval = 10_000;
+    const startTime = Date.now();
+
+    while (Date.now() - startTime < maxWaitTime) {
+      const currentStatus = await this.getCurrentDagRunStatus();
+
+      if (currentStatus === "success") {
+        return;
+      } else if (currentStatus === "failed") {
+        throw new Error(`DAG run failed: ${dagRunId}`);
+      }
+
+      await this.page.waitForTimeout(checkInterval);
+
+      await this.page.reload({ waitUntil: "domcontentloaded" });
+
+      await this.page.waitForTimeout(2000);
+    }
+
+    throw new Error(`DAG run did not complete within 5 minutes: ${dagRunId}`);
+  }
+
+  private async getCurrentDagRunStatus(): Promise<string> {
+    try {
+      const statusText = await this.stateElement.textContent().catch(() => "");
+      const status = statusText?.trim() ?? "";
+
+      switch (status) {
+        case "Failed":
+          return "failed";
+        case "Queued":
+          return "queued";
+        case "Running":
+          return "running";
+        case "Success":
+          return "success";
+        default:
+          return "unknown";
+      }
+    } catch {
+      return "unknown";
+    }
+  }
+
+  private async handleTriggerDialog(): Promise<string | null> {
+    await this.page.waitForTimeout(1000);
+
+    const responsePromise = this.page
+
+      .waitForResponse(
+        (response) => {
+          const url = response.url();
+
+          const method = response.request().method();
+
+          return (
+            method === "POST" && Boolean(url.includes("dagRuns")) && 
Boolean(!url.includes("hitlDetails"))
+          );
+        },
+        { timeout: 10_000 },
+      )
+
+      .catch(() => undefined);
+
+    await this.confirmButton.waitFor({ state: "visible", timeout: 8000 });
+
+    await this.page.waitForTimeout(2000);
+    await this.confirmButton.click({ force: true });
+
+    const apiResponse = await responsePromise;
+
+    if (apiResponse) {
+      try {
+        const responseBody = await apiResponse.text();
+        // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
+        const responseJson = JSON.parse(responseBody);
+
+        // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
+        if (Boolean(responseJson.dag_run_id)) {
+          // eslint-disable-next-line @typescript-eslint/no-unsafe-return, 
@typescript-eslint/no-unsafe-member-access
+          return responseJson.dag_run_id;
+        }
+      } catch {

Review Comment:
   Here I think we can use the `DagRunResponse` object for typing. 
   
   This will help remove all those unsafe assignment.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to