Skip to content

Commit 308fd1b

Browse files
authored
Support set_gsm_signal (#357)
* Support set_gsm_signal * Fix: NONE_OR_UNKNOWN doesn't work * Add set_gsm_signal unittest * Use int for signal strength const * Raise exception when signal strength is out of range * Fix: wrong class name * Removed args validation Since arg validation already done by server side * Show warning log when arg is out of range * Some changes for less maintenance
1 parent 984e572 commit 308fd1b

File tree

5 files changed

+105
-1
lines changed

5 files changed

+105
-1
lines changed

appium/webdriver/extensions/gsm.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env python
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from selenium import webdriver
16+
from ..mobilecommand import MobileCommand as Command
17+
18+
from appium.common.logger import logger
19+
20+
21+
class Gsm(webdriver.Remote):
22+
23+
(
24+
NONE_OR_UNKNOWN,
25+
POOR,
26+
MODERATE,
27+
GOOD,
28+
GREAT
29+
) = range(5)
30+
31+
def set_gsm_signal(self, strength):
32+
"""Set GSM signal strength (Emulator only)
33+
34+
:Args:
35+
- strength: Signal strength. Can be set Gsm.NONE_OR_UNKNOWN/POOR/MODERATE/GOOD/GREAT
36+
37+
:Usage:
38+
self.driver.set_gsm_signal(Gsm.GOOD)
39+
"""
40+
if strength not in self._dict_signal_strength().values():
41+
logger.warning('{} is out of range. Use the value in {}.'.format(
42+
strength, list(self._dict_signal_strength().keys())))
43+
self.execute(Command.SET_GSM_SIGNAL, {'signalStrength': strength, 'signalStrengh': strength})
44+
return self
45+
46+
def _dict_signal_strength(self):
47+
return {'{}.{}'.format(Gsm.__name__, attr): value for attr, value in vars(Gsm).items()
48+
if not callable(getattr(Gsm, attr)) and attr.isupper()}
49+
50+
# pylint: disable=protected-access
51+
52+
def _addCommands(self):
53+
self.command_executor._commands[Command.SET_GSM_SIGNAL] = \
54+
('POST', '/session/$sessionId/appium/device/gsm_signal')

appium/webdriver/mobilecommand.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,4 @@ class MobileCommand(object):
7979
SEND_SMS = 'sendSms'
8080
SET_POWER_CAPACITY = 'setPowerCapacity'
8181
SET_POWER_AC = 'setPowerAc'
82+
SET_GSM_SIGNAL = 'setGsmSignal'

appium/webdriver/webdriver.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from .extensions.clipboard import Clipboard
3333
from .extensions.context import Context
3434
from .extensions.device_time import DeviceTime
35+
from .extensions.gsm import Gsm
3536
from .extensions.images_comparison import ImagesComparison
3637
from .extensions.ime import IME
3738
from .extensions.keyboard import Keyboard
@@ -112,6 +113,7 @@ class WebDriver(
112113
Clipboard,
113114
Context,
114115
DeviceTime,
116+
Gsm,
115117
HardwareActions,
116118
ImagesComparison,
117119
IME,

test/unit/webdriver/device/device_time_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import httpretty
2222

2323

24-
class TestWebDriverDeviceLock(object):
24+
class TestWebDriverDeviceTime(object):
2525

2626
@httpretty.activate
2727
def test_device_time(self):
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env python
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from test.unit.helper.test_helper import (
16+
appium_command,
17+
android_w3c_driver,
18+
get_httpretty_request_body
19+
)
20+
21+
import httpretty
22+
23+
from appium.webdriver.webdriver import WebDriver
24+
from appium.webdriver.extensions.gsm import Gsm
25+
26+
27+
class TestWebDriveGsm(object):
28+
29+
def test_gsm_signal_strength(self):
30+
assert Gsm.NONE_OR_UNKNOWN == 0
31+
assert Gsm.POOR == 1
32+
assert Gsm.MODERATE == 2
33+
assert Gsm.GOOD == 3
34+
assert Gsm.GREAT == 4
35+
36+
@httpretty.activate
37+
def test_set_gsm_signal(self):
38+
driver = android_w3c_driver()
39+
httpretty.register_uri(
40+
httpretty.POST,
41+
appium_command('/session/1234567890/appium/device/gsm_signal'),
42+
)
43+
assert isinstance(driver.set_gsm_signal(Gsm.GREAT), WebDriver)
44+
45+
d = get_httpretty_request_body(httpretty.last_request())
46+
assert d['signalStrength'] == Gsm.GREAT
47+
assert d['signalStrengh'] == Gsm.GREAT

0 commit comments

Comments
 (0)