Skip to content

Commit

Permalink
Update network throttling (#2836)
Browse files Browse the repository at this point in the history
* update network throttling with new features

* add to test configuration

* fix typo
  • Loading branch information
yuyi-sl authored Jul 5, 2024
1 parent 4465ffd commit 9bb6419
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 6 deletions.
32 changes: 32 additions & 0 deletions docs/dev/test-configuration-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -1603,6 +1603,38 @@ Each network condition has a supported value range:

---

### `sauce: network-profile`

<p><small>| OPTIONAL | STRING | <span className="sauceGreen">Real Devices Only</span> |</small></p>

Set a network profile with predefined network conditions dynamically during your session.
Please refer to the [list of network profiles](/mobile-apps/features/network-throttling/#predefined-network-profiles) for more information about each profile's network conditions.

```java
driver.executeScript("sauce: network-profile", "2G");
```

---

### `sauce: network-conditions`

<p><small>| OPTIONAL | OBJECT | <span className="sauceGreen">Real Devices Only</span> |</small></p>

Set custom network conditions for `downloadSpeed`, `uploadSpeed`, `latency` or `loss` dynamically during your session.
Not all parameters need to be specified and only the ones specified will have conditioning applied.
Please refer to [Network Throttling - executeScript](/mobile-apps/features/network-throttling/#appium---executescript) for more information.

```java
driver.executeScript("sauce: network-conditions", ImmutableMap.of(
"downloadSpeed", 5000,
"uploadSpeed", 3000,
"latency", 200,
"loss", 2,
));
```

---

### `mobile: shell`

<p><small>| OPTIONAL | STRING | <span className="sauceGreen">Real Devices Only</span> | <span className="sauceGreen">Android Only</span> |</small></p>
Expand Down
78 changes: 72 additions & 6 deletions docs/mobile-apps/features/network-throttling.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,84 @@ The following table shows the predefined network profiles along with their corre

## Automated Testing

### Appium
To use the Sauce Labs Network Throttling feature in your automated Appium test, you can add the sauce-specific capability
### Appium - Capability
To use the Sauce Labs Network Throttling feature in your automated Appium test, you can add the Sauce-specific capability
[networkConditions](https://docs.saucelabs.com/dev/test-configuration-options/#networkconditions) to provide custom network conditions for
the entire session.
Alternatively, you can use the sauce-specific capability [networkProfile](https://docs.saucelabs.com/dev/test-configuration-options/#networkprofile)
Alternatively, you can use the Sauce-specific capability [networkProfile](https://docs.saucelabs.com/dev/test-configuration-options/#networkprofile)
to apply one of the predefined network profiles to your session.

```java
MutableCapabilities capabilities = new MutableCapabilities();
//...
MutableCapabilities sauceOptions = new MutableCapabilities();

// network conditions
sauceOptions.setCapability("networkConditions", ImmutableMap.of(
"downloadSpeed", 5000,
"uploadSpeed", 3000,
"latency", 200,
"loss", 2,
));

// OR

// network profile
sauceOptions.setCapability("networkProfile", "2G");

capabilities.setCapability("sauce:options", sauceOptions);
```

### Appium - executeScript

To change your desired network conditions dynamically any time during your automated Appium test, use our Sauce-specific scripts
[sauce: network-conditions](/dev/test-configuration-options/#sauce-network-conditions) and [sauce: network-profile](/dev/test-configuration-options/#sauce-network-profile) with
[Appium's Execute Script](https://appium.io/docs/en/2.0/guides/execute-methods/).



```java title="Dynamically set Network Conditions"
driver.executeScript("sauce: network-conditions", ImmutableMap.of(
"downloadSpeed", 5000,
"uploadSpeed", 3000,
"latency", 200,
"loss", 2,
));
```

```java title="Dynamically set a Network Profile"
driver.executeScript("sauce: network-profile", "4G-fast");
```

To disable network throttling, use the predefined network profile `no-throttling`:

```java
driver.executeScript("sauce: network-profile", "no-throttling");
```

## Live Testing
Apply network throttling dynamically to your manual Live tests by selecting a predefined profile or by providing network conditions.

1. In the live test window, in the left toolbar, click **Throttle Network** to open the network throttling tool.

<img src={useBaseUrl('img/mobile-apps/throttle-network-1.png')} alt="Throttle Network tool" width="650"/>

2. Select a predefined profile from the dropdown to start the network throttling.

<img src={useBaseUrl('img/mobile-apps/throttle-network-2.png')} alt="Throttle Network profile selection" width="650"/>

An active network throttling is indicated by the **pulsing red dot** on the top left of the **Throttle Network** tool.

<img src={useBaseUrl('img/mobile-apps/throttle-network-3.png')} alt="Throttle Network profile selection" width="650"/>

3. Click on the **pulsing red dot** to **pause** the network throttling. A paused throttling is indicated by the **pause icon**.

<img src={useBaseUrl('img/mobile-apps/throttle-network-4.png')} alt="Throttle Network profile selection" width="650"/>

## Upcoming

* Apply network throttling to your manual Live tests
* Change your desired network conditions dynamically any time during your automated Appium test
* Apply network throttling to your Espresso and XCUITest tests
* Apply network throttling to your native Espresso and XCUITest tests


## Limitations
:::note Limitations
Expand Down
Binary file added static/img/mobile-apps/throttle-network-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img/mobile-apps/throttle-network-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img/mobile-apps/throttle-network-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img/mobile-apps/throttle-network-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9bb6419

Please sign in to comment.