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(/1[3-9][0-9]{6}/), } = {}) { 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: 100 }); // 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('创建并选择').click(); await expect(this.page.getByText('用户资料创建成功!')).toBeVisible(); await this.page.getByText('以后再说').click(); await expect(this.page.getByText('以后再说')).not.toBeVisible(); }; }