我想减慢测试步骤的测试执行速度。我正在测试一个有两个选项卡的容器,每个选项卡都有不同的数据表。当我单击选项卡时,加载数据需要一些时间。由于竞争问题,PlayWright 在无头模式下速度太快,尽管下一个选项卡已被单击并打开,但仍然具有上一个选项卡的数据。我不能依赖表的数据,因为它总是不同的,因此
expect()
无法解决问题。
我在
slowMo: 500
中使用了 playwright.config.ts
,一切都按预期运行。然而,它减慢了我不想做的每一个测试。我只想降低一项特定测试的执行速度。我添加了 await browser.browserType().launch({slowMo: 500})
,但不起作用。如果可能的话,我不想添加超时或暂停执行。
import {test} from "../../../fixtures/catalog_management/sub_atr/pax_cargo_compatibilities";
test.describe('Pax Cargo Compatibilities', () => {
test('has items', async ({login, pax_cargo_compatibilities, action_toolbar}) => {
for (const tab of [pax_cargo_compatibilities.tab_requestor, pax_cargo_compatibilities.tab_provider]) {
await test.step(`${await tab.innerText()}`, async () => {
//this test doesn´t need to be slow
await tab.locator.click()
await action_toolbar.button_insert.click()
await pax_cargo_compatibilities.verify_properties()
await pax_cargo_compatibilities.dialog.getByTitle('Close').click()
})
}
.....many more tests
test('delete entity',async ({login, browser, pax_cargo_compatibilities, action_toolbar, form_buttons, validation, get_content_of_cell_of_tables_row}) => {
await browser.browserType().launch({slowMo: 500}) // does not work
for (const tab of [{'locator': pax_cargo_compatibilities.tab_requestor, 'tid': 'requestorTable'}, {'locator': pax_cargo_compatibilities.tab_provider, 'tid': 'providerTable'}]) {
await test.step(`${await tab.locator.innerText()}`, async () => {
await tab.locator.click() //this part needs time to load data correctly
let tab_table_data = pax_cargo_compatibilities.table.filter({has: pax_cargo_compatibilities.page.getByTestId(RegExp(`id=${tab.tid}`))})
console.log(await get_content_of_cell_of_tables_row(tab_table_data, [0,7]))
// console.log(await (pax_cargo_compatibilities.table).allTextContents())
// console.log('############################################################################')
})
}
)}
import {test as base} from '../base_fixture_catalog_management';
import {PaxCargoCompatibilities} from "../../../pom/catalog_management/sub_atr/pax_cargo_compatibilities";
import {get_content_of_cell_of_tables_row, login} from "../../../lib/shortcut";
import { Locator } from '@playwright/test';
/**
* Fixture of Pax Cargo Compatibilities which is an extension of 'base_fixture_catalog_management'
*/
export const test = base.extend<{ pax_cargo_compatibilities: PaxCargoCompatibilities, login: any , get_content_of_cell_of_tables_row: any}>({
pax_cargo_compatibilities: async ({page, catalog_management}, use) => {
await catalog_management.pax_cargo_compatibility.click()
await use(new PaxCargoCompatibilities(page));
}, login: async ({page}, use) => {
await login(page, process.env.EURALL)
await use(login)
}, get_content_of_cell_of_tables_row: async ({}: any, use: (arg0: (table: Locator, columns: number[]) => Promise<string[]>) => any) => {
await use(get_content_of_cell_of_tables_row)
}
})
export {expect} from '@playwright/test';
有人有想法或经验吗?
我已经实施但不满意的是
function delay(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
使用 test.slow()
如果您的测试在某些配置(但不是全部)中很慢,您可以根据条件将其标记为慢。我们建议在这种情况下传递一个描述参数。
import { test, expect } from '@playwright/test';
test('slow in Safari', async ({ page, browserName }) => {
test.slow(browserName === 'webkit', 'This feature is slow in Safari');
// ...
});