Rayrun
← Back to Discord Forum

How to reuse the same browser session in multiple tests using C#?

I started using Playwright and managed to set up several tests, but I cannot find a way to reuse the same browser. Most of the information I can find is about JavaScript.

Do you have any examples of doing that using C#?

This thread is trying to answer question "How can one reuse the same browser session in multiple tests using C# with Playwright?"

1 reply

Here on this page, look at these classes: https://playwright.dev/dotnet/docs/test-runners#base-nunit-classes-for-playwright You may want to just use something from there, but if it doesn't suits your needs, you can do it yourself. Personally, I have created my own infrastructure for it, so I can have it exactly the way as I want to. If you are interested in doing it yourself, I might send you some code for inspiration, but you mostly learn a bit about NUnit (what is TestFixture, and what are OneTimeSetup / OneTimeTearDown / Setup / TearnDown methods) and basically, you can create your own Playwright object using: await Microsoft.Playwright.Playwright.CreateAsync(); From that object, you can create Browser, and from Browser, you can create BrowserContexts and so on... This way you can create your own infrastructure, which is awesome 🙂

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