Use regular expression to specify device attributes
You can use regular expressions (regex) to select devices to test on instead of providing specific device models in the deviceName
(W3C protocol) or device
(JSON wire protocol) capability and OS versions in the platformVersion
(W3C protocol) or os_version
(JSON wire protocol) capability.
Based on the regex you pass, an available device is allocated from the device pool that matches your specifications.
By widening your search through regular expressions, you get better test execution speed by reducing queuing and device tier limits.
The following code snippet demonstrates running a test on any Samsung Galaxy S series phone with an Android version between 10 and 12:
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 | Required/Optional | Description | Sample Values |
---|---|---|---|
platformName |
Required | Specify the mobile operating system that you wish to test on |
android or ios
|
deviceName |
Required | Specify the device name or use regular expression, a matching device based on your specification will be allocated |
Samsung .* allocates any Samsung device iPhone [67]$ allocates iPhone 6 or iPhone 7 |
platformVersion |
Optional | Provide major OS version or range of OS versions using regex |
1[012] allocates version 10 , 11 or 12
|
deviceType |
Optional | Specify the type of device |
phone for phone or tablet for a tablet |
Note the following while using the platformVersion
capability:
- Minor and patch OS versions are not honored in the
platformVersion
capability. - Escape characters are not supported.
You can run tests on a wider set of devices. For example, to run tests on any Samsung Galaxy S series device refer to the following syntax:
The following code snippet demonstrates running a test from a pool of two devices:
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 | Required/Optional | Description | Sample Values |
---|---|---|---|
platformName |
Required | Specify the mobile operating system that you wish to test on |
android or ios
|
deviceName |
Required | Specify the device name or use regular expression, a matching device based on your specification will be allocated |
Samsung .* allocates any Samsung device iPhone [67]$ allocates iPhone 6 or iPhone 7 |
platformVersion |
Optional | Provide major OS version or range of OS versions using regex |
1[012] allocates version 10 , 11 or 12
|
deviceType |
Optional | Specify the type of device |
phone for phone or tablet for a tablet |
Note the following while using the platformVersion
capability:
- Minor and patch OS versions are not honored in the
platformVersion
capability. - Escape characters are not supported.
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("platformName", "android");
capabilities.setCapability("deviceName", "Samsung Galaxy S.*");
capabilities.setCapability("platformVersion", "1[012]");
var capabilities = {
"platformName" : "android",
"deviceName" : "Samsung Galaxy S.*",
"platformVersion" : "1[012]",
}
AppiumOptions capabilities = new AppiumOptions();
Dictionary<string, object> browserstackOptions = new Dictionary<string, object>();
capabilities.AddAdditionalCapability("platformName", "android");
capabilities.AddAdditionalCapability("deviceName", "Samsung Galaxy S.*");
capabilities.AddAdditionalCapability("platformVersion", "1[012]");
desired_cap = {
"platformName" : "android",
"deviceName" : "Samsung Galaxy S.*",
"platformVersion" : "1[012]",
}
capabilities = {
"platformName" => "android",
"deviceName" => "Samsung Galaxy S.*",
"platformVersion" => "1[012]",
}
Capability | Required/Optional | Description | Sample Values |
---|---|---|---|
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 |
Samsung .* allocates any Samsung device iPhone [67]$ allocates iPhone 6 or iPhone 7 |
os_version |
Optional | Provide major OS version or range of OS versions using regex |
1[012] allocates version 10 , 11 or 12
|
deviceType |
Optional | Specify the type of device |
phone for phone or tablet for a tablet |
Note the following while using the platformVersion
capability:
- Minor and patch OS versions are not honored in the
os_version
capability. - Escape characters are not supported.
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("platform", "android");
capabilities.setCapability("device", "Samsung Galaxy S.*");
capabilities.setCapability("os_version", "1[012]");
var capabilities = {
"platform" : "android",
"device" : "Samsung Galaxy S.*",
"os_version" : "1[012]",
}
AppiumOptions capabilities = new AppiumOptions();
Dictionary<string, object> browserstackOptions = new Dictionary<string, object>();
capabilities.AddAdditionalCapability("platform", "android");
capabilities.AddAdditionalCapability("device", "Samsung Galaxy S.*");
capabilities.AddAdditionalCapability("os_version", "1[012]");
desired_cap = {
"platform" : "android",
"device" : "Samsung Galaxy S.*",
"os_version" : "1[012]",
}
desired_caps = {
"platform" => "android",
"device" => "Samsung Galaxy S.*",
"os_version" => "1[012]",
}
To run tests on a single device from a pool of devices, see Run Tests on a Single Device on App 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
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!