playwright-fluent icon indicating copy to clipboard operation
playwright-fluent copied to clipboard

Reusing a browser instance rather than starting browser for each tests

Open franckLdx opened this issue 4 years ago • 2 comments

Is your feature request related to a problem? Please describe. Starting a browser for each test takes time. We could make a test campaigns faster by reusing single browser instance.

Describe the solution you'd like I would like to use one and only one browser instance and to create a context for each test. However this could have pitfalls for those who try to use parallelism. We should have the choice between using a single instance or not.

BR

Franck

franckLdx avatar Jan 27 '21 19:01 franckLdx

@franckLdx You can achieve such behaviour by creating new context in existing browser:

public async startNewIncognitoTab(playwrightFluent: PlaywrightFluent, options?: BrowserContextOptions): Promise<PlaywrightFluent> { const browser = await playwrightFluent.currentBrowser(); const context = await browser.newContext(options); const page = await context.newPage(); return new PlaywrightFluent(browser, page); }

Just close context after each test instead of browser, and then close browser once after all tests. Also new context will provide you with isolation on session level so your tests will not affect each other in parallel run.

osolomin90 avatar Dec 02 '21 14:12 osolomin90

Hi @osolomin90 , your solution is awesome ! Did not know it was possible to use my lib in such a way :)

hdorgeval avatar Dec 05 '21 00:12 hdorgeval