table locators移至Locators内

This commit is contained in:
zhiyong.yue 2023-05-26 14:50:47 +08:00
parent cd0a750b86
commit c1fcf4fa14
2 changed files with 8 additions and 8 deletions

View File

@ -52,7 +52,7 @@ fillTable可通过Table类获取cellLocator后直接调用fillForm进行填写
#### table.ts 获取表格cellLocator
tableLocator需要根据项目情况自行适配。
tableLocators内定义,需要根据项目情况自行适配。
获取到cellLocator后,可使用playwright Locator的所有方法进行操作。
#### 其他Page对象,继承PageCompoment,实现Page内方法

View File

@ -1,21 +1,22 @@
import type { Page, Locator } from 'playwright-core';
import { test } from '@playwright/test';
import { Locators } from './Locators';
export default class Table {
export class Table {
private locators: Locators
private readonly tableLocator: Locator;
/**
*
* @param page
* @param tableUniqueText ,
*/
constructor(private page: Page, private tableUniqueText: string | string[]) {
this.tableLocator = this.page.locator('//div[contains(@class,"singleTable")]').filter( { has: this.page.locator("visible=true") } )
this.locators = new Locators(page)
if (typeof tableUniqueText === "string") {
this.tableLocator = this.tableLocator.filter({ hasText: `${this.tableUniqueText}` });
this.tableLocator = this.locators.table.filter({ hasText: `${this.tableUniqueText}` });
} else {
this.tableLocator = tableUniqueText.reduce((acc, text) => acc.filter({ hasText: text }), this.tableLocator);
this.tableLocator = tableUniqueText.reduce((acc, text) => acc.filter({ hasText: text }), this.locators.table);
}
}
@ -49,8 +50,7 @@ export default class Table {
.filter({ has: this.page.getByText(`${row}`, { exact: true }) });
} else {
return this.tableLocator
.locator('tbody')
.locator('tr')
.locator('tbody tr')
.locator('visible=true')
.nth(row - 1);
}