Hey brother, can you please assist me how can i use one test login into another tab without closing 1st tab. this is my code. test.describe('Login tab demo', () => { test('1st admin login 1st tab', async function ({ page }) { await adminSigin.adminLogin(page) }) test('2nd tab login', async function ({ page }) { // how to use 1st tab login in new opened tab without close 1st tab await page.goto('admin link') }) }) Your help will useful for my work. thank
Hey there, Thanks for reaching out, Certainly! In Playwright, to use a login session from one tab in another without closing the first tab, you can share context or cookies between the tabs. Since tabs within the same browser context share cookies and storage by default, you can simply open a new tab in the same context and navigate to your desired URL. If your authentication state is stored in cookies or session storage, this method will allow the new tab to inherit the logged-in state from the first tab. test.describe('Login tab demo', () => { test('admin login and open a new tab', async ({ browser, context }) => { // First tab login const page = await context.newPage(); await adminSigin.adminLogin(page); // Perform login on the first tab // Open a new tab within the same context const newPage = await context.newPage(); // Now, navigate to the admin link in the new tab await newPage.goto('admin link'); // You can perform your tests here in the new tab // The new tab should have the same login session as the first tab // Optionally, if you need to interact with the first tab again, you can do so // Example: await page.goto('some other link'); // Cleanup: Closing tabs if necessary (optional) // await page.close(); // await newPage.close(); }); });
Glad to hear that! While we don't currently have a video on Popup modals, we'll consider creating one in the future. Please subscribe to our channel for updates on all our latest tutorials.
Hey there 👋🏻 To open a new tab without any pop-up using Playwright in Java, you can use page.click("a[target=_blank]"); This code finds a link () element on the page with the target attribute set to _blank (indicating that it should open in a new tab) and clicks on it. This will open a new tab without any pop-up.
📍𝐆𝐢𝐭𝐇𝐮𝐛 𝐋𝐢𝐧𝐤: github.com/ortoniKC/LambdaTest-Playwright-Java
Hey brother, can you please assist me how can i use one test login into another tab without closing 1st tab. this is my code. test.describe('Login tab demo', () => {
test('1st admin login 1st tab', async function ({ page }) {
await adminSigin.adminLogin(page)
})
test('2nd tab login', async function ({ page }) {
// how to use 1st tab login in new opened tab without close 1st tab
await page.goto('admin link')
})
}) Your help will useful for my work. thank
Hey there,
Thanks for reaching out,
Certainly! In Playwright, to use a login session from one tab in another without closing the first tab, you can share context or cookies between the tabs. Since tabs within the same browser context share cookies and storage by default, you can simply open a new tab in the same context and navigate to your desired URL. If your authentication state is stored in cookies or session storage, this method will allow the new tab to inherit the logged-in state from the first tab.
test.describe('Login tab demo', () => {
test('admin login and open a new tab', async ({ browser, context }) => {
// First tab login
const page = await context.newPage();
await adminSigin.adminLogin(page); // Perform login on the first tab
// Open a new tab within the same context
const newPage = await context.newPage();
// Now, navigate to the admin link in the new tab
await newPage.goto('admin link');
// You can perform your tests here in the new tab
// The new tab should have the same login session as the first tab
// Optionally, if you need to interact with the first tab again, you can do so
// Example: await page.goto('some other link');
// Cleanup: Closing tabs if necessary (optional)
// await page.close();
// await newPage.close();
});
});
Hi Koushik, thank you so much for your videos, you are a great teacher!
I got a question: do you have a video about how to handle popup modal(1:16) ?
Glad to hear that!
While we don't currently have a video on Popup modals, we'll consider creating one in the future.
Please subscribe to our channel for updates on all our latest tutorials.
how to open new tab without any popup ?
Hey there 👋🏻
To open a new tab without any pop-up using Playwright in Java, you can use
page.click("a[target=_blank]");
This code finds a link () element on the page with the target attribute set to _blank (indicating that it should open in a new tab) and clicks on it. This will open a new tab without any pop-up.
@@LambdaTest it didn't work for me.
Awesome. Thank you.
Thanks 😊
Subscribe to our channel to never miss an update on the upcoming tutorials! ✨