Skip to content

Commit 5abaaff

Browse files
authored
Support set_network_speed (appium#386)
* Support set_nework_speed * Add set_network_speed unittest * Add api doc * revert unexpected change * revert change
1 parent af2fa70 commit 5abaaff

4 files changed

Lines changed: 56 additions & 4 deletions

File tree

appium/webdriver/extensions/android/gsm.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ def make_gsm_call(self, phone_number, action):
5252
5353
:Args:
5454
- phone_number (str): The phone number to call to.
55-
- action (str): The call action - GsmCallActions.CALL/ACCEPT/CANCEL/HOLD
55+
- action (str): The call action.
56+
A member of the const appium.webdriver.extensions.android.gsm.GsmCallActions
5657
5758
:Usage:
5859
self.driver.make_gsm_call('5551234567', GsmCallActions.CALL)
@@ -69,7 +70,8 @@ def set_gsm_signal(self, strength):
6970
Android only.
7071
7172
:Args:
72-
- strength (int): Signal strength - GsmSignalStrength.NONE_OR_UNKNOWN/POOR/MODERATE/GOOD/GREAT
73+
- strength (int): Signal strength.
74+
A member of the enum appium.webdriver.extensions.android.gsm.GsmSignalStrength
7375
7476
:Usage:
7577
self.driver.set_gsm_signal(GsmSignalStrength.GOOD)
@@ -86,7 +88,8 @@ def set_gsm_voice(self, state):
8688
Android only.
8789
8890
:Args:
89-
- state(str): State of GSM voice - GsmVoiceState.UNREGISTERED/HOME/ROAMING/SEARCHING/DENIED/OFF/ON
91+
- state(str): State of GSM voice.
92+
A member of the const appium.webdriver.extensions.android.gsm.GsmVoiceState
9093
9194
:Usage:
9295
self.driver.set_gsm_voice(GsmVoiceState.HOME)

appium/webdriver/extensions/android/network.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,23 @@
1414

1515
from selenium import webdriver
1616

17+
from appium.common.helper import extract_const_attributes
18+
from appium.common.logger import logger
1719
from appium.webdriver.mobilecommand import MobileCommand as Command
1820

1921

22+
class NetSpeed(object):
23+
GSM = 'gsm' # GSM/CSD (up: 14.4(kbps), down: 14.4(kbps))
24+
SCSD = 'scsd' # HSCSD (up: 14.4, down: 57.6)
25+
GPRS = 'gprs' # GPRS (up: 28.8, down: 57.6)
26+
EDGE = 'edge' # EDGE/EGPRS (up: 473.6, down: 473.6)
27+
UMTS = 'umts' # UMTS/3G (up: 384.0, down: 384.0)
28+
HSDPA = 'hsdpa' # HSDPA (up: 5760.0, down: 13,980.0)
29+
LTE = 'lte' # LTE (up: 58,000, down: 173,000)
30+
EVDO = 'evdo' # EVDO (up: 75,000, down: 280,000)
31+
FULL = 'full' # No limit, the default (up: 0.0, down: 0.0)
32+
33+
2034
class Network(webdriver.Remote):
2135

2236
@property
@@ -40,7 +54,7 @@ def set_network_connection(self, connection_type):
4054
These are available through the enumeration `appium.webdriver.ConnectionType`
4155
4256
:Args:
43-
- connectionType - a member of the enum appium.webdriver.ConnectionType
57+
- connection_type - a member of the enum appium.webdriver.ConnectionType
4458
"""
4559
data = {
4660
'parameters': {
@@ -55,6 +69,25 @@ def toggle_wifi(self):
5569
self.execute(Command.TOGGLE_WIFI, {})
5670
return self
5771

72+
def set_network_speed(self, speed_type):
73+
"""Set the network speed emulation.
74+
Android Emulator only.
75+
76+
:Args:
77+
- speed_type (str): The network speed type.
78+
A member of the const appium.webdriver.extensions.android.network.NetSpeed.
79+
80+
:Usage:
81+
self.driver.set_network_speed(NetSpeed.LTE)
82+
"""
83+
constants = extract_const_attributes(NetSpeed)
84+
if speed_type not in constants.values():
85+
logger.warning('{} is unknown. Consider using one of {} constants. (e.g. {}.LTE)'.format(
86+
speed_type, list(constants.keys()), NetSpeed.__name__))
87+
88+
self.execute(Command.SET_NETWORK_SPEED, {'netspeed': speed_type})
89+
return self
90+
5891
# pylint: disable=protected-access
5992

6093
def _addCommands(self):
@@ -64,3 +97,5 @@ def _addCommands(self):
6497
('GET', '/session/$sessionId/network_connection')
6598
self.command_executor._commands[Command.SET_NETWORK_CONNECTION] = \
6699
('POST', '/session/$sessionId/network_connection')
100+
self.command_executor._commands[Command.SET_NETWORK_SPEED] = \
101+
('POST', '/session/$sessionId/appium/device/network_speed')

appium/webdriver/mobilecommand.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class MobileCommand(object):
8585
GET_PERFORMANCE_DATA = 'getPerformanceData'
8686
GET_NETWORK_CONNECTION = 'getNetworkConnection'
8787
SET_NETWORK_CONNECTION = 'setNetworkConnection'
88+
SET_NETWORK_SPEED = 'setNetworkSpeed'
8889

8990
# Android Emulator
9091
SEND_SMS = 'sendSms'

test/unit/webdriver/device/network_test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import httpretty
2323

24+
from appium.webdriver.extensions.android.network import NetSpeed
2425
from appium.webdriver.webdriver import WebDriver
2526

2627

@@ -49,6 +50,18 @@ def test_set_network_connection(self):
4950
d = get_httpretty_request_body(httpretty.last_request())
5051
assert d['parameters']['type'] == 2
5152

53+
@httpretty.activate
54+
def test_set_network_speed(self):
55+
driver = android_w3c_driver()
56+
httpretty.register_uri(
57+
httpretty.POST,
58+
appium_command('/session/1234567890/appium/device/network_speed'),
59+
)
60+
assert isinstance(driver.set_network_speed(NetSpeed.LTE), WebDriver)
61+
62+
d = get_httpretty_request_body(httpretty.last_request())
63+
assert d['netspeed'] == NetSpeed.LTE
64+
5265
@httpretty.activate
5366
def test_toggle_wifi(self):
5467
driver = android_w3c_driver()

0 commit comments

Comments
 (0)