Rayrun
โ† Back to Discord Forum

Problem with the tests

I have some tests that fail because I close the browser before doing any of the above steps. Is this possible as it is an async execution? Thanks!

This thread is trying to answer question "Why are some tests failing because the browser closes before certain steps are completed?"

12 replies

You probably miss some await , copy paste your code and we will be able to help you!

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, click on a button on the page that downloads an excel, but it can take a long time, more than 10 seconds yes. But shouldn't It wait for that step to finish before going to the next one? The Wait explicitly on the page I do it to try to wait for the excel to download.

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."); } }

Could it be because the downloadGeneric function is not async?

Probably you need to put await in "await this.page.waitForTimeout(2000);"

So, add this in your downloadGeneric function, make this function async

And on downdloadExcelInvestorPage maybe should be async too

Thanks, I am going to try it ๐Ÿ™‚

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); } }

@suarez677 I added some changes to avoid duplicated code.

it is just a suggestion ๐Ÿ™‚

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

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].