import { Locator, Page } from '@playwright/test'; export class NumberInput { private readonly page: Page; private readonly popupLocator: Locator; private readonly inputLocator: Locator; private readonly confirmButtonLocator: Locator; private readonly delButtonLocator: Locator; private readonly delAllButtonLocator: Locator; private readonly pointInputLocator: Locator; private readonly commonInputLocator: Locator; /** * 数字键盘组件 * @param page 页面 */ constructor(page: Page) { this.page = page; this.popupLocator = this.page.locator('div.popup_content'); this.commonInputLocator = this.popupLocator.getByPlaceholder(''); this.inputLocator = this.popupLocator.getByPlaceholder('请输入内容'); this.pointInputLocator = this.popupLocator.getByPlaceholder('请输入积分'); this.confirmButtonLocator = this.popupLocator.locator('button.sure'); this.delButtonLocator = this.popupLocator.locator('button.del'); this.delAllButtonLocator = this.popupLocator.locator('button.delAll'); } /** * 设置通用值 */ async setCommonValue(value: number): Promise { await this.commonInputLocator.fill(value.toString()); } /** * 设置值 * @param value */ async setValue(value: number): Promise { await this.inputLocator.fill(value.toString()); } /** * 设置文本 */ async setString(value: string): Promise { await this.inputLocator.fill(value); } /** * 设置积分值 * @param value */ async setPointValue(value: number): Promise { await this.pointInputLocator.fill(value.toString()); } /** * 点击数字键盘 * @param value */ async setInputValue(value: number): Promise { await this.page.getByRole('button', { name: value.toString() }).click(); } /** * 点击确认按钮 */ async confirmValue(): Promise { await this.confirmButtonLocator.click(); } /** * 点击删除按钮 */ async delValue(): Promise { await this.delButtonLocator.click(); } /** * 点击清空按钮 */ async delAllValue(): Promise { await this.delAllButtonLocator.click(); } }