Run Playwright on BrowserStack

At work we use Selenium and BrowserStack for end-to-end tests in C#. How much work is it to connect Playwright to BrowserStack?

 

Prerequisites

For BrowserStack we need an account that can run code on the Automate feature. If you do not already have an account, you can create one for free and test BrowserStack.

 

Preparation

We need the credentials of our account to access BrowserStack. I do not like to add credentials into my code and prefer a .env file (as I do in my Python applications). For C# I tried dotenv.net and created a .env file in my project.

Do not forget to add .env to your .gitignore!

If the .env file is no longer tracked in Git, you can add your username and the access key for BrowserStack:

username=****
accessKey=****

 

Connect to BrowserStack

You find all the code you need to connect to BrowserStack in their documentation. I only changed the code to include the .env values and set the locale to "en-GB" to run my browser in English instead of Dutch.

The MarkTestStatus() method tells BrowserStack if your test was successful or not. That way our tests are marked accordingly in the BrowserStack Dashboard:

Our test run successful.

BrowserStack records a video for each of our tests, just as it does with Selenium.

Attention: Playwright 1.27.2 marks the build status on BrowserStack, but 1.28 only gives an unmarked status for the same code. If that part does not work for you, wait for a newer version.

 

Next

Running Playwright on BrowserStack required a bit of copy and paste and worked surprisingly well. For NUnit we best create our own class and inherit from that instead of PageTest. Next week we try to run Playwright on Selenium Grid to see if we get a similar experience.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.