question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature] Allow to set launchPersistentContext in playwright.config file

See original GitHub issue

On one of our projects, we need to run tests with extensions. To launch extensions, we have to set browserType.launchPersistentContext in the beforeAll section of each test.

It would be convenient to set launchPersistentContext in a playwright.config file, for instance:

    use: {
        launchPersistentContext: {
            userDataDir: '/tmp/test-user-data-dir',
            args: [
                `--disable-extensions-except=${path.join(__dirname, './my-extension')}`,
                `--load-extension=${path.join(__dirname, './my-extension')}`
            ]
        }
     }

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:74
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
seremboncommented, Jun 2, 2022

@schmkr Extension should be unpacked. Here is an example:

test.describe('Open Chrome with loaded extension', () => {
    let context: BrowserContext;
    let page: Page;

    test.beforeAll(async () => {
        context = await chromium.launchPersistentContext('/tmp/test-user-data', {
            headless: false,
            channel: 'chrome',
            args: [
                `--disable-extensions-except=${path.join(__dirname, '../files/my-extenstion')}`,
                `--load-extension=${path.join(__dirname, '../files/my-extenstion')}`,
            ],
        });
        page = await context.newPage();
    });

    test('Open extensions page', async () => {
        await page.goto('chrome://extensions/');
        await page.pause();
    });
});
4reactions
schmkrcommented, Jun 2, 2022

Yesterday, I also started an attempt to use Playwright Test for writing E2E tests for a Chrome Extension. But because the browser (by default) is launched in incognito, extensions don’t work.

It would be very helpful if it was made possible to define the browser(s) to launch with a persistent context. And/or in a more generic way, if it was possible to add a way to use a (factory) function that returns a browser instance upon invoking. Something like:

// playwright.config.ts
import { PlaywrightTestConfig, devices } from '@playwright/test';

const config: PlaywrightTestConfig = {
  projects: [
    {
      name: 'chromium-from-a-factory-fn',
      use: () => { // returns a browser instance when invoked },
    },
  ],
};
export default config;

@serembon I would be interested in how you set the browserType.launchPersistentContext in the beforeAll section of each test. Could you show an example?

Read more comments on GitHub >

github_iconTop Results From Across the Web

BrowserType | Playwright - CukeTest
BrowserType provides methods to launch a specific browser instance or connect to an existing one. The following is a typical example of using...
Read more >
Use launchPersistentContext in Playwright Internal With ...
Learn how to use launchPersistentContext function in Playwright Internal framework for your next JavaScript automation project with LambdaTest Automation ...
Read more >
Releases - CodeceptJS
Update codecept.conf.js to get intellisense when writing config file: ... set timeout for every test in suite to 10 secs Feature('tests with timeout', ......
Read more >
Playwright for - Go Packages
Package playwright is a library to automate Chromium, Firefox and WebKit with a single API. Playwright is built to enable cross-browser web ...
Read more >
How to load a chrome extension in playwright - Petros Kyriakou
This will create a playwright.config.js (or .ts) file and a few ... So make sure testDir in playwright.config.js(or .ts) is set to your ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found