Skip to content

Commit 1657f8c

Browse files
Merge pull request #333 from hipyard/geolocation_pr
add set_location method for setting geolocation
2 parents e441d6d + dbb32b2 commit 1657f8c

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

android_tests/lib/android/specs/driver.rb

+11
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,17 @@ def validate_path(path)
175175
end
176176
end
177177

178+
# simple integration sanity test to check for unexpected exceptions
179+
t 'set_location' do
180+
begin
181+
set_location latitude: 55, longitude: -72, altitude: 33
182+
rescue Selenium::WebDriver::Error::UnknownError => e
183+
# on android this method is expected to fail with this message when running
184+
# on a regular device, or on genymotion.
185+
raise unless e.message.start_with?('ERROR running Appium command: port should be > 0 and < 65536')
186+
end
187+
end
188+
178189
# settings
179190
t 'get settings' do
180191
get_settings.wont_be_nil

ios_tests/lib/ios/specs/driver.rb

+5
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ def sauce?
185185
exists(0, 0) { fail 'error' }.must_equal false
186186
end
187187

188+
# simple integration sanity test to check for unexpected exceptions
189+
t 'set_location' do
190+
set_location latitude: 55, longitude: -72, altitude: 33
191+
end
192+
188193
# any script
189194
t 'execute_script' do
190195
execute_script %q(au.mainApp().getFirstWithPredicate("name contains[c] 'button'");)

lib/appium_lib/driver.rb

+17
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ def start_driver
484484
@driver = Selenium::WebDriver.for :remote, http_client: @client, desired_capabilities: @caps, url: server_url
485485
# Load touch methods.
486486
@driver.extend Selenium::WebDriver::DriverExtensions::HasTouchScreen
487+
@driver.extend Selenium::WebDriver::DriverExtensions::HasLocation
487488

488489
# export session
489490
if @export_session
@@ -592,6 +593,22 @@ def find_element(*args)
592593
@driver.find_element(*args)
593594
end
594595

596+
# Calls @driver.set_location
597+
#
598+
# @note This method does not work on real devices.
599+
#
600+
# @param [Hash] opts consisting of:
601+
# @option opts [Float] :latitude the latitude in degrees (required)
602+
# @option opts [Float] :longitude the longitude in degees (required)
603+
# @option opts [Float] :altitude the altitude, defaulting to 75
604+
# @return [Selenium::WebDriver::Location] the location constructed by the selenium webdriver
605+
def set_location(opts = {})
606+
latitude = opts.fetch(:latitude)
607+
longitude = opts.fetch(:longitude)
608+
altitude = opts.fetch(:altitude, 75)
609+
@driver.set_location(latitude, longitude, altitude)
610+
end
611+
595612
# Quit the driver and Pry.
596613
# quit and exit are reserved by Pry.
597614
# @return [void]

0 commit comments

Comments
 (0)