This thread is trying to answer question "How to open a new tab and use page objects in it, switch between tabs, and get cookies and a specific token from the second tab using Playwright?"
Do u know please, how to get cookies and boToken from the second tab? I still get the same token (web token ) as from the first page:
// get web token
await test.step(Get cookies and save web token
, async () => {
const obj = await context.cookies();
const tokenObject = obj.filter((val) => val.name.includes('idToken'));
webToken = tokenObject.map((a) => a.value).toString();
console.log('Web token: ' + webToken);
});
// get BOU token
await test.step(`Get BO token`, async () => {
const boPage = await context.newPage();
const tabBoPage = new UsersBoPage(boPage);
await tabBoPage.visit();
await tabBoPage.login();
const object = await context.cookies();
const boTokenObject = object.filter((val) => val.name.includes('idToken'));
boToken = boTokenObject.map((a) => a.value).toString();
console.log('BOU token: ' + boToken);
});
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].