更新 Playwright 工作流的定时任务时间,并重构测试用例以提高可读性

This commit is contained in:
wenpeng 2024-11-08 09:55:50 +08:00
parent d870c80378
commit af98ccd0b8
2 changed files with 30 additions and 33 deletions

View File

@ -5,7 +5,7 @@ on:
pull_request: pull_request:
branches: [main, master] branches: [main, master]
schedule: schedule:
- cron: '30 9 * * *' # 每天凌晨 12 点执行一次 - cron: '30 1 * * *' # 每天 上午 9.30 执行一次
workflow_dispatch: # 手动触发 workflow_dispatch: # 手动触发
jobs: jobs:
test: test:

View File

@ -2,45 +2,42 @@ const { test, expect } = require('./fixtures/common');
const { Customer } = require('./pom/customer'); const { Customer } = require('./pom/customer');
const { faker } = require('@faker-js/faker/locale/zh_CN'); const { faker } = require('@faker-js/faker/locale/zh_CN');
test('登录touch和h5创建顾客购买会员卡使用顾客账号到h5商城购买货品', async ({ test.describe
touchPage, .serial('登录touch和h5创建顾客购买会员卡使用顾客账号到h5商城购买货品', async () => {
touchCustomerPage,
h5LoginPage,
}) => {
const phone = faker.helpers.fromRegExp(/1[3-9][0-1]{9}/); const phone = faker.helpers.fromRegExp(/1[3-9][0-1]{9}/);
const customer = new Customer(1, 1, { phone: phone }); const customer = new Customer(1, 1, { phone: phone });
console.log(`${customer.phone}-${customer.username}`);
await touchCustomerPage.createCustomer(customer); test('登录touch和h5创建顾客购买会员卡', async ({ touchPage, touchCustomerPage }) => {
await test.step('在touch页面购买会员卡', async () => { await touchCustomerPage.createCustomer(customer);
await touchPage.getByText('去开单').click(); await test.step('在touch页面购买会员卡', async () => {
await touchPage.locator('.more > .icon > svg').click(); await touchPage.getByText('去开单').click();
await touchPage.getByText('去开卡').click(); await touchPage.locator('.more > .icon > svg').click();
const $firstCard = touchPage.locator('.memberCard_box').first(); await touchPage.getByText('去开卡').click();
await $firstCard.click(); const $firstCard = touchPage.locator('.memberCard_box').first();
await touchPage.getByRole('button', { name: '去结算' }).click(); await $firstCard.click();
await touchPage.locator('.row').filter({ hasText: '总额' }).locator('.touchIcon').click(); await touchPage.getByRole('button', { name: '去结算' }).click();
await touchPage.getByPlaceholder('请输入内容').fill('1000'); await touchPage.locator('.row').filter({ hasText: '总额' }).locator('.touchIcon').click();
await touchPage.locator('div').filter({ hasText: /^789$/ }).getByRole('button').nth(3).click(); await touchPage.getByPlaceholder('请输入内容').fill('1000');
await touchPage.locator('.paymentInfoItem', { hasText: '现金' }).click(); await touchPage
await touchPage.getByText('推送消费提醒').click(); .locator('div')
await touchPage.getByLabel('结算签字').uncheck(); .filter({ hasText: /^789$/ })
await touchPage.getByRole('button', { name: /结\s算/ }).click(); .getByRole('button')
await touchPage.getByRole('button', { name: /跳\s过/ }).click(); .nth(3)
await touchPage.close(); .click();
await touchPage.locator('.paymentInfoItem', { hasText: '现金' }).click();
await touchPage.getByText('推送消费提醒').click();
await touchPage.getByLabel('结算签字').uncheck();
await touchPage.getByRole('button', { name: /结\s算/ }).click();
await touchPage.getByRole('button', { name: /跳\s过/ }).click();
});
}); });
await test.step('登录h5并且商城页面使用会员卡进行购买', async () => { test('登录h5并且商城页面使用会员卡进行购买', async ({ h5Page, h5LoginPage }) => {
await h5LoginPage.login(customer.phone); await h5LoginPage.login(customer.phone);
await h5Page.locator('.singIn_content > .iconfont').click(); await h5Page.locator('.singIn_content > .iconfont').click();
const element = h5Page.locator('.coupon_content'); await h5Page.locator('.get_btn').click();
const boundingBox = await element.boundingBox(); await h5Page.locator('.back').click();
if (boundingBox) {
const x = boundingBox.x + boundingBox.width / 2; // 元素水平中心
const y = boundingBox.y - 10; // 元素上侧空白区域
await h5Page.mouse.click(x, y);
}
await h5Page.locator('.bar_item', { hasText: '商城' }).click(); await h5Page.locator('.bar_item', { hasText: '商城' }).click();
await expect(h5Page.locator('.title', { hasText: '商城' })).toBeVisible(); await expect(h5Page.locator('.title', { hasText: '商城' })).toBeVisible();
await h5Page.locator('.li span', { hasText: '全部' }).click(); await h5Page.locator('.li span', { hasText: '全部' }).click();