106 lines
3.1 KiB
TypeScript
106 lines
3.1 KiB
TypeScript
import { Locator, Page } from '@playwright/test';
|
|
|
|
export class NumberInput {
|
|
private readonly page: Page;
|
|
private readonly popupLocator: Locator;
|
|
private readonly inputLocators: { [key: string]: Locator } = {};
|
|
private readonly confirmButtonLocator: Locator;
|
|
private readonly delButtonLocator: Locator;
|
|
private readonly delAllButtonLocator: Locator;
|
|
// private readonly inputLocator: 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.inputLocators = {
|
|
common: this.popupLocator.getByPlaceholder(''),
|
|
normal: this.popupLocator.getByPlaceholder('请输入内容'),
|
|
point: this.popupLocator.getByPlaceholder('请输入积分'),
|
|
};
|
|
// 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');
|
|
}
|
|
|
|
/**
|
|
* 设置值
|
|
* @param type 输入框类型 (common, normal, point)
|
|
* @param value 输入值
|
|
*/
|
|
async setValue(type: 'common' | 'normal' | 'point', value: number | string): Promise<void> {
|
|
const locator = this.inputLocators[type];
|
|
if (!locator) {
|
|
throw new Error(`Invalid input type: ${type}`);
|
|
}
|
|
await locator.fill(value.toString());
|
|
}
|
|
|
|
/**
|
|
* 设置通用值
|
|
*/
|
|
// async setCommonValue(value: number): Promise<void> {
|
|
// await this.commonInputLocator.fill(value.toString());
|
|
// }
|
|
|
|
/**
|
|
* 设置值
|
|
*/
|
|
// async setValue(value: number): Promise<void> {
|
|
// await this.inputLocator.fill(value.toString());
|
|
// }
|
|
|
|
/**
|
|
* 设置积分值
|
|
* @param value
|
|
*/
|
|
// async setPointValue(value: number): Promise<void> {
|
|
// await this.pointInputLocator.fill(value.toString());
|
|
// }
|
|
|
|
/**
|
|
* 设置文本
|
|
*/
|
|
async setString(value: string): Promise<void> {
|
|
// await this.inputLocator.fill(value);
|
|
await this.inputLocators.normal.fill(value);
|
|
}
|
|
|
|
/**
|
|
* 点击数字键盘
|
|
* @param value
|
|
*/
|
|
async setInputValue(value: number): Promise<void> {
|
|
await this.page.getByRole('button', { name: value.toString() }).click();
|
|
}
|
|
|
|
/**
|
|
* 点击确认按钮
|
|
*/
|
|
async confirmValue(): Promise<void> {
|
|
await this.confirmButtonLocator.click();
|
|
}
|
|
|
|
/**
|
|
* 点击删除按钮
|
|
*/
|
|
async delValue(): Promise<void> {
|
|
await this.delButtonLocator.click();
|
|
}
|
|
|
|
/**
|
|
* 点击清空按钮
|
|
*/
|
|
async delAllValue(): Promise<void> {
|
|
await this.delAllButtonLocator.click();
|
|
}
|
|
}
|