I have a test written like this trying to create a program on two pages at the same time. Now it doesn’t work as expected and browser awaits for action on first page to start it on the second one, what am I doing wrong?
Can someone help?
The problem was that test worked 27seconds, now after the refactor it takes 29:)
not so experienced with pw
import type { Locator, Page } from '@fe/pw-config'
import { test } from '@fe/pw-config'
import { allure } from 'allure-playwright'
import { constructN } from 'ramda'
import { chooseItemForProgram, clickAddItem, clickAddProgram, clickDeleteProgram, clickEditAddItem, clickEditSave, clickExpandItems, clickOvenType, confirmProgramDelete, deleteItemFromCurrentProgram, fillAddProgramItem, fillProgramNameField, getProgramFromProgramsByName } from '../../utils'
import { addProgramItemTable, addProgramSaveButton, editProgramPopup, itemAddPopUp, noItemsLocator, tooltipDeleteText, tooltipTrigger } from '../../bakery-manage-pageobjects'
import { checkHidden, checkVisible, getLocatorDataTestId, goToPageAndGetToken } from '~/playwright/utils'
import { getOvenTypes, itemDeleteById } from '~/playwright/requests'
import type { OvenTypeDto } from '~/api/generated/oe-wms-bakery'
test('program edit add item from another program test with parallel windows', async ({ browser, page, baseURL }) => {
const itemId = '1312275664'
const itemId1 = '1312275668'
const itemName = 'Пирог осетинский с мясным фаршем Фыдджын, 500 г'
const itemName1 = 'Пирог осетинский со свежим сыром Уалибах Дабон, 500 г'
const random = Math.floor(Math.random() * 1000)
const programName = `автотест${random}`
const programName1 = `автотест${random + 1}`
const token = await goToPageAndGetToken(page, `${baseURL}/bakery-manage`)
const context = await browser.newContext()
const page1 = await context.newPage()
const page2 = await context.newPage()
const ovenTypes = await getOvenTypes(token)
await Promise.all([
await goToPageAndGetToken(page1, `${baseURL}/bakery-manage`),
await goToPageAndGetToken(page2, `${baseURL}/bakery-manage`),
])
await Promise.all([
clickOvenType(page1, ovenTypes[0].name as string),
clickOvenType(page2, ovenTypes[0].name as string),
])
async function createProgram(page: Page, programName: string, itemId: string, itemName: string) {
await clickAddProgram(page)
await clickAddItem(page)
await fillAddProgramItem(itemId, page)
await chooseItemForProgram(page, itemName)
await checkHidden(itemAddPopUp(page))
await checkVisible(addProgramItemTable(page).getByText(itemName))
await fillProgramNameField(page, programName)
await addProgramSaveButton(page).click()
}
await Promise.all([
createProgram(page1, programName, itemId, itemName),
createProgram(page2, programName1, itemId1, itemName1),
])
const program = getProgramFromProgramsByName(page1, programName)
await program.getByTestId('edit-program-button').click()
await checkVisible(editProgramPopup(page1))
await clickEditAddItem(page1)
await fillAddProgramItem(itemId1, page1)
await chooseItemForProgram(page1, itemName1)
await tooltipTrigger(page1).hover()
await checkVisible(tooltipDeleteText(page1, programName1))
await deleteItemFromCurrentProgram(page1)
await clickEditSave(page1)
await checkHidden(editProgramPopup(page1))
await clickExpandItems(program)
await Promise.all([
checkVisible(page1.getByText(itemId)),
checkVisible(page1.getByText(itemName)),
checkVisible(page1.getByText(itemId1)),
checkVisible(page1.getByText(itemName1)),
checkHidden(noItemsLocator(program)),
])
const program1 = getProgramFromProgramsByName(page2, programName1)
const testId = await getLocatorDataTestId(program)
const testId1 = await getLocatorDataTestId(program1)
await Promise.all([
clickDeleteProgram(page1, testId),
confirmProgramDelete(page1, testId),
clickDeleteProgram(page2, testId1),
confirmProgramDelete(page2, testId1),
])
})