vatsrahul1001 commented on code in PR #60514: URL: https://github.com/apache/airflow/pull/60514#discussion_r2693055076
########## airflow-core/src/airflow/ui/tests/e2e/pages/TaskInstancesPage.ts: ########## @@ -0,0 +1,341 @@ +/*! + * 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 { expect, type Locator, type Page } from "@playwright/test"; +import { BasePage } from "tests/e2e/pages/BasePage"; + +export class TaskInstancesPage extends BasePage { + public static get taskInstancesUrl(): string { + return "/task_instances"; + } + + public readonly taskInstancesTable: Locator; + + public constructor(page: Page) { + super(page); + this.taskInstancesTable = page.locator('table, div[role="table"]'); + } + + /** + * Apply a filter by selecting a filter type and value + */ + public async applyFilter(filterName: string, filterValue: string): Promise<void> { + const addFilterButton = this.page.locator( + 'button:has-text("Filter"), button:has-text("Add Filter"), button[aria-label*="filter" i]', + ); + + await expect(addFilterButton.first()).toBeVisible({ timeout: 5000 }); + await addFilterButton.first().click(); + + const filterMenu = this.page.locator('[role="menu"], [role="menuitem"]'); + + await expect(filterMenu.first()).toBeVisible({ timeout: 5000 }); + + const filterOption = this.page.locator(`[role="menuitem"]:has-text("${filterName}")`).first(); + + await expect(filterOption).toBeVisible({ timeout: 5000 }); + await filterOption.click(); + + const filterPill = this.page.locator(`[role="combobox"], button:has-text("${filterName}:")`); + + await expect(filterPill.first()).toBeVisible({ timeout: 5000 }); + await filterPill.first().click(); + + const dropdown = this.page.locator('[role="option"], [role="listbox"]'); + + await expect(dropdown.first()).toBeVisible({ timeout: 5000 }); + + const valueOption = this.page.locator(`[role="option"]:has-text("${filterValue}")`).first(); + + await expect(valueOption).toBeVisible({ timeout: 5000 }); + await valueOption.click(); + + await this.page.waitForLoadState("networkidle"); + } + + /** + * Navigate to Task Instances page and wait for data to load + */ + public async navigate(): Promise<void> { + await this.navigateTo(TaskInstancesPage.taskInstancesUrl); + await this.page.waitForURL(/.*task_instances/, { timeout: 15_000 }); + await this.taskInstancesTable.waitFor({ state: "visible", timeout: 10_000 }); + + const dataLink = this.taskInstancesTable.locator("a[href*='/dags/']").first(); + const noDataMessage = this.page.locator('text="No Task Instances found"'); + + await expect(dataLink.or(noDataMessage)).toBeVisible({ timeout: 30_000 }); + } + + /** + * Verify pagination works correctly with offset and limit parameters + */ + public async verifyPagination(limit: number): Promise<void> { Review Comment: current implementation parses pagination text with regex which is complex and fragile. DAG Runs [PR](https://github.com/apache/airflow/issues/59309) uses a simpler approach ########## airflow-core/src/airflow/ui/tests/e2e/specs/task-instances.spec.ts: ########## @@ -0,0 +1,148 @@ +/*! + * 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 { test, expect } from "@playwright/test"; +import { AUTH_FILE, testConfig } from "playwright.config"; +import { TaskInstancesPage } from "tests/e2e/pages/TaskInstancesPage"; + +test.describe("Task Instances Page", () => { + test.setTimeout(60_000); + + let taskInstancesPage: TaskInstancesPage; + const testDagId = testConfig.testDag.id; + + test.beforeAll(async ({ browser }) => { + const context = await browser.newContext({ storageState: AUTH_FILE }); + const page = await context.newPage(); + const baseUrl = process.env.AIRFLOW_UI_BASE_URL ?? "http://localhost:8080"; + const timestamp = Date.now(); + + // Create first DAG run for success state + const runId1 = `test_ti_success_${timestamp}`; + const logicalDate1 = new Date(timestamp).toISOString(); + const triggerResponse1 = await page.request.post(`${baseUrl}/api/v2/dags/${testDagId}/dagRuns`, { + data: JSON.stringify({ + dag_run_id: runId1, + logical_date: logicalDate1, + }), + headers: { + "Content-Type": "application/json", + }, + }); + + expect(triggerResponse1.ok()).toBeTruthy(); + + // Get all task instances for the first run + const tasksResponse1 = await page.request.get( + `${baseUrl}/api/v2/dags/${testDagId}/dagRuns/${runId1}/taskInstances`, + ); + + expect(tasksResponse1.ok()).toBeTruthy(); + + const tasksData1 = (await tasksResponse1.json()) as { + task_instances: Array<{ task_id: string }>; + }; + + // Mark all tasks as success + for (const task of tasksData1.task_instances) { + const patchResponse = await page.request.patch( + `${baseUrl}/api/v2/dags/${testDagId}/dagRuns/${runId1}/taskInstances/${task.task_id}`, + { + data: JSON.stringify({ new_state: "success" }), + headers: { "Content-Type": "application/json" }, + }, + ); + + expect(patchResponse.ok()).toBeTruthy(); + } + + // Create second DAG run for failed state + const runId2 = `test_ti_failed_${timestamp}`; + const logicalDate2 = new Date(timestamp + 60_000).toISOString(); + const triggerResponse2 = await page.request.post(`${baseUrl}/api/v2/dags/${testDagId}/dagRuns`, { + data: JSON.stringify({ + dag_run_id: runId2, + logical_date: logicalDate2, + }), + headers: { + "Content-Type": "application/json", + }, + }); + + expect(triggerResponse2.ok()).toBeTruthy(); + + // Get all task instances for the second run + const tasksResponse2 = await page.request.get( + `${baseUrl}/api/v2/dags/${testDagId}/dagRuns/${runId2}/taskInstances`, + ); + + expect(tasksResponse2.ok()).toBeTruthy(); + + const tasksData2 = (await tasksResponse2.json()) as { + task_instances: Array<{ task_id: string }>; + }; + + // Mark all tasks as failed + for (const task of tasksData2.task_instances) { + const patchResponse = await page.request.patch( + `${baseUrl}/api/v2/dags/${testDagId}/dagRuns/${runId2}/taskInstances/${task.task_id}`, + { + data: JSON.stringify({ new_state: "failed" }), + headers: { "Content-Type": "application/json" }, + }, + ); + + expect(patchResponse.ok()).toBeTruthy(); + } + + await context.close(); + }); + + test.beforeEach(({ page }) => { + taskInstancesPage = new TaskInstancesPage(page); + }); + + test("verify task instances table displays data", async () => { + await taskInstancesPage.navigate(); + await taskInstancesPage.verifyTaskInstancesExist(); + }); + + test("verify task details display correctly", async () => { + await taskInstancesPage.navigate(); + await taskInstancesPage.verifyTaskDetailsDisplay(); + }); + + test("verify filtering by failed state", async () => { + await taskInstancesPage.navigate(); + await taskInstancesPage.verifyStateFiltering("Failed"); + }); + + test("verify filtering by success state", async () => { + await taskInstancesPage.navigate(); + await taskInstancesPage.verifyStateFiltering("Success"); + }); + + test("verify pagination with offset and limit", async () => { + await taskInstancesPage.verifyPagination(5); + }); + + test("verify different task states display visually distinct", async () => { Review Comment: We do not need this. Lets remove color checking ########## airflow-core/src/airflow/ui/tests/e2e/pages/TaskInstancesPage.ts: ########## @@ -0,0 +1,341 @@ +/*! + * 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 { expect, type Locator, type Page } from "@playwright/test"; +import { BasePage } from "tests/e2e/pages/BasePage"; + +export class TaskInstancesPage extends BasePage { + public static get taskInstancesUrl(): string { + return "/task_instances"; + } + + public readonly taskInstancesTable: Locator; + + public constructor(page: Page) { + super(page); + this.taskInstancesTable = page.locator('table, div[role="table"]'); + } + + /** + * Apply a filter by selecting a filter type and value + */ + public async applyFilter(filterName: string, filterValue: string): Promise<void> { Review Comment: DAG Runs [PR](https://github.com/apache/airflow/issues/59309) uses URL parameters for filtering which is simpler and more reliable. ########## airflow-core/src/airflow/ui/tests/e2e/pages/TaskInstancesPage.ts: ########## @@ -0,0 +1,341 @@ +/*! + * 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 { expect, type Locator, type Page } from "@playwright/test"; +import { BasePage } from "tests/e2e/pages/BasePage"; + +export class TaskInstancesPage extends BasePage { + public static get taskInstancesUrl(): string { + return "/task_instances"; + } + + public readonly taskInstancesTable: Locator; + + public constructor(page: Page) { + super(page); + this.taskInstancesTable = page.locator('table, div[role="table"]'); + } + + /** + * Apply a filter by selecting a filter type and value + */ + public async applyFilter(filterName: string, filterValue: string): Promise<void> { + const addFilterButton = this.page.locator( + 'button:has-text("Filter"), button:has-text("Add Filter"), button[aria-label*="filter" i]', + ); + + await expect(addFilterButton.first()).toBeVisible({ timeout: 5000 }); + await addFilterButton.first().click(); + + const filterMenu = this.page.locator('[role="menu"], [role="menuitem"]'); + + await expect(filterMenu.first()).toBeVisible({ timeout: 5000 }); + + const filterOption = this.page.locator(`[role="menuitem"]:has-text("${filterName}")`).first(); + + await expect(filterOption).toBeVisible({ timeout: 5000 }); + await filterOption.click(); + + const filterPill = this.page.locator(`[role="combobox"], button:has-text("${filterName}:")`); + + await expect(filterPill.first()).toBeVisible({ timeout: 5000 }); + await filterPill.first().click(); + + const dropdown = this.page.locator('[role="option"], [role="listbox"]'); + + await expect(dropdown.first()).toBeVisible({ timeout: 5000 }); + + const valueOption = this.page.locator(`[role="option"]:has-text("${filterValue}")`).first(); + + await expect(valueOption).toBeVisible({ timeout: 5000 }); + await valueOption.click(); + + await this.page.waitForLoadState("networkidle"); + } + + /** + * Navigate to Task Instances page and wait for data to load + */ + public async navigate(): Promise<void> { + await this.navigateTo(TaskInstancesPage.taskInstancesUrl); + await this.page.waitForURL(/.*task_instances/, { timeout: 15_000 }); + await this.taskInstancesTable.waitFor({ state: "visible", timeout: 10_000 }); + + const dataLink = this.taskInstancesTable.locator("a[href*='/dags/']").first(); + const noDataMessage = this.page.locator('text="No Task Instances found"'); + + await expect(dataLink.or(noDataMessage)).toBeVisible({ timeout: 30_000 }); + } + + /** + * Verify pagination works correctly with offset and limit parameters + */ + public async verifyPagination(limit: number): Promise<void> { + await this.navigateTo(`${TaskInstancesPage.taskInstancesUrl}?offset=0&limit=${limit}`); + await this.page.waitForURL(/.*task_instances/, { timeout: 10_000 }); + await this.taskInstancesTable.waitFor({ state: "visible", timeout: 10_000 }); + + const rows = this.taskInstancesTable.locator('tbody tr:not(.no-data), div[role="row"]:not(:first-child)'); + const rowCount = await rows.count(); + + expect(rowCount).toBeGreaterThan(0); + + const paginationInfo = this.page.locator("text=/\\d+\\s*-\\s*\\d+\\s*of\\s*\\d+/i"); + + if ((await paginationInfo.count()) > 0) { + await expect(paginationInfo.first()).toBeVisible(); + + const paginationText = (await paginationInfo.first().textContent()) ?? ""; + + expect(paginationText).toBeTruthy(); + + const regex = /(\d+)\s*-\s*(\d+)\s*of\s*(\d+)/i; + const match = regex.exec(paginationText); + + if (match?.[1] !== undefined && match[2] !== undefined && match[3] !== undefined) { + const start = parseInt(match[1], 10); + const end = parseInt(match[2], 10); + const total = parseInt(match[3], 10); + + expect(start).toBeGreaterThan(0); + expect(end).toBeGreaterThanOrEqual(start); + expect(total).toBeGreaterThanOrEqual(end); + + const initialStart = start; + + await this.navigateTo(`${TaskInstancesPage.taskInstancesUrl}?offset=${limit}&limit=${limit}`); + await this.page.waitForURL(/.*task_instances/, { timeout: 10_000 }); + await this.taskInstancesTable.waitFor({ state: "visible", timeout: 10_000 }); + + const paginationInfoPage2 = this.page.locator("text=/\\d+\\s*-\\s*\\d+\\s*of\\s*\\d+/i"); + + if ((await paginationInfoPage2.count()) > 0) { + const paginationText2 = (await paginationInfoPage2.first().textContent()) ?? ""; + const regex2 = /(\d+)\s*-\s*(\d+)\s*of\s*(\d+)/i; + const match2 = regex2.exec(paginationText2); + + if (match2?.[1] !== undefined) { + const startPage2 = parseInt(match2[1], 10); + + expect(startPage2).toBeGreaterThan(initialStart); + } + } + } + } + } + + /** + * Verify that state filtering works correctly + */ + public async verifyStateFiltering(expectedState: string): Promise<void> { + await this.applyFilter("State", expectedState); + + await this.page.waitForURL(/.*state=.*/, { timeout: 10_000 }); + await this.page.waitForLoadState("networkidle"); + await expect(this.taskInstancesTable).toBeVisible(); + + const url = this.page.url(); + + expect(url).toContain("state="); + + const rowsAfterFilter = this.taskInstancesTable.locator( + 'tbody tr:not(.no-data), div[role="row"]:not(:first-child)', + ); + const countAfter = await rowsAfterFilter.count(); + + if (countAfter === 0) { Review Comment: should we use await expect(dataLinks.first().or(noDataMessage.first())).toBeVisible({ timeout: 30_000 }); -- 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]
