Skip to main content
Experience faster, smarter testing with BrowserStack AI Agents. See what your workflow’s been missing. Explore now!
No Result Found
Connect & Get help from fellow developers on our Discord community. Ask the CommunityAsk the Community

Run C# Playwright-Android tests on BrowserStack Automate

Learn how to run your C# Playwright Android tests on BrowserStack Automate using the BrowserStack.Playwright package for .NET

Use the BrowserStack.Playwright NuGet package to run Playwright Android tests written in C# on real devices via BrowserStack Automate. This guide shows you how to install the package, configure capabilities, connect to an Android device, run a sample script, and mark the session status.

Prerequisites

  • BrowserStack Username and Access key. You can find this in your account profile. If you have not created an account yet, you can sign up for a Free Trial.
  • You have .NET 6.0 or later installed (run: dotnet --version).
  • You have removed any existing Microsoft.Playwright package to avoid conflicts.

Perform the steps given below to run a Playwright-Android test:

Install the BrowserStack Playwright package

Run the given command to add the BrowserStack.Playwright dependency to your project.

terminal
Copy icon Copy

Set your credentials securely

Execute the given command to set environment variables:

terminal
Copy icon Copy

Understand required capabilities

You must pass a capabilities JSON when establishing the WebSocket connection. Below are some key capability fields:

  • browserstack.username / browserstack.accessKey: Your credentials.
  • browser: chrome (Android currently supports Chrome).
  • device: Device name (Example: Samsung Galaxy S25 Ultra).
  • os_version: Android OS version.
  • name: Your test name (shown in Automate dashboard).
  • client.playwrightVersion: Local Playwright version.
  • browserstack.playwrightVersion: Remote Playwright version on BrowserStack (keep aligned for API compatibility).
  • browserstack.console: info,errors,warnings for console log verbosity.

Keep version pairs updated when upgrading locally.

Sample C# Android automation script

The following is a sample test script

sample-script.cs
Copy icon Copy

This script:

  • Connects to a BrowserStack Android device.
  • Launches a browser context.
  • Navigates to Google.
  • Marks the session as passed.

Run the test

Run the given command to execute the test on BrowserStack:

terminal
Copy icon Copy

The test connects to a real Android device, opens Chrome, loads Google, and ends the session.

View results in Automate dashboard

After the run:

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback!

Talk to an Expert
Download Copy Check Circle