- 添加了商品分类页面的测试用例,包括验证表格头和新增分类功能 - 添加了商品列表页面的测试用例,验证页面元素和功能 - 新增了 CommondityCategoryPage 和 CommondityCreateCategoryPage 两个页面对象 - 更新了环境变量和配置文件,为测试用例做准备
49 lines
1.6 KiB
TypeScript
49 lines
1.6 KiB
TypeScript
import { expect, type Locator, type Page } from '@playwright/test';
|
|
|
|
export class CommondityCategoryPage {
|
|
readonly page: Page;
|
|
readonly commondity_category_search_input: Locator;
|
|
readonly commondity_category_search_button: Locator;
|
|
readonly commondity_create_category_button: Locator;
|
|
readonly table_headers: Locator;
|
|
readonly table_rows: Locator;
|
|
|
|
constructor(page: Page) {
|
|
this.page = page;
|
|
this.commondity_category_search_input = page.getByRole('textbox', { name: '请输入分类名称' });
|
|
this.commondity_category_search_button = page.getByRole('button', { name: /查\s询/ });
|
|
this.commondity_create_category_button = page.getByRole('button', { name: '新增分类' });
|
|
this.table_headers = page.locator('.m-table__header-wrapper thead th');
|
|
this.table_rows = page.locator('.m-table__body-wrapper tbody tr');
|
|
}
|
|
|
|
async verify_table_headers() {
|
|
const expected_headers = [
|
|
'分类名称',
|
|
'父分类',
|
|
'品类编码',
|
|
'分类排序',
|
|
'创建时间',
|
|
'更新时间',
|
|
'操作',
|
|
];
|
|
|
|
const actual_headers = await this.table_headers.all();
|
|
|
|
for (let i = 0; i < expected_headers.length; i++) {
|
|
await expect(actual_headers[i]).toHaveText(expected_headers[i]);
|
|
}
|
|
}
|
|
|
|
async get_table_row_content(rowIndex: number): Promise<string[]> {
|
|
const table_rows = await this.table_rows.nth(rowIndex).locator('td').all();
|
|
const cell_content: string[] = [];
|
|
|
|
for (const cell of table_rows) {
|
|
cell_content.push(await cell.textContent() ?? '-');
|
|
}
|
|
|
|
return cell_content;
|
|
}
|
|
}
|