Skip to content

Commit d706142

Browse files
authored
feat: define Appium::Location (#447)
1 parent 75bba80 commit d706142

File tree

6 files changed

+21
-13
lines changed

6 files changed

+21
-13
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@ Read `release_notes.md` for commit level details.
66

77
### Enhancements
88

9+
- Add `::Appium::Location` since `::Selenium::WebDriver::Location` no longer exists
10+
911
### Bug fixes
1012

1113
### Deprecations
1214

15+
- `::Selenium::WebDriver::Location` is deprecated in favor of `::Appium::Location` in Appium Ruby binding
16+
17+
1318
## [6.1.0] - 2023-01-18
1419

1520
### Bug fixes

appium_lib_core.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
2222
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
2323
spec.require_paths = ['lib']
2424

25-
spec.add_runtime_dependency 'selenium-webdriver', '~> 4.2', '< 4.8'
25+
spec.add_runtime_dependency 'selenium-webdriver', '~> 4.2', '< 4.9'
2626
spec.add_runtime_dependency 'faye-websocket', '~> 0.11.0'
2727

2828
spec.add_development_dependency 'rake', '~> 13.0'

lib/appium_lib_core/common/base/bridge.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ def network_connection=(type)
302302
# called in 'extend DriverExtensions::HasLocation'
303303
def location
304304
obj = execute(:get_location) || {}
305-
::Selenium::WebDriver::Location.new obj['latitude'], obj['longitude'], obj['altitude']
305+
::Appium::Location.new obj['latitude'], obj['longitude'], obj['altitude']
306306
end
307307

308308
# For Appium

lib/appium_lib_core/common/base/has_location.rb

+10-10
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,27 @@ class Base
2121
module HasLocation
2222
# Get the location of the device.
2323
#
24-
# @return [::Selenium::WebDriver::Location]
24+
# @return [::Appium::Location]
2525
#
2626
# @example
2727
#
28-
# driver.location #=> ::Selenium::WebDriver::Location.new(10, 10, 10)
28+
# driver.location #=> ::Appium::Location.new(10, 10, 10)
2929
#
3030
def location
3131
@bridge.location
3232
end
3333

3434
# Set the location of the device.
3535
#
36-
# @param [::Selenium::WebDriver::Location] location Set the location.
36+
# @param [::Appium::Location] location Set the location.
3737
#
3838
# @example
3939
#
40-
# driver.location = ::Selenium::WebDriver::Location.new(10, 10, 10)
40+
# driver.location = ::Appium::Location.new(10, 10, 10)
4141
#
4242
def location=(location)
43-
unless location.is_a?(::Selenium::WebDriver::Location)
44-
raise TypeError, "expected #{::Selenium::WebDriver::Location}, got #{location.inspect}:#{location.class}"
43+
unless location.is_a?(::Appium::Location)
44+
raise TypeError, "expected #{::Appium::Location}, got #{location.inspect}:#{location.class}"
4545
end
4646

4747
@bridge.set_location location.latitude, location.longitude, location.altitude
@@ -56,17 +56,17 @@ def location=(location)
5656
# in meters/second @since Appium 1.21.0 and in knots for emulators @since Appium 1.22.0.
5757
# @param [String, Number] satellites Sets the count of geo satellites being tracked in range 1..12 @since Appium 1.22.0.
5858
# This number is respected on Emulators.
59-
# @param [::Selenium::WebDriver::Location]
59+
# @param [::Appium::Location]
6060
#
6161
# @example
6262
#
63-
# driver.location = ::Selenium::WebDriver::Location.new(10, 10, 10)
63+
# driver.location = ::Appium::Location.new(10, 10, 10)
6464
#
6565
def set_location(latitude, longitude, altitude, speed: nil, satellites: nil)
6666
if speed.nil? && satellites.nil?
67-
self.location = ::Selenium::WebDriver::Location.new(Float(latitude), Float(longitude), Float(altitude))
67+
self.location = ::Appium::Location.new(Float(latitude), Float(longitude), Float(altitude))
6868
else
69-
loc = ::Selenium::WebDriver::Location.new(Float(latitude), Float(longitude), Float(altitude))
69+
loc = ::Appium::Location.new(Float(latitude), Float(longitude), Float(altitude))
7070

7171
speed = Float(speed) unless speed.nil?
7272
satellites = Integer(satellites) unless satellites.nil?

lib/appium_lib_core/driver.rb

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
require 'uri'
1616

1717
module Appium
18+
# The struct for 'location'
19+
Location = Struct.new(:latitude, :longitude, :altitude)
20+
1821
module Core
1922
module Android
2023
autoload :Uiautomator1, 'appium_lib_core/android'

test/unit/android/webdriver/w3c/commands_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def test_set_location
184184
.with(body: { location: { latitude: 1.0, longitude: 1.0, altitude: 1.0 } }.to_json)
185185
.to_return(headers: HEADER, status: 200, body: { value: nil }.to_json)
186186

187-
@driver.location = ::Selenium::WebDriver::Location.new(1.0, 1.0, 1.0)
187+
@driver.location = ::Appium::Location.new(1.0, 1.0, 1.0)
188188
@driver.set_location 1, 1, 1
189189

190190
assert_requested(:post, "#{SESSION}/location", times: 2)

0 commit comments

Comments
 (0)