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.
playwright-demo/tests/zhb/pom/customerPage.js
2024-10-24 21:29:34 +08:00

55 lines
1.8 KiB
JavaScript

const { faker } = require('@faker-js/faker/locale/zh_CN');
const { expect } = require('@playwright/test');
export class Customer {
constructor({
name = faker.person.fullName(),
phone = faker.helpers.fromRegExp(/123[0-5]{8}/),
} = {}) {
this.name = name;
this.phone = phone;
}
}
export class CustomerPage {
/**
* @param {import('@playwright/test').Page} page
*/
constructor(page) {
this.page = page;
}
/**
* 创建顾客
* @param {Customer} customer
*/
createCustomer = async (customer) => {
console.log(customer.name);
console.log(customer.phone);
await expect(this.page.locator('#page_member').getByText('新增顾客档案')).toBeVisible();
await this.page.locator('#page_member').getByText('新增顾客档案').click();
await this.page.getByPlaceholder('请输入会员姓名').fill(customer.name);
await this.page.getByPlaceholder('请输入手机号码').click();
await expect(this.page.getByText('请输入数字')).toBeVisible();
await this.page.getByPlaceholder('在此输入').click();
await this.page.keyboard.type(customer.phone, { delay: 50 });
// await this.page.getByPlaceholder('在此输入').type(customer.phone, { delay: 100 });
await this.page.locator('#maskBoard').getByText('确认').click();
await expect(this.page.getByPlaceholder('请输入手机号码')).toHaveValue(customer.phone, {
timeout: 2000,
});
await this.page
.locator('div')
.filter({ hasText: /^员工带客$/ })
.locator('span')
.first()
.click();
await this.page.getByText('创建', { exact: true }).click();
await expect(this.page.getByText('用户资料创建成功!')).toBeVisible();
await this.page.getByText('以后再说').click();
await expect(this.page.getByText('以后再说')).not.toBeVisible();
};
}