|
| 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') |
0 commit comments