test(playwright): additional dataset list playwright tests (#36684)

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Joe Li
2026-02-05 16:42:07 -08:00
committed by GitHub
parent ef4f7afa90
commit 5040db859c
30 changed files with 2828 additions and 125 deletions

View File

@@ -0,0 +1,207 @@
/**
* 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 { Locator, Page } from '@playwright/test';
const ACE_EDITOR_SELECTORS = {
TEXT_INPUT: '.ace_text-input',
TEXT_LAYER: '.ace_text-layer',
CONTENT: '.ace_content',
SCROLLER: '.ace_scroller',
} as const;
/**
* AceEditor component for interacting with Ace Editor instances in Playwright.
* Uses the ace editor API directly for reliable text manipulation.
*/
export class AceEditor {
readonly page: Page;
private readonly locator: Locator;
constructor(page: Page, selector: string);
constructor(page: Page, locator: Locator);
constructor(page: Page, selectorOrLocator: string | Locator) {
this.page = page;
if (typeof selectorOrLocator === 'string') {
this.locator = page.locator(selectorOrLocator);
} else {
this.locator = selectorOrLocator;
}
}
/**
* Gets the editor element locator
*/
get element(): Locator {
return this.locator;
}
/**
* Waits for the ace editor to be fully loaded and ready for interaction.
*/
async waitForReady(): Promise<void> {
// Wait for editor to be attached (outer .ace_editor div may be CSS-hidden)
await this.locator.waitFor({ state: 'attached' });
await this.locator
.locator(ACE_EDITOR_SELECTORS.CONTENT)
.waitFor({ state: 'attached' });
// Wait for window.ace library to be fully loaded (may load async)
await this.page.waitForFunction(
() =>
typeof (window as unknown as { ace?: { edit?: unknown } }).ace?.edit ===
'function',
{ timeout: 10000 },
);
}
/**
* Sets text in the ace editor using the ace API.
* Uses element handle to target the specific editor instance (not global ID lookup).
* @param text - The text to set
*/
async setText(text: string): Promise<void> {
await this.waitForReady();
const elementHandle = await this.locator.elementHandle();
if (!elementHandle) {
throw new Error('Could not get element handle for ace editor');
}
await this.page.evaluate(
({ element, value }) => {
const windowWithAce = window as unknown as {
ace?: {
edit(el: Element): {
setValue(v: string, c: number): void;
session: { getUndoManager(): { reset(): void } };
};
};
};
if (!windowWithAce.ace) {
throw new Error(
'Ace editor library not loaded. Ensure the page has finished loading.',
);
}
// ace.edit() accepts either an element ID string or the DOM element itself
const editor = windowWithAce.ace.edit(element);
editor.setValue(value, 1);
editor.session.getUndoManager().reset();
},
{ element: elementHandle, value: text },
);
}
/**
* Gets the text content from the ace editor.
* Uses element handle to target the specific editor instance.
* @returns The text content
*/
async getText(): Promise<string> {
await this.waitForReady();
const elementHandle = await this.locator.elementHandle();
if (!elementHandle) {
throw new Error('Could not get element handle for ace editor');
}
return this.page.evaluate(element => {
const windowWithAce = window as unknown as {
ace?: { edit(el: Element): { getValue(): string } };
};
if (!windowWithAce.ace) {
throw new Error(
'Ace editor library not loaded. Ensure the page has finished loading.',
);
}
return windowWithAce.ace.edit(element).getValue();
}, elementHandle);
}
/**
* Clears the text in the ace editor.
*/
async clear(): Promise<void> {
await this.setText('');
}
/**
* Appends text to the existing content in the ace editor.
* Uses element handle to target the specific editor instance.
* @param text - The text to append
*/
async appendText(text: string): Promise<void> {
await this.waitForReady();
const elementHandle = await this.locator.elementHandle();
if (!elementHandle) {
throw new Error('Could not get element handle for ace editor');
}
await this.page.evaluate(
({ element, value }) => {
const windowWithAce = window as unknown as {
ace?: {
edit(el: Element): {
getValue(): string;
setValue(v: string, c: number): void;
};
};
};
if (!windowWithAce.ace) {
throw new Error(
'Ace editor library not loaded. Ensure the page has finished loading.',
);
}
const editor = windowWithAce.ace.edit(element);
const currentText = editor.getValue();
// Only add newline if there's existing text that doesn't already end with one
const needsNewline = currentText && !currentText.endsWith('\n');
const newText = currentText + (needsNewline ? '\n' : '') + value;
editor.setValue(newText, 1);
},
{ element: elementHandle, value: text },
);
}
/**
* Focuses the ace editor.
* Uses element handle to target the specific editor instance.
*/
async focus(): Promise<void> {
await this.waitForReady();
const elementHandle = await this.locator.elementHandle();
if (!elementHandle) {
throw new Error('Could not get element handle for ace editor');
}
await this.page.evaluate(element => {
const windowWithAce = window as unknown as {
ace?: { edit(el: Element): { focus(): void } };
};
if (!windowWithAce.ace) {
throw new Error(
'Ace editor library not loaded. Ensure the page has finished loading.',
);
}
windowWithAce.ace.edit(element).focus();
}, elementHandle);
}
/**
* Checks if the editor is visible.
*/
async isVisible(): Promise<boolean> {
return this.locator.isVisible();
}
}

View File

@@ -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 { Locator, Page } from '@playwright/test';
/**
* Core Checkbox component used in Playwright tests to interact with checkbox
* elements in the Superset UI.
*
* This class wraps a Playwright {@link Locator} pointing to a checkbox input
* and provides convenience methods for common interactions such as checking,
* unchecking, toggling, and asserting checkbox state and visibility.
*
* @example
* const checkbox = new Checkbox(page, page.locator('input[type="checkbox"]'));
* await checkbox.check();
* await expect(await checkbox.isChecked()).toBe(true);
*
* @param page - The Playwright {@link Page} instance associated with the test.
* @param locator - The Playwright {@link Locator} targeting the checkbox element.
*/
export class Checkbox {
readonly page: Page;
private readonly locator: Locator;
constructor(page: Page, locator: Locator) {
this.page = page;
this.locator = locator;
}
/**
* Gets the checkbox element locator
*/
get element(): Locator {
return this.locator;
}
/**
* Checks the checkbox (ensures it's checked)
*/
async check(): Promise<void> {
await this.locator.check();
}
/**
* Unchecks the checkbox (ensures it's unchecked)
*/
async uncheck(): Promise<void> {
await this.locator.uncheck();
}
/**
* Toggles the checkbox state
*/
async toggle(): Promise<void> {
await this.locator.click();
}
/**
* Checks if the checkbox is checked
*/
async isChecked(): Promise<boolean> {
return this.locator.isChecked();
}
/**
* Checks if the checkbox is visible
*/
async isVisible(): Promise<boolean> {
return this.locator.isVisible();
}
/**
* Checks if the checkbox is enabled
*/
async isEnabled(): Promise<boolean> {
return this.locator.isEnabled();
}
}

View File

@@ -0,0 +1,187 @@
/**
* 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 { Locator, Page } from '@playwright/test';
/**
* Ant Design Select component selectors
*/
const SELECT_SELECTORS = {
DROPDOWN: '.ant-select-dropdown',
OPTION: '.ant-select-item-option',
SEARCH_INPUT: '.ant-select-selection-search-input',
CLEAR: '.ant-select-clear',
} as const;
/**
* Select component for Ant Design Select/Combobox interactions.
*/
export class Select {
readonly page: Page;
private readonly locator: Locator;
constructor(page: Page, selector: string);
constructor(page: Page, locator: Locator);
constructor(page: Page, selectorOrLocator: string | Locator) {
this.page = page;
if (typeof selectorOrLocator === 'string') {
this.locator = page.locator(selectorOrLocator);
} else {
this.locator = selectorOrLocator;
}
}
/**
* Creates a Select from a combobox role with the given accessible name
* @param page - The Playwright page
* @param name - The accessible name (aria-label or placeholder text)
*/
static fromRole(page: Page, name: string): Select {
const locator = page.getByRole('combobox', { name });
return new Select(page, locator);
}
/**
* Gets the select element locator
*/
get element(): Locator {
return this.locator;
}
/**
* Opens the dropdown, types to filter, and selects an option.
* Handles cases where the option may not be initially visible in the dropdown.
* Waits for dropdown to close after selection to avoid stale dropdowns.
* @param optionText - The text of the option to select
*/
async selectOption(optionText: string): Promise<void> {
await this.open();
await this.type(optionText);
await this.clickOption(optionText);
// Wait for dropdown to close to avoid multiple visible dropdowns
await this.waitForDropdownClose();
}
/**
* Waits for dropdown to close after selection
* This prevents strict mode violations when multiple selects are used sequentially
*/
private async waitForDropdownClose(): Promise<void> {
// Wait for dropdown to actually close (become hidden)
await this.page
.locator(`${SELECT_SELECTORS.DROPDOWN}:not(.ant-select-dropdown-hidden)`)
.last()
.waitFor({ state: 'hidden', timeout: 5000 })
.catch(error => {
// Only ignore TimeoutError (dropdown may already be closed); re-throw others
if (!(error instanceof Error) || error.name !== 'TimeoutError') {
throw error;
}
});
}
/**
* Opens the dropdown
*/
async open(): Promise<void> {
await this.locator.click();
}
/**
* Clicks an option in an already-open dropdown by its text content.
* Uses selector-based approach matching Cypress patterns.
* Handles multiple dropdowns by targeting only visible, non-hidden ones.
* @param optionText - The text of the option to click (partial match for filtered results)
*/
async clickOption(optionText: string): Promise<void> {
// Target visible dropdown (excludes hidden ones via :not(.ant-select-dropdown-hidden))
// Use .last() in case multiple dropdowns exist - the most recent one is what we want
const dropdown = this.page
.locator(`${SELECT_SELECTORS.DROPDOWN}:not(.ant-select-dropdown-hidden)`)
.last();
await dropdown.waitFor({ state: 'visible' });
// Find option by text content - use partial match since filtered results may have prefixes
// (e.g., searching for 'main' shows 'examples.main', 'system.main')
// First try exact match, fall back to partial match
const exactOption = dropdown
.locator(SELECT_SELECTORS.OPTION)
.getByText(optionText, { exact: true });
if ((await exactOption.count()) > 0) {
await exactOption.click();
} else {
// Fall back to first option containing the text
const partialOption = dropdown
.locator(SELECT_SELECTORS.OPTION)
.filter({ hasText: optionText })
.first();
await partialOption.click();
}
}
/**
* Closes the dropdown by pressing Escape
*/
async close(): Promise<void> {
await this.page.keyboard.press('Escape');
}
/**
* Types into the select to filter options (assumes dropdown is open)
* @param text - The text to type
*/
async type(text: string): Promise<void> {
// Find the actual search input inside the select component
const searchInput = this.locator.locator(SELECT_SELECTORS.SEARCH_INPUT);
try {
// Wait for search input in case dropdown is still rendering
await searchInput.first().waitFor({ state: 'attached', timeout: 1000 });
await searchInput.first().fill(text);
} catch (error) {
// Only handle TimeoutError (search input not found); re-throw other errors
if (!(error instanceof Error) || error.name !== 'TimeoutError') {
throw error;
}
// Fallback: locator might be the input itself (e.g., from getByRole('combobox'))
await this.locator.fill(text);
}
}
/**
* Clears the current selection
*/
async clear(): Promise<void> {
await this.locator.clear();
}
/**
* Checks if the select is visible
*/
async isVisible(): Promise<boolean> {
return this.locator.isVisible();
}
/**
* Checks if the select is enabled
*/
async isEnabled(): Promise<boolean> {
return this.locator.isEnabled();
}
}

View File

@@ -0,0 +1,75 @@
/**
* 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 { Locator, Page } from '@playwright/test';
/**
* Tabs component for Ant Design tab navigation.
*/
export class Tabs {
readonly page: Page;
private readonly locator: Locator;
constructor(page: Page, locator?: Locator) {
this.page = page;
// Default to the tablist role if no specific locator provided
this.locator = locator ?? page.getByRole('tablist');
}
/**
* Gets the tablist element locator
*/
get element(): Locator {
return this.locator;
}
/**
* Gets a tab by name, scoped to this tablist's container
* @param tabName - The name/label of the tab
*/
getTab(tabName: string): Locator {
return this.locator.getByRole('tab', { name: tabName });
}
/**
* Clicks a tab by name
* @param tabName - The name/label of the tab to click
*/
async clickTab(tabName: string): Promise<void> {
await this.getTab(tabName).click();
}
/**
* Gets the tab panel content for a given tab
* @param tabName - The name/label of the tab
*/
getTabPanel(tabName: string): Locator {
return this.page.getByRole('tabpanel', { name: tabName });
}
/**
* Checks if a tab is selected
* @param tabName - The name/label of the tab
*/
async isSelected(tabName: string): Promise<boolean> {
const tab = this.getTab(tabName);
const ariaSelected = await tab.getAttribute('aria-selected');
return ariaSelected === 'true';
}
}

View File

@@ -0,0 +1,109 @@
/**
* 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 { Locator, Page } from '@playwright/test';
/**
* Playwright helper for interacting with HTML {@link HTMLTextAreaElement | `<textarea>`} elements.
*
* This component wraps a Playwright {@link Locator} and provides convenience methods for
* filling, clearing, and reading the value of a textarea without having to work with
* locators directly.
*
* Typical usage:
* ```ts
* const textarea = new Textarea(page, 'textarea[name="description"]');
* await textarea.fill('Some multi-line text');
* const value = await textarea.getValue();
* ```
*
* You can also construct an instance from the `name` attribute:
* ```ts
* const textarea = Textarea.fromName(page, 'description');
* await textarea.clear();
* ```
*/
export class Textarea {
readonly page: Page;
private readonly locator: Locator;
constructor(page: Page, selector: string);
constructor(page: Page, locator: Locator);
constructor(page: Page, selectorOrLocator: string | Locator) {
this.page = page;
if (typeof selectorOrLocator === 'string') {
this.locator = page.locator(selectorOrLocator);
} else {
this.locator = selectorOrLocator;
}
}
/**
* Creates a Textarea from a name attribute
* @param page - The Playwright page
* @param name - The name attribute value
*/
static fromName(page: Page, name: string): Textarea {
const locator = page.locator(`textarea[name="${name}"]`);
return new Textarea(page, locator);
}
/**
* Gets the textarea element locator
*/
get element(): Locator {
return this.locator;
}
/**
* Fills the textarea with text (clears existing content)
* @param text - The text to fill
*/
async fill(text: string): Promise<void> {
await this.locator.fill(text);
}
/**
* Clears the textarea content
*/
async clear(): Promise<void> {
await this.locator.clear();
}
/**
* Gets the current value of the textarea
*/
async getValue(): Promise<string> {
return this.locator.inputValue();
}
/**
* Checks if the textarea is visible
*/
async isVisible(): Promise<boolean> {
return this.locator.isVisible();
}
/**
* Checks if the textarea is enabled
*/
async isEnabled(): Promise<boolean> {
return this.locator.isEnabled();
}
}

View File

@@ -18,10 +18,15 @@
*/
// Core Playwright Components for Superset
export { AceEditor } from './AceEditor';
export { Button } from './Button';
export { Checkbox } from './Checkbox';
export { Form } from './Form';
export { Input } from './Input';
export { Menu } from './Menu';
export { Modal } from './Modal';
export { Select } from './Select';
export { Table } from './Table';
export { Tabs } from './Tabs';
export { Textarea } from './Textarea';
export { Toast } from './Toast';