Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions airflow-core/src/airflow/ui/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,15 @@ export const testConfig = {
asset: {
name: process.env.TEST_ASSET_NAME ?? "s3://dag1/output_1.txt",
},
connection: {
baseUrl: process.env.AIRFLOW_UI_BASE_URL ?? "http://localhost:28080",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have we removed this?

configPage: {
expectedHeading: process.env.TEST_CONFIG_PAGE_HEADING ?? "Airflow Configuration",
expectedKey: process.env.TEST_CONFIG_PAGE_KEY ?? "dags_folder",
expectedSection: process.env.TEST_CONFIG_PAGE_SECTION ?? "core",
expectsTableData: (process.env.TEST_CONFIG_PAGE_EXPECTS_TABLE_DATA ?? "false").toLowerCase() === "true",
forbiddenMessage:
process.env.TEST_CONFIG_PAGE_FORBIDDEN_MESSAGE ??
"Your Airflow administrator chose not to expose the configuration",
path: process.env.TEST_CONFIG_PAGE_PATH ?? "/configs",
},
credentials: {
password: process.env.TEST_PASSWORD ?? "admin",
Expand Down
6 changes: 6 additions & 0 deletions airflow-core/src/airflow/ui/tests/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ Environment variables (with defaults):
- `TEST_USERNAME` - Username (default: `airflow`)
- `TEST_PASSWORD` - Password (default: `airflow`)
- `TEST_DAG_ID` - Test DAG ID (default: `example_bash_operator`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need so many config? I think only TEST_CONFIG_PAGE_EXPECTS_TABLE_DATA might be required

- `TEST_CONFIG_PAGE_PATH` - Config page path (default: `/configs`)
- `TEST_CONFIG_PAGE_HEADING` - Config page heading (default: `Airflow Configuration`)
- `TEST_CONFIG_PAGE_EXPECTS_TABLE_DATA` - `true` to assert table rows are exposed; `false` to assert 403 message (default: `false`)
- `TEST_CONFIG_PAGE_SECTION` - Section asserted when table data is exposed (default: `core`)
- `TEST_CONFIG_PAGE_KEY` - Key asserted when table data is exposed (default: `dags_folder`)
- `TEST_CONFIG_PAGE_FORBIDDEN_MESSAGE` - Message asserted when table data is hidden (default: `Your Airflow administrator chose not to expose the configuration`)

## Debugging

Expand Down
95 changes: 95 additions & 0 deletions airflow-core/src/airflow/ui/tests/e2e/pages/ConfigsPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*!
* 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 "./BasePage";

export class ConfigsPage extends BasePage {
public readonly forbiddenStatus: Locator;
public readonly heading: Locator;
public readonly rows: Locator;
public readonly table: Locator;

public constructor(page: Page) {
super(page);
this.heading = page.getByRole("heading", { name: /configuration/i });
this.table = page.getByTestId("table-list");
this.forbiddenStatus = page.getByText(/403 forbidden/i);
this.rows = this.table.locator("tbody tr").filter({
has: page.locator("td"),
});
}

public async getColumnNames(): Promise<Array<string>> {
return this.table.locator("thead th").allTextContents();
}

public async getRowCount(): Promise<number> {
return this.rows.count();
}

public async getRowDetails(index: number): Promise<{ key: string; section: string; value: string }> {
const row = this.rows.nth(index);
const cells = row.locator("td");

const section = await cells.nth(0).textContent();
const key = await cells.nth(1).textContent();
const value = await cells.nth(2).textContent();

return {
key: (key ?? "").trim(),
section: (section ?? "").trim(),
value: (value ?? "").trim(),
};
}

public async hasSectionAndKey(section: string, key: string): Promise<boolean> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use filter

public async hasSectionAndKey(section: string, key: string): Promise<boolean> {
  const row = this.rows.filter({ hasText: section }).filter({ hasText: key });
  return (await row.count()) > 0;
}

const sectionLower = section.toLowerCase();
const keyLower = key.toLowerCase();
const rowCount = await this.getRowCount();

for (let i = 0; i < rowCount; i++) {
const row = await this.getRowDetails(i);

if (row.section.toLowerCase() === sectionLower && row.key.toLowerCase() === keyLower) {
return true;
}
}

return false;
}

public async navigate(path = "/configs"): Promise<void> {
await this.navigateTo(path);
}

public async waitForLoad(): Promise<void> {
await this.heading.waitFor({ state: "visible", timeout: 30_000 });
await this.page.waitForFunction(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can just use

await expect(this.table.or(this.forbiddenStatus)).toBeVisible({ timeout: 30_000 });

() => {
const table = document.querySelector('[data-testid="table-list"]');
const bodyText = document.body.textContent;

return table !== null || bodyText.includes("403 Forbidden");
},
undefined,
{ timeout: 30_000 },
);
}
}
115 changes: 115 additions & 0 deletions airflow-core/src/airflow/ui/tests/e2e/specs/configs.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*!
* 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, test } from "@playwright/test";
import { testConfig } from "playwright.config";

import { ConfigsPage } from "../pages/ConfigsPage";

const escapeForRegex = (value: string): string => value.replaceAll(/[$()*+.?[\\\]^{|}]/g, "\\$&");

test.describe("Configuration Page", () => {
let configsPage: ConfigsPage;
const { configPage } = testConfig;

test.beforeEach(async ({ page }) => {
configsPage = new ConfigsPage(page);
await configsPage.navigate(configPage.path);
await configsPage.waitForLoad();
});

test("verify configuration displays", async () => {
await expect(configsPage.heading).toHaveText(new RegExp(configPage.expectedHeading, "i"));

if (!configPage.expectsTableData) {
await expect(configsPage.forbiddenStatus).toBeVisible();
await expect(
configsPage.page.getByText(new RegExp(escapeForRegex(configPage.forbiddenMessage), "i")),
).toBeVisible();

return;
}

await expect(configsPage.table).toBeVisible();

const rowCount = await configsPage.getRowCount();

expect(rowCount).toBeGreaterThan(0);

const columns = await configsPage.getColumnNames();

expect(columns).toEqual(expect.arrayContaining(["Section", "Key", "Value"]));
});

test("verify configuration page is accessible via Admin menu", async ({ page }) => {
await page.goto("/");

await page.getByRole("button", { name: /^admin$/i }).click();

const configMenuItem = page.getByRole("menuitem", { name: /^config$/i });

await expect(configMenuItem).toBeVisible();
await configMenuItem.click();

await configsPage.waitForLoad();
expect(page.url()).toContain(configPage.path);

if (!configPage.expectsTableData) {
await expect(configsPage.forbiddenStatus).toBeVisible();
await expect(
configsPage.page.getByText(new RegExp(escapeForRegex(configPage.forbiddenMessage), "i")),
).toBeVisible();

return;
}

await expect(configsPage.table).toBeVisible();
});

test("verify configuration section and key are rendered", async () => {
test.skip(
!configPage.expectsTableData,
"Set TEST_CONFIG_PAGE_EXPECTS_TABLE_DATA=true when configuration values are exposed.",
);

const sectionAndKeyExists = await configsPage.hasSectionAndKey(
configPage.expectedSection,
configPage.expectedKey,
);

expect(sectionAndKeyExists).toBe(true);
});

test("verify section, key and value are populated in configuration rows", async () => {
test.skip(
!configPage.expectsTableData,
"Set TEST_CONFIG_PAGE_EXPECTS_TABLE_DATA=true when configuration values are exposed.",
);

const rowCount = await configsPage.getRowCount();
const rowsToCheck = Math.min(rowCount, 3);

for (let i = 0; i < rowsToCheck; i++) {
const { key, section, value } = await configsPage.getRowDetails(i);

expect(section).not.toEqual("");
expect(key).not.toEqual("");
expect(value).not.toEqual("");
}
});
});
Loading