test.only("verify Moengage integration", async ({ page }) => { let networkRequests = ""; await page.route( "https://sdk-01.moengage.com/v2/report/", async (route, request) => { console.log("1*********************************"); networkRequests = request.postData()!; console.log("2**********************************"); console.log(networkRequests); console.log("3**********************************"); await route.continue(); } ); await page.goto( "https://rohitgupta.wingified.com/moengage.html?id=541364" , { waitUntil: "networkidle" } ); const moengageCookies: any = await page.context().cookies(); expect(JSON.stringify(moengageCookies)).toContain("_vis_opt_exp_20_combi"); console.log(networkRequests); console.log("4**********************************"); });
This thread is trying to answer question "Why is the route function not working in headless mode when trying to verify Moengage integration?"
My guess is that in headless mode, the authentication is unsuccessful. Have you recorded and inspected a trace file? https://playwright.dev/docs/trace-viewer-intro
Another suggestion: page.route is overkill if you only want to inspect a response. In such case you can better use page.waitForResponse: https://playwright.dev/docs/api/class-page#page-wait-for-response
Or, if you have multiple responses that you want to monitor and 'log': https://playwright.dev/docs/api/class-page#page-event-response
Checked again with getting all the urls & got to know that https://sdk-01.moengage.com/v2/report/* this is not available in headless mode while getting this in headed mode.
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].