Skip to main content
No Result Found

Dynamic device capability on Automate

Use regular expression to select a device for Selenium testing on BrowserStack Automate. Test on 3000+ devices on our real device cloud.

You can use regular expressions (regex) to select devices to test on, instead of providing specific device models in your capabilities. Based on the regex you pass, an available device is dynamically allocated from the available device pool that matches your specifications.

This approach not only affords you greater flexibility in test device selection, but also eliminates testing queues induced by device tier limits. Moreover, by broadening your search criteria using regular expressions, you can expedite your tests with an expanded device coverage, thereby enhancing test execution speed and efficiency.

If you are using BrowserStack’s SDK as your integration method, then you can also use regex in your browserstack.yml file to specify device attributes as shown below:

Capability Requirement Description Sample Values
deviceType Optional Specify the type of device phone for phone or tablet for a tablet

Note: Please specify the platform or osVersion when using deviceType
deviceName Required Specify the device name or use regular expression, a matching device based on your specification will be allocated

To allocate devices between iPhone 10 and 11

To allocate any iPhone

To avoid allocation of Oppo or Huawei devices





- iPhone [10-11]


- iPhone.*

- ^(?=Oppo.*|Huawei.* ).*

The following code snippet demonstrates running a test on any Samsung Galaxy S series phone:

browserstack.yml
Copy icon Copy

The following code snippet demonstrates running a test from a pool of two devices:

browserstack.yml
Copy icon Copy

BrowserStack SDK is a plug-n-play solution that takes care of all the integration steps for you. Using the BrowserStack SDK is the recommended integration method for your project. To know more, visit the SDK core concepts page.

Capability Requirement Description Sample Values
deviceType Optional Specify the type of device phone for phone or tablet for a tablet

Note: Please specify the platform or osVersion when using deviceType
deviceName Required Specify the device name or use regular expression, a matching device based on your specification will be allocated

To allocate devices between iPhone 10 and 11

To allocate any iPhone

To avoid allocation of Oppo or Huawei devices





- iPhone [10-11]


- iPhone.*

- ^(?=Oppo.*|Huawei.* ).*

The following code snippet demonstrates running a test on any Samsung Galaxy S series phone:

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("platformName", "android");
capabilities.setCapability("deviceName", "Samsung Galaxy S.*");
var capabilities = {
    "platformName" : "android",
    "deviceName" : "Samsung Galaxy S.*",
}
AppiumOptions capabilities = new AppiumOptions();
Dictionary<string, object> browserstackOptions = new Dictionary<string, object>();
capabilities.AddAdditionalCapability("platformName", "android");
capabilities.AddAdditionalCapability("deviceName", "Samsung Galaxy S.*");
desired_cap = {
    "platformName" : "android",
    "deviceName" : "Samsung Galaxy S.*",
}
capabilities = {
    "platformName" => "android",
    "deviceName" => "Samsung Galaxy S.*",
}
Capability Required/Optional Description Sample Values
deviceType Optional Specify the type of device phone for phone or tablet for a tablet

Note: Please specify the platform or osVersion when using deviceType
os Required Specify the mobile operating system that you wish to test on android or ios
device Required Specify the device name or use regular expression, a matching device based on your specification will be allocated

To allocate devices between iPhone 10 and 11

To allocate either iPad or iPhone

To allocate iPhone XR




- iPhone [10-11]


- iPad.*,iPhone.*

- iPhone XR$

The following code snippet demonstrates running a test on any Samsung Galaxy S series phone:

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("device", "Samsung Galaxy S.*");
var capabilities = {
    "device" : "Samsung Galaxy S.*",
}
AppiumOptions capabilities = new AppiumOptions();
Dictionary<string, object> browserstackOptions = new Dictionary<string, object>();
capabilities.AddAdditionalCapability("device", "Samsung Galaxy S.*");
desired_cap = {
    "device" : "Samsung Galaxy S.*",
}
desired_caps = {
    "device" => "Samsung Galaxy S.*",
}

To run tests on a single device from a pool of devices, see Run Tests on a Single Device on Automate

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