def _update_command_executor(self, keep_alive): """Update command executor following directConnect feature""" direct_protocol = 'directConnectProtocol' direct_host = 'directConnectHost' direct_port = 'directConnectPort' direct_path = 'directConnectPath' if (not {direct_protocol, direct_host, direct_port, direct_path}.issubset(set(self.capabilities))): message = 'Direct connect capabilities from server were:\n' for key in [direct_protocol, direct_host, direct_port, direct_path]: message += '{}: \'{}\'\n'.format(key, self.capabilities.get(key, '')) logger.warning(message) return protocol = self.capabilities[direct_protocol] hostname = self.capabilities[direct_host] port = self.capabilities[direct_port] path = self.capabilities[direct_path] executor = '{scheme}://{hostname}:{port}{path}'.format( scheme=protocol, hostname=hostname, port=port, path=path ) logger.info('Updated request endpoint to %s', executor) # Override command executor self.command_executor = RemoteConnection(executor, keep_alive=keep_alive) self._addCommands()
def _update_command_executor(self, keep_alive): """Update command executor following directConnect feature""" direct_protocol = 'directConnectProtocol' direct_host = 'directConnectHost' direct_port = 'directConnectPort' direct_path = 'directConnectPath' if (not {direct_protocol, direct_host, direct_port, direct_path}.issubset(set(self.capabilities))): message = 'Direct connect capabilities from server were:\n' for key in [direct_protocol, direct_host, direct_port, direct_path]: message += '{}: \'{}\'\n'.format(key, self.capabilities.get(key, '')) logger.warning(message) return protocol = self.capabilities[direct_protocol] hostname = self.capabilities[direct_host] port = self.capabilities[direct_port] path = self.capabilities[direct_path] executor = '{scheme}://{hostname}:{port}{path}'.format( scheme=protocol, hostname=hostname, port=port, path=path ) logger.info('Updated request endpoint to %s', executor) # Override command executor self.command_executor = RemoteConnection(executor, keep_alive=keep_alive) self._addCommands()
def set_gsm_signal(self: T, strength: int) -> T: """Set GSM signal strength (Emulator only) Android only. Args: strength: Signal strength. A member of the enum :obj:`appium.webdriver.extensions.android.gsm.GsmSignalStrength` Usage: self.driver.set_gsm_signal(GsmSignalStrength.GOOD) Returns: Union['WebDriver', 'Gsm']: Self instance """ 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. ' f'(e.g. {GsmSignalStrength.__name__}.GOOD)') self.execute(Command.SET_GSM_SIGNAL, { 'signalStrength': strength, 'signalStrengh': strength }) return self
def make_gsm_call(self: T, phone_number: str, action: str) -> T: """Make GSM call (Emulator only) Android only. Args: phone_number: The phone number to call to. action: The call action. A member of the const `appium.webdriver.extensions.android.gsm.GsmCallActions` Usage: self.driver.make_gsm_call('5551234567', GsmCallActions.CALL) Returns: Union['WebDriver', 'Gsm']: Self instance """ 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. ' f'(e.g. {GsmCallActions.__name__}.CALL)') self.execute(Command.MAKE_GSM_CALL, { 'phoneNumber': phone_number, 'action': action }) return self
def events(self): """ Retrieves events information from the current session Usage: events = driver.events Returns: `dict containing events timing information from the current session` """ try: session = self.session return session['events'] except Exception as e: logger.warning('Could not find events information in the session. Error:', e) return {}
def _merge_capabilities(self, capabilities: Dict) -> Dict[str, Any]: """Manage capabilities whether W3C format or MJSONWP format""" if _FORCE_MJSONWP in capabilities: logger.warning( "[Deprecated] 'forceMjsonwp' capability will be dropped after switching base selenium client from v3 to v4 " "to follow W3C spec capabilities. Appium 2.0 will also support only W3C session creation capabilities." ) force_mjsonwp = capabilities[_FORCE_MJSONWP] del capabilities[_FORCE_MJSONWP] if force_mjsonwp != False: return {'desiredCapabilities': capabilities} w3c_caps = _make_w3c_caps(capabilities) return {'capabilities': w3c_caps, 'desiredCapabilities': capabilities}
def set_gsm_voice(self, state): """Set GSM voice state (Emulator only) Android only. :Args: - state(str): State of GSM voice - GsmVoiceState.UNREGISTERED/HOME/ROAMING/SEARCHING/DENIED/OFF/ON :Usage: self.driver.set_gsm_voice(GsmVoiceState.HOME) """ constants = extract_const_attributes(GsmVoiceState) if state not in constants.values(): logger.warning('{} is unknown. Consider using one of {} constants. (e.g. {}.HOME)'.format( state, list(constants.keys()), GsmVoiceState.__name__)) self.execute(Command.SET_GSM_VOICE, {'state': state}) return self
def set_gsm_signal(self, strength): """Set GSM signal strength (Emulator only) Android only. :Args: - strength (int): Signal strength - GsmSignalStrength.NONE_OR_UNKNOWN/POOR/MODERATE/GOOD/GREAT :Usage: self.driver.set_gsm_signal(GsmSignalStrength.GOOD) """ constants = extract_const_attributes(GsmSignalStrength) if strength not in constants.values(): logger.warning('{} is out of range. Consider using one of {} constants. (e.g. {}.GOOD)'.format( strength, list(constants.keys()), GsmSignalStrength.__name__)) self.execute(Command.SET_GSM_SIGNAL, {'signalStrength': strength, 'signalStrengh': strength}) return self
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 - GsmCallActions.CALL/ACCEPT/CANCEL/HOLD :Usage: self.driver.make_gsm_call('5551234567', GsmCallActions.CALL) """ constants = extract_const_attributes(GsmCallActions) if action not in constants.values(): logger.warning('{} is unknown. Consider using one of {} constants. (e.g. {}.CALL)'.format( action, list(constants.keys()), GsmCallActions.__name__)) self.execute(Command.MAKE_GSM_CALL, {'phoneNumber': phone_number, 'action': action}) 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 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( '{} is unknown. Consider using one of {} constants. (e.g. {}.HOME)' .format(state, list(constants.keys()), GsmVoiceState.__name__)) self.execute(Command.SET_GSM_VOICE, {'state': state}) return self
def set_network_speed(self, speed_type): """Set the network speed emulation. Android Emulator only. :Args: - speed_type (str): The network speed type. A member of the const appium.webdriver.extensions.android.network.NetSpeed. :Usage: self.driver.set_network_speed(NetSpeed.LTE) """ constants = extract_const_attributes(NetSpeed) if speed_type not in constants.values(): logger.warning('{} is unknown. Consider using one of {} constants. (e.g. {}.LTE)'.format( speed_type, list(constants.keys()), NetSpeed.__name__)) self.execute(Command.SET_NETWORK_SPEED, {'netspeed': speed_type}) 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 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( '{} is out of range. Consider using one of {} constants. (e.g. {}.GOOD)' .format(strength, list(constants.keys()), GsmSignalStrength.__name__)) self.execute(Command.SET_GSM_SIGNAL, { 'signalStrength': strength, 'signalStrengh': strength }) return self
def set_gsm_voice(self: T, state: str) -> T: """Set GSM voice state (Emulator only) Android only. Args: state: State of GSM voice. A member of the const `appium.webdriver.extensions.android.gsm.GsmVoiceState` Usage: self.driver.set_gsm_voice(GsmVoiceState.HOME) Returns: Union['WebDriver', 'Gsm']: Self instance """ 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. ' f'(e.g. {GsmVoiceState.__name__}.HOME)') self.execute(Command.SET_GSM_VOICE, {'state': state}) return self
def set_network_speed(self: T, speed_type: str) -> T: """Set the network speed emulation. Android Emulator only. Args: speed_type: The network speed type. A member of the const appium.webdriver.extensions.android.network.NetSpeed. Usage: self.driver.set_network_speed(NetSpeed.LTE) Returns: Union['WebDriver', 'Network']: Self instance """ constants = extract_const_attributes(NetSpeed) if speed_type not in constants.values(): logger.warning( f'{speed_type} is unknown. Consider using one of {list(constants.keys())} constants. ' f'(e.g. {NetSpeed.__name__}.LTE)') self.execute(Command.SET_NETWORK_SPEED, {'netspeed': speed_type}) return self