Module: Appium::Core::Ios::Xcuitest::Device::Battery

Defined in:
lib/appium_lib_core/ios/xcuitest/device/battery.rb

Class Method Summary collapse

Class Method Details

.add_methodsObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/appium_lib_core/ios/xcuitest/device/battery.rb', line 21

def self.add_methods
  ::Appium::Core::Device.add_endpoint_method(:battery_info) do
    def battery_info
      response = execute_script 'mobile: batteryInfo', {}

      state = case response['state']
              when 1, 2, 3
                ::Appium::Core::Base::Device::BatteryStatus::IOS[response['state']]
              else
                ::Appium::Logger.warn("The state is unknown or undefined: #{response['state']}")
                ::Appium::Core::Base::Device::BatteryStatus::IOS[0] # :unknown
              end
      { state: state, level: response['level'] }
    end
  end
end