Module: Appium::Core::Base::HasLocation Private

Included in:
Driver
Defined in:
lib/appium_lib_core/common/base/has_location.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Instance Method Details

#location::Selenium::WebDriver::Location

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get the location of the device.

Examples:


driver.location #=> ::Selenium::WebDriver::Location.new(10, 10, 10)

Returns:

  • (::Selenium::WebDriver::Location)

30
31
32
# File 'lib/appium_lib_core/common/base/has_location.rb', line 30

def location
  @bridge.location
end

#location=(location) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Set the location of the device.

Examples:


driver.location = ::Selenium::WebDriver::Location.new(10, 10, 10)

Parameters:

  • location (::Selenium::WebDriver::Location)

    Set the location.


42
43
44
45
46
47
48
# File 'lib/appium_lib_core/common/base/has_location.rb', line 42

def location=(location)
  unless location.is_a?(::Selenium::WebDriver::Location)
    raise TypeError, "expected #{::Selenium::WebDriver::Location}, got #{location.inspect}:#{location.class}"
  end

  @bridge.set_location location.latitude, location.longitude, location.altitude
end

#set_location(latitude, longitude, altitude, speed: nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Set the location of the device.

Examples:


driver.location = ::Selenium::WebDriver::Location.new(10, 10, 10)

Parameters:

  • latitude (String, Number)

    Set the latitude.

  • longitude (String, Number)

    Set the longitude.

  • altitude (String, Number)

    Set the altitude.

  • speed (String, Number) (defaults to: nil)

    Set the speed to apply the location on Android real devices @since Appium 1.21.0.

  • (::Selenium::WebDriver::Location)

62
63
64
65
66
67
68
69
# File 'lib/appium_lib_core/common/base/has_location.rb', line 62

def set_location(latitude, longitude, altitude, speed: nil)
  if speed.nil?
    self.location = ::Selenium::WebDriver::Location.new(Float(latitude), Float(longitude), Float(altitude))
  else
    loc = ::Selenium::WebDriver::Location.new(Float(latitude), Float(longitude), Float(altitude))
    @bridge.set_location loc.latitude, loc.longitude, loc.altitude, speed: Float(speed)
  end
end