How to Manage Multiple Browser Contexts in Playwright Using lambdaSetBrowserPosition?

How to Manage Multiple Browser Contexts in Playwright Using lambdaSetBrowserPosition?

Hey Saanvi,

You can manage multiple browser contexts in Playwright while using LambdaTest by leveraging the lambdaSetBrowserPosition capability.

Below is an example snippet demonstrating its usage:

await Page_1.evaluate(() => {}, `lambdatest_action: ${JSON.stringify({
        action: 'lambdaSetBrowserPosition',
      })}`);

To provide a complete understanding, here’s an example twoBrowser.ts file that shows how to manage multiple browser contexts effectively:

import { test as base, chromium, ChromiumBrowser } from '@playwright/test';

// Define your fixture
export const test = base.extend<{
  browser1: ChromiumBrowser;
  browser2: ChromiumBrowser;
}>({
  browser1: async ({}, use) => {
    const browser = await chromium.launch({
      headless: false,
      args: ['--window-size=1280,720', '--window-position=0,0'],
    });
    await use(browser);
  },
  browser2: async ({}, use) => {
    const browser = await chromium.launch({
      headless: false,
      args: ['--window-size=1280,720', '--window-position=1280,0'],
    });
    await use(browser);
  },
});

export { expect } from '@playwright/test';

Result:

For additional details, refer to the LambdaTest Playwright Capabilities Documentation and search for lambdaSetBrowserPosition.

If you have any questions or need further clarification, feel free to reach out.

Happy Testing! :tada: