Repository: apache/airflow
File: airflow-core/src/airflow/ui/tests/e2e/pages/AssetListPage.ts (TypeScript)

Code before:
 *   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 AssetListPage extends BasePage {
  public readonly emptyState: Locator;
  public readonly heading: Locator;
  public readonly nextButton: Locator;
  public readonly prevButton: Locator;
  public readonly rows: Locator;
  public readonly searchInput: Locator;
  public readonly table: Locator;

  public constructor(page: Page) {
    super(page);

    this.heading = page.getByRole("heading", { level: 2 });
    this.table = page.getByTestId("table-list");
    this.rows = this.table.locator("tbody tr").filter({
      has: page.locator("td"),
    });

    this.nextButton = page.getByTestId("next");
    this.prevButton = page.getByTestId("prev");

    this.searchInput = page.getByRole("textbox");
    this.emptyState = page.getByText(/no items/i);
  }

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

  public async assetNames(): Promise<Array<string>> {
    return this.rows.locator("td a").allTextContents();
  }

  public async goNext(): Promise<boolean> {
    const next = this.page.locator('[data-testid="next"]');

    if ((await next.count()) === 0) {
      return false;

Review comment (suggestion):
This is Fragile
We can try 
`this.heading = page.getByRole("heading", { name: /assets/i });`

Code after:
 *   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 AssetListPage extends BasePage {
  public readonly emptyState: Locator;
  public readonly heading: Locator;
  public readonly rows: Locator;
  public readonly searchInput: Locator;
  public readonly table: Locator;

  public constructor(page: Page) {
    super(page);

    this.heading = page.getByRole("heading", {
      name: /\d+\s+asset/i,
    });
    this.table = page.getByTestId("table-list");
    this.rows = this.table.locator("tbody tr").filter({
      has: page.locator("td"),
    });

    this.searchInput = page.getByTestId("search-dags");
    this.emptyState = page.getByText(/no items/i);
  }

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

  public async assetNames(): Promise<Array<string>> {
    return this.rows.locator("td a").allTextContents();
  }

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

  public async openFirstAsset(): Promise<string> {
    const count = await this.rows.count();

    if (count === 0) {