Simulate mobile network conditions
BrowserStack App Automate enables you to test mobile applications under various network conditions such as offline mode, airplane mode, and network profiles such as 3g-umts-good, 4g-lte-good, etc., on BrowserStack’s real mobile device cloud.
To simulate network conditions, you can use any of the pre-defined network profiles we provide or create a custom network profile.
In this guide, you will learn how to:
- Simulate device offline and airplane mode
- Simulate network conditions using predefined network profiles
- Simulate network conditions using a custom network profile
- Reset the device to default network configuration
Simulate device offline and airplane mode
Add following network profiles as the value to the networkProfile
key in your test script to simulate offline or airplane mode of a device.
Profile Name | Description |
---|---|
no-network |
Disables network on the device to put it in the offline mode. Note: This profile is supported on: - Android devices - all Android OS versions - iPhones - iOS 13 and above. |
airplane-mode |
Enables the airplane mode setting on an Android device to put it in the airplane mode. Note: This profile is supported on all Android devices except Oppo Reno 6, Xiaomi Redmi Note 9, Huawei P30, Oppo Reno 3 Pro, Vivo Y50, and Motorola Moto G9 Play. |
Set network mode at the start of session
To set the network mode at the start of the session, add the network profiles, no-network
or airplane-mode
, as a value to the browserstack.networkProfile
capability in your test script:
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("browserstack.networkProfile", "no-network");
var capabilities = {
'browserstack.networkProfile': 'no-network'
}
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.SetCapability("browserstack.networkProfile", "no-network");
$capabilities = new DesiredCapabilities();
$capabilities->setCapability("browserstack.networkProfile", "no-network");
capabilities = {
'browserstack.networkProfile': 'no-network'
}
capabilities = {
'browserstack.networkProfile': 'no-network'
}
Set network mode in the middle of session
While your session is running, run the following cURL command in your terminal to set the network mode in the middle of the session:
curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" -H "Content-Type: application/json" -d '{"networkProfile":"no-network"}' -X PUT "https://api-cloud.browserstack.com/app-automate/sessions/<sessionid>/update_network.json"
Replace <sessionid>
with the ID of your ongoing test session. To get the session ID of your ongoing test, check out the code snippets in the get session ID section.
Simulate network conditions using predefined network profiles
Add any of the predefined network profiles, provided by BrowserStack, as the value to the networkProfile
key in your test script to simulate various network conditions.
Set predefined network profile at the start of session
Add the predefined network profile as a value to the browserstack.networkProfile
capability to set a predefined network profile at the start of the session.
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("browserstack.networkProfile", "2g-gprs-good");
var capabilities = {
'browserstack.networkProfile': '2g-gprs-good'
}
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.SetCapability("browserstack.networkProfile", "2g-gprs-good");
$capabilities = new DesiredCapabilities();
$capabilities->setCapability("browserstack.networkProfile", "2g-gprs-good");
capabilities = {
'browserstack.networkProfile': '2g-gprs-good'
}
capabilities = {
'browserstack.networkProfile': '2g-gprs-good'
}
Set predefined network profile in the middle of session
While your session is running, run the following cURL command in your terminal to add the predefined network profiles. To see the predefined network profiles, check out this section.
curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" -H "Content-Type: application/json" -d '{"networkProfile":"2g-gprs-good"}' -X PUT "https://api-cloud.browserstack.com/app-automate/sessions/<sessionid>/update_network.json"
Replace <sessionid>
with the ID of your ongoing test session. To get the session ID of your ongoing test, check out the code snippets in the get session ID section.
Supported predefined network profile
The following table shows the supported predefined network profiles available in BrowserStack:
Profile Name | Bandwidth in/out (Kbps) | Latency (ms) | Packet Loss (%) |
---|---|---|---|
2g-gprs-good | 50/30 | 500 | 1 |
2g-gprs-lossy | 30/20 | 650 | 2 |
edge-good | 250/150 | 300 | 0 |
2gedge-lossy | 150/100 | 500 | 1 |
3g-umts-good | 400/100 | 100 | 0 |
3g-umts-lossy | 200/50 | 200 | 1 |
3.5g-hspa-good | 1800/400 | 100 | 0 |
3.5g-hspa-lossy | 900/200 | 190 | 1 |
3.5g-hspa-plus-good | 7000/1500 | 100 | 0 |
3.5g-hspa-plus-lossy | 2000/600 | 130 | 1 |
4g-lte-good | 18000/9000 | 100 | 0 |
4g-lte-high-latency | 18000/9000 | 3000 | 0 |
4g-lte-lossy | 7000/3000 | 120 | 1 |
4g-lte-advanced-good | 25000/18000 | 80 | 0 |
4g-lte-advanced-lossy | 15000/10000 | 70 | 1 |
reset | Removes predefined or custom network settings from the device and sets it back to its original state. | N/A | N/A |
Simulate network conditions using a custom network profile
Create a custom network profile using supported parameters to simulate network condition.
Set custom network condition at the start of session
Add the custom network parameters to the browserstack.customNetwork
capability to set a custom network profile at the start of the session, as shown in the following tab:
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("browserstack.customNetwork", "1000, 1000, 100, 1");
var capabilities = {
'browserstack.customNetwork': '1000, 1000, 100, 1'
}
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.SetCapability("browserstack.customNetwork", "1000, 1000, 100, 1");
$capabilities = new DesiredCapabilities();
$capabilities->setCapability("browserstack.customNetwork", "1000, 1000, 100, 1");
capabilities = {
'browserstack.customNetwork': '1000, 1000, 100, 1'
}
capabilities = {
'browserstack.customNetwork': '1000, 1000, 100, 1'
}
Set custom network profile in the middle of session
While your session is running, run the following cURL command in your terminal to set a custom network profile in the middle of the session. To see the parameters of a custom network profile, check out this section.
curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" -H "Content-Type: application/json" -d '{"customNetwork":"1000,1000,100,1"}' -X PUT "https://api-cloud.browserstack.com/app-automate/sessions/<sessionid>/update_network.json"
Replace <sessionid>
with the ID of your ongoing test session. To get the session ID of your ongoing test, check out the code snippets in the get session ID section.
Supported custom network profile parameters
The following table shows parameters to create a custom network profile:
Parameter | Range |
---|---|
Download speed | 0-50000 kbps |
Upload speed | 0-50000 kbps |
Latency | 0-3000 ms |
Packet loss | 0-99% |
Reset device to default network configuration
Use the following cURL request to set the value for networkProfile
or customNetwork
keys to reset
to remove the active network condition from the device and set it back to the default network.
- Remove configured network mode (
no-network
,airplane-mode
) and network condition (2G
,3G
, etc.) from a device:curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" -H "Content-Type: application/json" -d '{"networkProfile":"reset"}' -X PUT "https://api-cloud.browserstack.com/app-automate/sessions/<sessionid>/update_network.json"
- Reset custom network condition from a device:
curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" -H "Content-Type: application/json" -d '{"customNetwork":"reset"}' -X PUT "https://api-cloud.browserstack.com/app-automate/sessions/<sessionid>/update_network.json"
Replace
<sessionid>
with the ID of your ongoing test session. To get the session ID of your ongoing test, check out the code snippets in the get session ID section.
Need some help?
If you have any queries, get in touch with us.
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!