Execute Methods
All examples in this documentation are using the webdriverio
client.
Overview
TV Labs provides a superset of Appium functionality through execute methods that expose additional functionality of the platform that aren't traditionally available through Appium. This page outlines the available execute methods.
Network Control
tvlabs: disableNetwork
Disables the network connection for the device, simulating a network outage. Returns true if the network was successfully disabled, otherwise returns an error.
Example:
await driver.execute('tvlabs: disableNetwork');
If a network throttle is active, it will be disabled when tvlabs: disableNetwork
is executed. After tvlabs: enableNetwork
is executed, the network throttle command will need to be explicitly re-enabled if desired.
await driver.execute('tvlabs: enableNetworkThrottle', { limitDown: 5 });
// Network is throttled
await driver.execute('tvlabs: disableNetwork');
// Network is offline
await driver.execute('tvlabs: enableNetwork');
// Network is online, no throttling enabled
await driver.execute('tvlabs: enableNetworkThrottle', { limitDown: 5 });
// Throttling re-enabled
tvlabs: enableNetwork
Restores the network connection after tvlabs: disableNetwork
was executed. Returns true if the network was successfully enabled, otherwise returns an error.
Example:
await driver.execute('tvlabs: enableNetwork');
tvlabs: isNetworkEnabled
Returns true if the network is enabled.
Example:
await driver.execute('tvlabs: disableNetwork');
const isNetworkEnabled = await driver.execute('tvlabs: isNetworkEnabled');
console.log(isNetworkEnabled);
// false
Network Throttling
tvlabs: enableNetworkThrottle
Enables network rate limiting for the device. Returns true if the rate limit was successfully enabled, otherwise returns an error.
Arguments:
limitDown
(required, number)- The download limit in mbits / second
limitUp
(optional, number | string)- The upload limit in mbits / second. Accepts "infinity" as a value.
- Default:
"infinity"
Example:
// Throttle download to 5 mbits / second
await driver.execute('tvlabs: enableNetworkThrottle', {
limitDown: 5,
});
tvlabs: disableNetworkThrottle
Disables network rate limiting for the device. Returns true if the rate limit was successfully disabled, otherwise returns an error.
Example:
await driver.execute('tvlabs: disableNetworkThrottle');
tvlabs: isNetworkThrottleEnabled
Returns true if the rate limit is enabled.
Example:
await driver.execute('tvlabs: enableNetworkThrottle', {
limitDown: 5,
});
const isNetworkThrottleEnabled = await driver.execute('tvlabs: isNetworkThrottleEnabled');
console.log(isNetworkThrottleEnabled);
// true
Network Capture
More details on network capture functionality can be found on the Network Capture page.
tvlabs: startNetworkCapture
Starts network capture for the current session.
Arguments:
reload
(optional, boolean)- Whether to reload the page after starting network capture
- Chromium-based platforms only
- Default:
true
cache
(optional, boolean)- Whether to enable or disable the page cache
- Chromium-based platforms only
- Default:
false
Example:
// Start a network capture with defaults
await driver.execute('tvlabs: startNetworkCapture');
// Start a network capture without reloading the page
await driver.execute('tvlabs: startNetworkCapture', {
reload: false,
});
On non-Chromium based platforms, after starting a network capture in an application that uses HTTP keep-alive, the application may need to be re-launched to ensure any open network connections are re-established and intercepted. This can be done with the terminateApp
and activateApp
methods.
tvlabs: stopNetworkCapture
Stops network capture and finalizes the HAR file for download. If the session network capture was started using capabilities, this method may be used to stop the capture before the session ends.
Arguments: None
Example:
// Stop an already running capture
await driver.execute('tvlabs: stopNetworkCapture');