86 lines
2.3 KiB
TypeScript
86 lines
2.3 KiB
TypeScript
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<void> {
|
|
await this.commonInputLocator.fill(value.toString());
|
|
}
|
|
|
|
/**
|
|
* 设置值
|
|
*/
|
|
async setValue(value: number): Promise<void> {
|
|
await this.inputLocator.fill(value.toString());
|
|
}
|
|
|
|
/**
|
|
* 设置文本
|
|
*/
|
|
async setString(value: string): Promise<void> {
|
|
await this.inputLocator.fill(value);
|
|
}
|
|
|
|
/**
|
|
* 设置积分值
|
|
* @param value
|
|
*/
|
|
async setPointValue(value: number): Promise<void> {
|
|
await this.pointInputLocator.fill(value.toString());
|
|
}
|
|
|
|
/**
|
|
* 点击数字键盘
|
|
* @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();
|
|
}
|
|
}
|