|
| 1 | +module Appium |
| 2 | + module Android |
| 3 | + module Device |
| 4 | + module Emulator |
| 5 | + GSM_CALL_ACTIONS = [:call, :accept, :cancel, :hold].freeze |
| 6 | + |
| 7 | + GSM_VOICE_STATES = [:on, :off, :denied, :searching, :roaming, :home, :unregistered].freeze |
| 8 | + |
| 9 | + GSM_SIGNALS = { none_or_unknown: 0, poor: 1, moderate: 2, good: 3, great: 4 }.freeze |
| 10 | + |
| 11 | + # :gsm // GSM/CSD (up: 14.4, down: 14.4). |
| 12 | + # :scsd // HSCSD (up: 14.4, down: 57.6). |
| 13 | + # :gprs // GPRS (up: 28.8, down: 57.6). |
| 14 | + # :edge // EDGE/EGPRS (up: 473.6, down: 473.6). |
| 15 | + # :umts // UMTS/3G (up: 384.0, down: 384.0). |
| 16 | + # :hsdpa // HSDPA (up: 5760.0, down: 13,980.0). |
| 17 | + # :lte // LTE (up: 58,000, down: 173,000). |
| 18 | + # :evdo // EVDO (up: 75,000, down: 280,000). |
| 19 | + # :full // No limit, the default (up: 0.0, down: 0.0). |
| 20 | + NET_SPEED = [:gsm, :scsd, :gprs, :edge, :umts, :hsdpa, :lte, :evdo, :full].freeze |
| 21 | + |
| 22 | + POWER_AC_STATE = [:on, :off].freeze |
| 23 | + |
| 24 | + # @!method send_sms(phone_number:, message:) |
| 25 | + # Emulate send SMS event on the connected emulator. |
| 26 | + # |
| 27 | + # @param [String] phone_number: The phone number of message sender |
| 28 | + # @param [String] message: The message to send |
| 29 | + # |
| 30 | + # @example |
| 31 | + # |
| 32 | + # @driver.send_sms phone_number: '00000000000', message: 'test message' |
| 33 | + # |
| 34 | + |
| 35 | + # @!method gsm_call(phone_number:, action:) |
| 36 | + # Emulate GSM call event on the connected emulator. |
| 37 | + # |
| 38 | + # @param [String] phone_number: The phone number of message sender |
| 39 | + # @param [Hash] action: One of available GSM call actions. Available action is GSM_CALL_ACTION. |
| 40 | + # |
| 41 | + # @example |
| 42 | + # |
| 43 | + # @driver.gsm_call phone_number: '00000000000', action: :call |
| 44 | + # |
| 45 | + |
| 46 | + # @!method gsm_signal(signal_strength) |
| 47 | + # Emulate GSM signal strength change event on the connected emulator. |
| 48 | + # |
| 49 | + # @param [Hash] signal_strength One of available GSM signal strength. Available action is GSM_SIGNAL. |
| 50 | + # |
| 51 | + # @example |
| 52 | + # |
| 53 | + # @driver.gsm_signal :good |
| 54 | + # |
| 55 | + |
| 56 | + # @!method gsm_voice(state) |
| 57 | + # Emulate GSM voice event on the connected emulator. |
| 58 | + # |
| 59 | + # @param [Hash] state One of available GSM voice state. Available action is GSM_VOICE_STATE. |
| 60 | + # |
| 61 | + # @example |
| 62 | + # |
| 63 | + # @driver.gsm_voice :on |
| 64 | + # |
| 65 | + |
| 66 | + # @!method set_network_speed(netspeed) |
| 67 | + # Emulate network speed change event on the connected emulator. |
| 68 | + # |
| 69 | + # @param [Hash] netspeed One of available Network Speed values. Available action is NET_SPEED. |
| 70 | + # |
| 71 | + # @example |
| 72 | + # |
| 73 | + # @driver.set_network_speed :gsm |
| 74 | + # |
| 75 | + |
| 76 | + # @!method set_power_capacity(percent) |
| 77 | + # Emulate power capacity change on the connected emulator. |
| 78 | + # |
| 79 | + # @param [Integer] percent Percentage value in range [0, 100]. |
| 80 | + # |
| 81 | + # @example |
| 82 | + # |
| 83 | + # @driver.set_power_capacity 10 |
| 84 | + # |
| 85 | + |
| 86 | + # @!method set_power_ac(state) |
| 87 | + # Emulate power state change on the connected emulator. |
| 88 | + # |
| 89 | + # @param [Hash] state One of available power AC state. Available action is POWER_AC_STATE. |
| 90 | + # |
| 91 | + # @example |
| 92 | + # |
| 93 | + # @driver.set_power_ac :on |
| 94 | + # |
| 95 | + def self.emulator_commands |
| 96 | + Appium::Core::Device.add_endpoint_method(:send_sms) do |
| 97 | + def send_sms(phone_number:, message:) |
| 98 | + execute(:send_sms, {}, { phoneNumber: phone_number, message: message }) |
| 99 | + end |
| 100 | + end |
| 101 | + |
| 102 | + Appium::Core::Device.add_endpoint_method(:gsm_call) do |
| 103 | + def gsm_call(phone_number:, action:) |
| 104 | + unless GSM_CALL_ACTIONS.member? action.to_sym |
| 105 | + raise "action: should be member of #{GSM_CALL_ACTIONS}. Not #{action}." |
| 106 | + end |
| 107 | + |
| 108 | + execute(:gsm_call, {}, { phoneNumber: phone_number, action: action }) |
| 109 | + end |
| 110 | + end |
| 111 | + |
| 112 | + Appium::Core::Device.add_endpoint_method(:gsm_signal) do |
| 113 | + def gsm_signal(signal_strength) |
| 114 | + raise "#{signal_strength} should be member of #{GSM_SIGNALS} " if GSM_SIGNALS[signal_strength.to_sym].nil? |
| 115 | + |
| 116 | + execute(:gsm_signal, {}, { signalStrengh: GSM_SIGNALS[signal_strength] }) |
| 117 | + end |
| 118 | + end |
| 119 | + |
| 120 | + Appium::Core::Device.add_endpoint_method(:gsm_voice) do |
| 121 | + def gsm_voice(state) |
| 122 | + unless GSM_VOICE_STATES.member? state.to_sym |
| 123 | + raise "The state should be member of #{GSM_VOICE_STATES}. Not #{state}." |
| 124 | + end |
| 125 | + |
| 126 | + execute(:gsm_voice, {}, { state: state }) |
| 127 | + end |
| 128 | + end |
| 129 | + |
| 130 | + Appium::Core::Device.add_endpoint_method(:set_network_speed) do |
| 131 | + def set_network_speed(netspeed) |
| 132 | + unless NET_SPEED.member? netspeed.to_sym |
| 133 | + raise "The netspeed should be member of #{NET_SPEED}. Not #{netspeed}." |
| 134 | + end |
| 135 | + |
| 136 | + execute(:set_network_speed, {}, { netspeed: netspeed }) |
| 137 | + end |
| 138 | + end |
| 139 | + |
| 140 | + Appium::Core::Device.add_endpoint_method(:set_power_capacity) do |
| 141 | + def set_power_capacity(percent) |
| 142 | + unless (0..100).member? percent |
| 143 | + raise "The percent should be between 0 and 100. Not #{percent}." |
| 144 | + end |
| 145 | + |
| 146 | + execute(:set_power_capacity, {}, { percent: percent }) |
| 147 | + end |
| 148 | + end |
| 149 | + |
| 150 | + Appium::Core::Device.add_endpoint_method(:set_power_ac) do |
| 151 | + def set_power_ac(state) |
| 152 | + unless POWER_AC_STATE.member? state.to_sym |
| 153 | + raise "The state should be member of #{POWER_AC_STATE}. Not #{state}." |
| 154 | + end |
| 155 | + |
| 156 | + execute(:set_power_ac, {}, { state: state }) |
| 157 | + end |
| 158 | + end |
| 159 | + end # def self.emulator_commands |
| 160 | + end # module Emulator |
| 161 | + end # module Device |
| 162 | + end # module Android |
| 163 | +end # module Appium |
0 commit comments