/** * 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 { Page, Locator } from '@playwright/test'; import { TIMEOUT } from '../utils/constants'; /** * Explore Page object */ export class ExplorePage { private readonly page: Page; private static readonly SELECTORS = { DATASOURCE_CONTROL: '[data-test="datasource-control"]', VIZ_SWITCHER: '[data-test="fast-viz-switcher"]', } as const; constructor(page: Page) { this.page = page; } /** * Waits for the Explore page to load. * Validates URL contains /explore/ and datasource control is visible. * * @param options - Optional wait options */ async waitForPageLoad(options?: { timeout?: number }): Promise { const timeout = options?.timeout ?? TIMEOUT.PAGE_LOAD; await this.page.waitForURL('**/explore/**', { timeout }); await this.page.waitForSelector(ExplorePage.SELECTORS.DATASOURCE_CONTROL, { state: 'visible', timeout, }); } /** * Gets the datasource control locator. * Returns a Locator that tests can use with expect() or to read text. * * @returns Locator for the datasource control * * @example * const name = await explorePage.getDatasourceControl().textContent(); */ getDatasourceControl(): Locator { return this.page.locator(ExplorePage.SELECTORS.DATASOURCE_CONTROL); } /** * Gets the currently selected dataset name from the datasource control */ async getDatasetName(): Promise { const text = await this.getDatasourceControl().textContent(); return text?.trim() || ''; } /** * Gets the visualization switcher locator. * Returns a Locator that tests can use with expect().toBeVisible(), etc. * * @returns Locator for the viz switcher * * @example * await expect(explorePage.getVizSwitcher()).toBeVisible(); */ getVizSwitcher(): Locator { return this.page.locator(ExplorePage.SELECTORS.VIZ_SWITCHER); } }