Skip to content

Commit 69a698b

Browse files
Add px_to_window_rel
1 parent 218185f commit 69a698b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

lib/appium_lib/common/helper.rb

+16
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,20 @@ def find_names name
216216
def tag tag_name
217217
find_element :tag_name, tag_name
218218
end
219+
220+
# Converts pixel values to window relative values
221+
#
222+
# ```ruby
223+
# px_to_window_rel x: 50, y: 150
224+
# ```
225+
226+
def px_to_window_rel opts={}
227+
228+
w = $driver.window_size
229+
x = opts.fetch :x, 0
230+
y = opts.fetch :y, 0
231+
232+
OpenStruct.new( x: x.to_f / w.width.to_f,
233+
y: y.to_f / w.height.to_f )
234+
end
219235
end # module Appium::Common

0 commit comments

Comments
 (0)