This repository has been archived on 2025-04-22. You can view files and clone it, but cannot push or open issues or pull requests.
hlk_autotest/tests/pages/components/numberInput.ts
LingandRX 6517e4192c feat: 初始化慧来客自动化测试项目
- 添加项目配置文件和环境变量设置
- 创建测试用例目录结构和命名规范
- 实现基础测试 fixture 和页面对象模型
- 添加示例测试用例和数据生成器
- 配置 playwright 和 gitignore 文件
2024-12-22 19:18:27 +08:00

87 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());
}
/**
* 设置值
* @param value
*/
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();
}
}