table locators移至Locators内
This commit is contained in:
parent
cd0a750b86
commit
c1fcf4fa14
|
@ -52,7 +52,7 @@ fillTable可通过Table类获取cellLocator后直接调用fillForm进行填写
|
||||||
|
|
||||||
#### table.ts 获取表格cellLocator
|
#### table.ts 获取表格cellLocator
|
||||||
|
|
||||||
tableLocator需要根据项目情况自行适配。
|
table在Locators内定义,需要根据项目情况自行适配。
|
||||||
获取到cellLocator后,可使用playwright Locator的所有方法进行操作。
|
获取到cellLocator后,可使用playwright Locator的所有方法进行操作。
|
||||||
|
|
||||||
#### 其他Page对象,继承PageCompoment,实现Page内方法
|
#### 其他Page对象,继承PageCompoment,实现Page内方法
|
||||||
|
|
|
@ -1,21 +1,22 @@
|
||||||
import type { Page, Locator } from 'playwright-core';
|
import type { Page, Locator } from 'playwright-core';
|
||||||
import { test } from '@playwright/test';
|
import { test } from '@playwright/test';
|
||||||
|
import { Locators } from './Locators';
|
||||||
|
|
||||||
export default class Table {
|
export class Table {
|
||||||
|
private locators: Locators
|
||||||
private readonly tableLocator: Locator;
|
private readonly tableLocator: Locator;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造函数
|
* 构造函数
|
||||||
* @param page 页面对象
|
* @param page 页面对象
|
||||||
* @param tableUniqueText 表格唯一文本,可以接收一组文本。
|
* @param tableUniqueText 表格唯一文本,可以接收一组文本。
|
||||||
*/
|
*/
|
||||||
constructor(private page: Page, private tableUniqueText: string | string[]) {
|
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") {
|
if (typeof tableUniqueText === "string") {
|
||||||
this.tableLocator = this.tableLocator.filter({ hasText: `${this.tableUniqueText}` });
|
this.tableLocator = this.locators.table.filter({ hasText: `${this.tableUniqueText}` });
|
||||||
} else {
|
} 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 }) });
|
.filter({ has: this.page.getByText(`${row}`, { exact: true }) });
|
||||||
} else {
|
} else {
|
||||||
return this.tableLocator
|
return this.tableLocator
|
||||||
.locator('tbody')
|
.locator('tbody tr')
|
||||||
.locator('tr')
|
|
||||||
.locator('visible=true')
|
.locator('visible=true')
|
||||||
.nth(row - 1);
|
.nth(row - 1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue