Rayrun
← Back to Discord Forum

Open new tab with Page Object page

michaldrajnaposted in #help-playwright
Open in Discord
michaldrajna
michaldrajna

Hi, how to open new tab and use there my page objects?

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?"

11 replies

you will need to initialize your page objects with the page from playwright

michaldrajna
michaldrajna

Oh ok and is it possible to switch between tabs to be visible page where interactions are now?

from playwright's side all tabs are active

michaldrajna
michaldrajna

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

await boPage.cookies() maybe?

instead of context

michaldrajna
michaldrajna

I tried it but I get : Property 'cookies' does not exist on type 'Page'.

ah right, cookies are on context only

maybe log count of cookies with idToken name

because it returns all cookies so perhaps you're getting the first cookie from another tab

@skorp32: Number of cookies with name "idToken": 1 :/

Number of cookies with name "idToken": 1 :/

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