From 165848bfeff7a2c6bddb27ce25934d4611e9fae2 Mon Sep 17 00:00:00 2001 From: Edgars Eglitis Date: Mon, 12 Feb 2024 17:06:44 +0200 Subject: [PATCH 1/2] fix: replace touchactions with w3c action chains --- lib/core/device.rb | 92 +++++++++++++++++----------------------------- 1 file changed, 34 insertions(+), 58 deletions(-) diff --git a/lib/core/device.rb b/lib/core/device.rb index fba1c171..bcd6d069 100644 --- a/lib/core/device.rb +++ b/lib/core/device.rb @@ -478,10 +478,10 @@ def tap_by_coord(action) el = wait_for(action) el_location = el.location log_info("#{@role}: element coordinates: x -> #{el_location.x}, y -> #{el_location.y}") - action = Appium::TouchAction.new(@driver).press(x: el_location.x, y: el_location.y).wait(600).release.perform + @driver.action.move_to_location(el_location.x, el_location.y).pointer_down(:left).release.perform end - # presses on the provided element. Uses Appium's TouchAction. + # presses on the provided element. Uses Appium's action chains. # Accepts: # Strategy # Id @@ -506,15 +506,7 @@ def press(action) while (Time.now - start) < wait_time begin - @platform == "iOS" ? - @driver.action.move_to(el) : - @driver.action.move_to(el).perform - rescue => e - error = e - end - - begin - Appium::TouchAction.new(@driver).press(el).wait(600).release.perform + @driver.action.move_to(el).pointer_down(:left).release.perform log_info("Time for click: #{Time.now - start}s") if action["CheckTime"] return rescue => e @@ -649,13 +641,13 @@ def clear_field(action) def swipe_up(action) el = wait_for(action) el_location = el.location - opts = { - start_x: el_location.x, - start_y: el_location.y, - end_x: el_location.x, - end_y: 0, - } - action = Appium::TouchAction.new(@driver).swipe(opts).perform + + @driver.action + .move_to_location(el_location.x, el_location.y) + .pointer_down(:left) + .move_to_location(el_location.x, 0, duration: 200) + .release + .perform end # Accepts: @@ -665,14 +657,12 @@ def swipe_down(action) el = wait_for(action) el_location = el.location - opts = { - start_x: el_location.x, - start_y: el_location.y, - end_x: el_location.x, - end_y: 1500, - } - - action = Appium::TouchAction.new(@driver).swipe(opts).perform + @driver.action + .move_to_location(el_location.x, el_location.y) + .pointer_down(:left) + .move_to_location(el_location.x, 1500, duration: 200) + .release + .perform end def swipe_elements(action) @@ -683,15 +673,13 @@ def swipe_elements(action) el1_y = el1.location.y + (el1.size.height / 2) el2_x = el2.location.x + (el2.size.width / 2) el2_y = el2.location.y + (el2.size.height / 2) - opts = { - start_x: el1_x, - start_y: el1_y, - end_x: el2_x, - end_y: el2_y, - duration: 2000, - } - action = Appium::TouchAction.new(@driver).swipe(opts).perform + @driver.action + .move_to_location(el1_x, el1_y) + .pointer_down(:left) + .move_to_location(el2_x, el2_y, duration: 2000) + .release + .perform end # TODO @@ -701,21 +689,6 @@ def driver_method(action) # @driver.send(action["Method"], action["Var"]) # Check how to send multiple vars end - # TODO - def touch_actions(action) - log_info("TODO") - # HERE USER WILL PUT SEVERAL ACTIONS IN A LIST: - # - Action: press - # Coordinates: - # X: - # ... - # Element: - # Strategy: - # Id: - # - Action: release - # ... - end - # swipes to provided X and Y values. # Accepts: # StartX @@ -723,14 +696,17 @@ def touch_actions(action) # OffsetX # OffsetY def swipe_coord(action) - opts = { - start_x: action["StartX"], - start_y: action["StartY"], - end_x: action["EndX"] ? action["EndX"] : 0, - end_y: action["EndY"] ? action["EndY"] : 0, - } + start_x = action["StartX"] + start_y = action["StartY"] + end_x = action["EndX"] ? action["EndX"] : 0 + end_y = action["EndY"] ? action["EndY"] : 0 - action = Appium::TouchAction.new(@driver).swipe(opts).perform + @driver.action + .move_to_location(start_x, start_y) + .pointer_down(:left) + .move_to_location(end_x, end_y, duration: 200) + .release + .perform end # clicks on the provided coordinates, if not provided then middle of the screen @@ -739,13 +715,13 @@ def swipe_coord(action) # Y def click_coord(action = nil) if action["X"] && action["Y"] - action = Appium::TouchAction.new(@driver).press(x: action["X"], y: action["Y"]).release.perform + @driver.action.move_to_location(action["X"], action["Y"]).pointer_down(:left).release.perform else window_size = @driver.window_size x_middle = window_size.width * 0.5 y_middle = window_size.height * 0.5 - action = Appium::TouchAction.new(@driver).press(x: x_middle, y: y_middle).release.perform + @driver.action.move_to_location(x_middle, y_middle).pointer_down(:left).release.perform end end From b2b1d60bdfc1e2ff955d4470e15da4d0a8a07811 Mon Sep 17 00:00:00 2001 From: Edgars Eglitis Date: Tue, 13 Feb 2024 11:09:11 +0200 Subject: [PATCH 2/2] fix: adjust actionchain duration values --- lib/core/device.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/core/device.rb b/lib/core/device.rb index bcd6d069..38b70964 100644 --- a/lib/core/device.rb +++ b/lib/core/device.rb @@ -645,7 +645,7 @@ def swipe_up(action) @driver.action .move_to_location(el_location.x, el_location.y) .pointer_down(:left) - .move_to_location(el_location.x, 0, duration: 200) + .move_to_location(el_location.x, 0, duration: 0.2) .release .perform end @@ -660,7 +660,7 @@ def swipe_down(action) @driver.action .move_to_location(el_location.x, el_location.y) .pointer_down(:left) - .move_to_location(el_location.x, 1500, duration: 200) + .move_to_location(el_location.x, 1500, duration: 0.2) .release .perform end @@ -677,7 +677,7 @@ def swipe_elements(action) @driver.action .move_to_location(el1_x, el1_y) .pointer_down(:left) - .move_to_location(el2_x, el2_y, duration: 2000) + .move_to_location(el2_x, el2_y, duration: 2) .release .perform end @@ -704,7 +704,7 @@ def swipe_coord(action) @driver.action .move_to_location(start_x, start_y) .pointer_down(:left) - .move_to_location(end_x, end_y, duration: 200) + .move_to_location(end_x, end_y, duration: 0.2) .release .perform end