Module appium.webdriver.extensions.android.gsm
Expand source code
#!/usr/bin/env python
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TypeVar
from selenium import webdriver
from appium.common.helper import extract_const_attributes
from appium.common.logger import logger
from appium.webdriver.mobilecommand import MobileCommand as Command
class GsmCallActions:
CALL = 'call'
ACCEPT = 'accept'
CANCEL = 'cancel'
HOLD = 'hold'
class GsmSignalStrength:
NONE_OR_UNKNOWN = 0
POOR = 1
MODERATE = 2
GOOD = 3
GREAT = 4
class GsmVoiceState:
UNREGISTERED = 'unregistered'
HOME = 'home'
ROAMING = 'roaming'
SEARCHING = 'searching'
DENIED = 'denied'
OFF = 'off'
ON = 'on'
T = TypeVar('T', bound='Gsm')
class Gsm(webdriver.Remote):
def make_gsm_call(self, phone_number: str, action: str) -> T:
"""Make GSM call (Emulator only)
Android only.
Args:
phone_number (str): The phone number to call to.
action (str): The call action.
A member of the const `appium.webdriver.extensions.android.gsm.GsmCallActions`
:Usage:
self.driver.make_gsm_call('5551234567', GsmCallActions.CALL)
"""
constants = extract_const_attributes(GsmCallActions)
if action not in constants.values():
logger.warning(
f'{action} is unknown. Consider using one of {list(constants.keys())} constants. (e.g. {GsmCallActions.__name__}.CALL)')
self.execute(Command.MAKE_GSM_CALL, {'phoneNumber': phone_number, 'action': action})
return self
def set_gsm_signal(self, strength: int) -> T:
"""Set GSM signal strength (Emulator only)
Android only.
Args:
strength (int): Signal strength.
A member of the enum `appium.webdriver.extensions.android.gsm.GsmSignalStrength`
Usage:
self.driver.set_gsm_signal(GsmSignalStrength.GOOD)
"""
constants = extract_const_attributes(GsmSignalStrength)
if strength not in constants.values():
logger.warning(
f'{strength} is out of range. Consider using one of {list(constants.keys())} constants. (e.g. {GsmSignalStrength.__name__}.GOOD)')
self.execute(Command.SET_GSM_SIGNAL, {'signalStrength': strength, 'signalStrengh': strength})
return self
def set_gsm_voice(self, state: str) -> T:
"""Set GSM voice state (Emulator only)
Android only.
Args:
state (str): State of GSM voice.
A member of the const `appium.webdriver.extensions.android.gsm.GsmVoiceState`
Usage:
self.driver.set_gsm_voice(GsmVoiceState.HOME)
"""
constants = extract_const_attributes(GsmVoiceState)
if state not in constants.values():
logger.warning(
f'{state} is unknown. Consider using one of {list(constants.keys())} constants. (e.g. {GsmVoiceState.__name__}.HOME)')
self.execute(Command.SET_GSM_VOICE, {'state': state})
return self
# pylint: disable=protected-access
def _addCommands(self) -> None:
self.command_executor._commands[Command.MAKE_GSM_CALL] = \
('POST', '/session/$sessionId/appium/device/gsm_call')
self.command_executor._commands[Command.SET_GSM_SIGNAL] = \
('POST', '/session/$sessionId/appium/device/gsm_signal')
self.command_executor._commands[Command.SET_GSM_VOICE] = \
('POST', '/session/$sessionId/appium/device/gsm_voice')
Classes
class Gsm (command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities=None, browser_profile=None, proxy=None, keep_alive=False, file_detector=None, options=None)
-
Controls a browser by sending commands to a remote server. This server is expected to be running the WebDriver wire protocol as defined at https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol
:Attributes: - session_id - String ID of the browser session started and controlled by this WebDriver. - capabilities - Dictionaty of effective capabilities of this browser session as returned by the remote server. See https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities - command_executor - remote_connection.RemoteConnection object used to execute commands. - error_handler - errorhandler.ErrorHandler object used to handle errors.
Create a new driver that will issue commands using the wire protocol.
:Args: - command_executor - Either a string representing URL of the remote server or a custom remote_connection.RemoteConnection object. Defaults to 'http://127.0.0.1:4444/wd/hub'. - desired_capabilities - A dictionary of capabilities to request when starting the browser session. Required parameter. - browser_profile - A selenium.webdriver.firefox.firefox_profile.FirefoxProfile object. Only used if Firefox is requested. Optional. - proxy - A selenium.webdriver.common.proxy.Proxy object. The browser session will be started with given proxy settings, if possible. Optional. - keep_alive - Whether to configure remote_connection.RemoteConnection to use HTTP keep-alive. Defaults to False. - file_detector - Pass custom file detector object during instantiation. If None, then default LocalFileDetector() will be used. - options - instance of a driver options.Options class
Expand source code
class Gsm(webdriver.Remote): def make_gsm_call(self, phone_number: str, action: str) -> T: """Make GSM call (Emulator only) Android only. Args: phone_number (str): The phone number to call to. action (str): The call action. A member of the const `appium.webdriver.extensions.android.gsm.GsmCallActions` :Usage: self.driver.make_gsm_call('5551234567', GsmCallActions.CALL) """ constants = extract_const_attributes(GsmCallActions) if action not in constants.values(): logger.warning( f'{action} is unknown. Consider using one of {list(constants.keys())} constants. (e.g. {GsmCallActions.__name__}.CALL)') self.execute(Command.MAKE_GSM_CALL, {'phoneNumber': phone_number, 'action': action}) return self def set_gsm_signal(self, strength: int) -> T: """Set GSM signal strength (Emulator only) Android only. Args: strength (int): Signal strength. A member of the enum `appium.webdriver.extensions.android.gsm.GsmSignalStrength` Usage: self.driver.set_gsm_signal(GsmSignalStrength.GOOD) """ constants = extract_const_attributes(GsmSignalStrength) if strength not in constants.values(): logger.warning( f'{strength} is out of range. Consider using one of {list(constants.keys())} constants. (e.g. {GsmSignalStrength.__name__}.GOOD)') self.execute(Command.SET_GSM_SIGNAL, {'signalStrength': strength, 'signalStrengh': strength}) return self def set_gsm_voice(self, state: str) -> T: """Set GSM voice state (Emulator only) Android only. Args: state (str): State of GSM voice. A member of the const `appium.webdriver.extensions.android.gsm.GsmVoiceState` Usage: self.driver.set_gsm_voice(GsmVoiceState.HOME) """ constants = extract_const_attributes(GsmVoiceState) if state not in constants.values(): logger.warning( f'{state} is unknown. Consider using one of {list(constants.keys())} constants. (e.g. {GsmVoiceState.__name__}.HOME)') self.execute(Command.SET_GSM_VOICE, {'state': state}) return self # pylint: disable=protected-access def _addCommands(self) -> None: self.command_executor._commands[Command.MAKE_GSM_CALL] = \ ('POST', '/session/$sessionId/appium/device/gsm_call') self.command_executor._commands[Command.SET_GSM_SIGNAL] = \ ('POST', '/session/$sessionId/appium/device/gsm_signal') self.command_executor._commands[Command.SET_GSM_VOICE] = \ ('POST', '/session/$sessionId/appium/device/gsm_voice')
Ancestors
- selenium.webdriver.remote.webdriver.WebDriver
Subclasses
Methods
def make_gsm_call(self, phone_number, action)
-
Make GSM call (Emulator only)
Android only.
Args
phone_number
:str
- The phone number to call to.
action
:str
- The call action.
A member of the const
GsmCallActions
:Usage: self.driver.make_gsm_call('5551234567', GsmCallActions.CALL)
Expand source code
def make_gsm_call(self, phone_number: str, action: str) -> T: """Make GSM call (Emulator only) Android only. Args: phone_number (str): The phone number to call to. action (str): The call action. A member of the const `appium.webdriver.extensions.android.gsm.GsmCallActions` :Usage: self.driver.make_gsm_call('5551234567', GsmCallActions.CALL) """ constants = extract_const_attributes(GsmCallActions) if action not in constants.values(): logger.warning( f'{action} is unknown. Consider using one of {list(constants.keys())} constants. (e.g. {GsmCallActions.__name__}.CALL)') self.execute(Command.MAKE_GSM_CALL, {'phoneNumber': phone_number, 'action': action}) return self
def set_gsm_signal(self, strength)
-
Set GSM signal strength (Emulator only)
Android only.
Args
strength
:int
- Signal strength.
A member of the enum
GsmSignalStrength
Usage
self.driver.set_gsm_signal(GsmSignalStrength.GOOD)
Expand source code
def set_gsm_signal(self, strength: int) -> T: """Set GSM signal strength (Emulator only) Android only. Args: strength (int): Signal strength. A member of the enum `appium.webdriver.extensions.android.gsm.GsmSignalStrength` Usage: self.driver.set_gsm_signal(GsmSignalStrength.GOOD) """ constants = extract_const_attributes(GsmSignalStrength) if strength not in constants.values(): logger.warning( f'{strength} is out of range. Consider using one of {list(constants.keys())} constants. (e.g. {GsmSignalStrength.__name__}.GOOD)') self.execute(Command.SET_GSM_SIGNAL, {'signalStrength': strength, 'signalStrengh': strength}) return self
def set_gsm_voice(self, state)
-
Set GSM voice state (Emulator only)
Android only.
Args
state
:str
- State of GSM voice.
A member of the const
GsmVoiceState
Usage
self.driver.set_gsm_voice(GsmVoiceState.HOME)
Expand source code
def set_gsm_voice(self, state: str) -> T: """Set GSM voice state (Emulator only) Android only. Args: state (str): State of GSM voice. A member of the const `appium.webdriver.extensions.android.gsm.GsmVoiceState` Usage: self.driver.set_gsm_voice(GsmVoiceState.HOME) """ constants = extract_const_attributes(GsmVoiceState) if state not in constants.values(): logger.warning( f'{state} is unknown. Consider using one of {list(constants.keys())} constants. (e.g. {GsmVoiceState.__name__}.HOME)') self.execute(Command.SET_GSM_VOICE, {'state': state}) return self
class GsmCallActions (*args, **kwargs)
-
Expand source code
class GsmCallActions: CALL = 'call' ACCEPT = 'accept' CANCEL = 'cancel' HOLD = 'hold'
Class variables
var ACCEPT
-
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.
var CALL
-
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.
var CANCEL
-
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.
var HOLD
-
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.
class GsmSignalStrength (*args, **kwargs)
-
Expand source code
class GsmSignalStrength: NONE_OR_UNKNOWN = 0 POOR = 1 MODERATE = 2 GOOD = 3 GREAT = 4
Class variables
var GOOD
-
int([x]) -> integer int(x, base=10) -> integer
Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.int(). For floating point numbers, this truncates towards zero.
If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by '+' or '-' and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal.
>>> int('0b100', base=0) 4
var GREAT
-
int([x]) -> integer int(x, base=10) -> integer
Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.int(). For floating point numbers, this truncates towards zero.
If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by '+' or '-' and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal.
>>> int('0b100', base=0) 4
var MODERATE
-
int([x]) -> integer int(x, base=10) -> integer
Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.int(). For floating point numbers, this truncates towards zero.
If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by '+' or '-' and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal.
>>> int('0b100', base=0) 4
var NONE_OR_UNKNOWN
-
int([x]) -> integer int(x, base=10) -> integer
Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.int(). For floating point numbers, this truncates towards zero.
If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by '+' or '-' and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal.
>>> int('0b100', base=0) 4
var POOR
-
int([x]) -> integer int(x, base=10) -> integer
Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.int(). For floating point numbers, this truncates towards zero.
If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by '+' or '-' and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal.
>>> int('0b100', base=0) 4
class GsmVoiceState (*args, **kwargs)
-
Expand source code
class GsmVoiceState: UNREGISTERED = 'unregistered' HOME = 'home' ROAMING = 'roaming' SEARCHING = 'searching' DENIED = 'denied' OFF = 'off' ON = 'on'
Class variables
var DENIED
-
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.
var HOME
-
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.
var OFF
-
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.
var ON
-
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.
var ROAMING
-
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.
var SEARCHING
-
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.
var UNREGISTERED
-
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.