Get your setup working faster. Join our Discord for optimisation tips from elite testers.
Join our Discord
Run Playwright tests on Android devices
Learn how to run your Playwright tests on Android devices with BrowserStack Automate.
Prerequisites
Playwright for Android supports Node.js, Java, and C# only.
Quickstart
To run your Playwright test suite with Android devices on BrowserStack, perform the following steps:
Refer to the steps provided in the run your first test page.
In Step 3, while configuring your browserstack.yml file, use the deviceName parameter and specify the devices parameters as shown below:
```yml
userName: YOUR_USERNAME
accessKey: YOUR_ACCESS_KEY
platforms:
- browserName: chrome
osVersion: 15.0
deviceName: Samsung Galaxy S25 Ultra
- browserName: chrome
osVersion: 16.0
deviceName: Google Pixel 10
- browserName: chrome
osVersion: 16.0
deviceName: Google Pixel 9
```
Copy
Select over 100+ browsers-OS combinations from the list of supported device and OS.
Clone sample repository
Clone our sample Git repository using the following command:
```bash
git clone -b playwright-legacy https://github.com/browserstack/node-js-playwright-browserstack.git
cd node-js-playwright-browserstack
```
Copy
Install dependencies
Install the required dependencies by running the following command:
Set access credentials
Set the environment variables BROWSERSTACK_USERNAME and BROWSERSTACK_ACCESS_KEY with your credentials as follows:
```bash
export BROWSERSTACK_USERNAME="YOUR_USERNAME"
export BROWSERSTACK_ACCESS_KEY="YOUR_ACCESS_KEY"
```
Copy
Alternatively, you can add your credentials to the browserstack.username and browserstack.accessKey capabilities in the fixtures.js file.
Execute build on BrowserStack
You are now ready to run your build on BrowserStack. From the root directory of the project, run the following command:
Understanding the test configurations
Set Browser-OS combination
You can set the Android Browser-OS combination in the playwright.config.js as shown:
```javascript
projects: [
{
name: "chrome@Samsung Galaxy S22:13@browserstack-mobile",
use: {
baseURL: "https://www.bstackdemo.com/",
browserName: "chromium",
channel: "chrome",
},
},
],
```
Copy
Patching the capabilities dynamically
The patchMobileCaps function within the fixture.js file facilitates dynamic patching of the capabilities according to the project name.
```javascript
const patchMobileCaps = (name, title) => {
let combination = name.split(/@browserstack/)[0];
let [browserCaps, osCaps] = combination.split(/:/);
let [browser, deviceName] = browserCaps.split(/@/);
let osCapsSplit = osCaps.split(/ /);
let os = osCapsSplit.shift();
let osVersion = osCapsSplit.join(" ");
caps.browser = browser ? browser : "chrome";
caps.deviceName = deviceName ? deviceName : "Samsung Galaxy S22 Ultra";
caps.osVersion = osVersion ? osVersion : "12.0";
caps.name = title;
caps.realMobile = "true";
};
```
Copy
Is this page helping you?
Thank you for your valuable feedback!