This thread is trying to answer question "Why are some tests failing because the browser closes before certain steps are completed?"
This is the code that sometimes closes the browser before doing the step "investmentMappage.downloadGeneric("lender",test.info().title);".
status = await investmentMappage.validateLenderInInvestorSection(); if(status===false){ console.log("Error validating section Lender"); test.fail(); } await page.waitForTimeout(1000); investmentMappage.downloadGeneric("lender",test.info().title); await page.waitForTimeout(2000); await investmentMappage.validateTitleInvestorSection(); await investmentMappage.goToLanding(); const landingpage = new LandingPage(page); await landingpage.checkLanding(); await page.waitForLoadState('networkidle'); await page.waitForTimeout(2000);
Seems kind of "blind testing" what if you downloadGeneric take 10 seconds? Would assert this code is really brittle and i would honestly expect it to fail. You need to look for hard/deterministic locators and ensure they are present after 'x' happens. In general never do a wait on the page itself, and only on a given target/locator you expect to be there when a given state had been reached...
downloadGeneric(tab: string,testname: string){ this.page.waitForTimeout(2000); if(tab.toLowerCase()==="owners"){ console.log("--- "+tab+" ---"); this.downdloadExcelInvestorPage(locators.ownersTabExcelButton,locators.ownersTabExcelYesButton,locators.ownersTabExcelDownloadButton,locators.ownersTabExcelCloseButton,testname); }else if(tab.toLowerCase()==="jvs"){ console.log("--- "+tab+" ---"); this.downdloadExcelInvestorPage(locators.jvsTabExcelButton,locators.jvsTabExcelYesButton,locators.jvsTabExcelDownloadButton,locators.jvsTabExcelCloseButton,testname); }else if(tab.toLowerCase()==="refunds"){ console.log("--- "+tab+" ---"); this.downdloadExcelInvestorPage(locators.reFundsTabExcelButton,locators.reFundsTabExcelYesButton,locators.reFundsTabExcelDownloadButton,locators.reFundsTabExcelCloseButton,testname); }else if(tab.toLowerCase()==="sellers"){ console.log("--- "+tab+" ---"); this.downdloadExcelInvestorPage(locators.sellersTabExcelButton,locators.sellersTabExcelYesButton,locators.sellersTabExcelDownloadButton,locators.sellersTabExcelCloseButton,testname); }else if(tab.toLowerCase()==="potentialinvestors"){ console.log("--- "+tab+" ---"); this.downdloadExcelInvestorPage(locators.potentialInvestorsTabExcelButton,locators.potentialInvestorsTabExcelYesButton,locators.potentialInvestorsTabExcelDownloadButton,locators.potentialInvestorsTabExcelCloseButton,testname); }else if(tab.toLowerCase()==="lender"){ console.log("--- "+tab+" ---"); this.downdloadExcelInvestorPage(locators.lenderTabExcelButton,locators.lenderTabExcelYesButton,locators.lenderTabExcelDownloadButton,locators.lenderTabExcelCloseButton,testname); }else{ console.log("Incorrect Tab."); } }
async function downloadGeneric(tab: string,testname: string){ const attributes = { owners: { excelButton: locators.ownersTabExcelButton, excelYesButton: locators.ownersTabExcelYesButton, excelDownloadButton: locators.ownersTabExcelDownloadButton, excelCloseButton: locators.ownersTabExcelCloseButton }, jvs: { excelButton: locators.jvsTabExcelButton, excelYesButton: locators.jvsTabExcelYesButton, excelDownloadButton: locators.jvsTabExcelDownloadButton, excelCloseButton: locators.jvsTabExcelCloseButton } }; try { await this.page.waitForTimeout(2000); console.log("--- "+tab+" ---"); await this.downdloadExcelInvestorPage(attributes[tab].excelButton,attributes[tab].excelYesButton,attributes[tab].excelDownloadButton,attributes[tab].excelCloseButton,testname); } catch (error) { console.log(error); } }
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].