Skip to content

Commit ba4d51c

Browse files
Update location_rel to use center point
1 parent 57313bf commit ba4d51c

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

lib/appium_lib/common/patch.rb

+13-3
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,20 @@ def name
4949
# https://github.com/appium/appium/wiki/Automating-mobile-gestures
5050
# @return [OpenStruct] the relative x, y in a struct. ex: { x: 0.50, y: 0.20 }
5151
def location_rel
52-
xy = self.location
52+
location = self.location
53+
location_x = location.x.to_f
54+
location_y = location.y.to_f
55+
56+
size = self.size
57+
size_width = size.width.to_f
58+
size_height = size.height.to_f
59+
60+
center_x = location_x + (size_width / 2.0)
61+
center_y = location_y + (size_height / 2.0)
62+
5363
w = $driver.window_size
54-
OpenStruct.new( x: "#{xy.x.to_f} / #{w.width.to_f}",
55-
y: "#{xy.y.to_f} / #{w.height.to_f}" )
64+
OpenStruct.new( x: "#{center_x} / #{w.width.to_f}",
65+
y: "#{center_y} / #{w.height.to_f}" )
5666
end
5767
end
5868
end # module Appium::Common

0 commit comments

Comments
 (0)