Module: Appium::Core::Android::Device::Emulator

Defined in:
lib/appium_lib_core/android/device/emulator.rb

Constant Summary collapse

GSM_CALL_ACTIONS =
[:call, :accept, :cancel, :hold].freeze
GSM_VOICE_STATES =
[:on, :off, :denied, :searching, :roaming, :home, :unregistered].freeze
GSM_SIGNALS =
{ none_or_unknown: 0, poor: 1, moderate: 2, good: 3, great: 4 }.freeze
NET_SPEED =

:gsm // GSM/CSD (up: 14.4, down: 14.4). :scsd // HSCSD (up: 14.4, down: 57.6). :gprs // GPRS (up: 28.8, down: 57.6). :edge // EDGE/EGPRS (up: 473.6, down: 473.6). :umts // UMTS/3G (up: 384.0, down: 384.0). :hsdpa // HSDPA (up: 5760.0, down: 13,980.0). :lte // LTE (up: 58,000, down: 173,000). :evdo // EVDO (up: 75,000, down: 280,000). :full // No limit, the default (up: 0.0, down: 0.0).

[:gsm, :scsd, :gprs, :edge, :umts, :hsdpa, :lte, :evdo, :full].freeze
POWER_AC_STATE =
[:on, :off].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.add_methodsObject

self.emulator_commands


115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/appium_lib_core/android/device/emulator.rb', line 115

def self.add_methods
  ::Appium::Core::Device.add_endpoint_method(:send_sms) do
    def send_sms(phone_number:, message:)
      execute(:send_sms, {}, { phoneNumber: phone_number, message: message })
    end
  end

  ::Appium::Core::Device.add_endpoint_method(:gsm_call) do
    def gsm_call(phone_number:, action:)
      unless GSM_CALL_ACTIONS.member? action.to_sym
        raise "action: should be member of #{GSM_CALL_ACTIONS}. Not #{action}."
      end

      execute(:gsm_call, {}, { phoneNumber: phone_number, action: action })
    end
  end

  ::Appium::Core::Device.add_endpoint_method(:gsm_signal) do
    def gsm_signal(signal_strength)
      raise "#{signal_strength} should be member of #{GSM_SIGNALS.keys} " if GSM_SIGNALS[signal_strength.to_sym].nil?

      execute(:gsm_signal, {}, { signalStrength: GSM_SIGNALS[signal_strength],
                                 signalStrengh: GSM_SIGNALS[signal_strength] })
    end
  end

  ::Appium::Core::Device.add_endpoint_method(:gsm_voice) do
    def gsm_voice(state)
      unless GSM_VOICE_STATES.member? state.to_sym
        raise "The state should be member of #{GSM_VOICE_STATES}. Not #{state}."
      end

      execute(:gsm_voice, {}, { state: state })
    end
  end

  ::Appium::Core::Device.add_endpoint_method(:set_network_speed) do
    def set_network_speed(netspeed)
      raise "The netspeed should be member of #{NET_SPEED}. Not #{netspeed}." unless NET_SPEED.member? netspeed.to_sym

      execute(:set_network_speed, {}, { netspeed: netspeed })
    end
  end

  ::Appium::Core::Device.add_endpoint_method(:set_power_capacity) do
    def set_power_capacity(percent)
      unless (0..100).member? percent
        ::Appium::Logger.warn "The  percent should be between 0 and 100. Not #{percent}."
      end

      execute(:set_power_capacity, {}, { percent: percent })
    end
  end

  ::Appium::Core::Device.add_endpoint_method(:set_power_ac) do
    def set_power_ac(state)
      unless POWER_AC_STATE.member? state.to_sym
        raise "The state should be member of #{POWER_AC_STATE}. Not #{state}."
      end

      execute(:set_power_ac, {}, { state: state })
    end
  end
end

Instance Method Details

#gsm_call(phone_number: , action: ) ⇒ Object

Emulate GSM call event on the connected emulator.


# File 'lib/appium_lib_core/android/device/emulator.rb', line 50

#gsm_signal(signal_strength) ⇒ Object

Emulate GSM signal strength change event on the connected emulator.


# File 'lib/appium_lib_core/android/device/emulator.rb', line 61

#gsm_voice(state) ⇒ Object

Emulate GSM voice event on the connected emulator.


# File 'lib/appium_lib_core/android/device/emulator.rb', line 71

#send_sms(phone_number: , message: ) ⇒ Object

Emulate send SMS event on the connected emulator.


# File 'lib/appium_lib_core/android/device/emulator.rb', line 39

#set_network_speed(netspeed) ⇒ Object

Emulate network speed change event on the connected emulator.


# File 'lib/appium_lib_core/android/device/emulator.rb', line 81

#set_power_ac(state) ⇒ Object

Emulate power state change on the connected emulator.


# File 'lib/appium_lib_core/android/device/emulator.rb', line 101

#set_power_capacity(percent) ⇒ Object

Emulate power capacity change on the connected emulator.


# File 'lib/appium_lib_core/android/device/emulator.rb', line 91