From c6451e000aad0d51af4de060b1fe8cde613c16d5 Mon Sep 17 00:00:00 2001 From: Edgars Eglitis Date: Fri, 5 Jul 2024 16:09:11 +0300 Subject: [PATCH 1/3] fix: adjust timeouts for click actions --- lib/core/device.rb | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/core/device.rb b/lib/core/device.rb index ce9bcf4d..6b008d7c 100644 --- a/lib/core/device.rb +++ b/lib/core/device.rb @@ -447,17 +447,17 @@ def end_record(action) # OffsetFractionY # NoRaise def click(action) - start = Time.now + before_find = Time.now el = wait_for(action) return unless el - now = Time.now - log_info("Time to find element: #{now - start}s") if action["CheckTime"] + after_find = Time.now + log_info("Time to find element: #{after_find - before_find}s") if action["CheckTime"] error = nil wait_time = (action["CheckTime"] ? action["CheckTime"] : @timeout) - while (Time.now - start) < wait_time + while (Time.now - after_find) < wait_time begin @platform == "iOS" ? @driver.action.move_to(el) : @@ -478,7 +478,7 @@ def click(action) else el.click end - log_info("Time for click: #{Time.now - start}s") if action["CheckTime"] + log_info("Time for click: #{Time.now - after_find}s") if action["CheckTime"] return rescue => e error = e @@ -535,20 +535,20 @@ def tap_by_coord(action) # CheckTime # NoRaise def press(action) - start = Time.now + before_find = Time.now el = wait_for(action) return unless el - now = Time.now - log_info("Time to find element: #{now - start}s") if action["CheckTime"] + after_find = Time.now + log_info("Time to find element: #{after_find - before_find}s") if action["CheckTime"] error = nil wait_time = (action["CheckTime"] ? action["CheckTime"] : @timeout) - while (Time.now - start) < wait_time + while (Time.now - after_find) < wait_time begin @driver.action.move_to(el).pointer_down(:left).release.perform - log_info("Time for click: #{Time.now - start}s") if action["CheckTime"] + log_info("Time for click: #{Time.now - after_find}s") if action["CheckTime"] return rescue => e error = e @@ -568,17 +568,17 @@ def press(action) # CheckTime # NoRaise def click_and_hold(action) - start = Time.now + before_find = Time.now el = wait_for(action) return unless el - now = Time.now - log_info("Time to find element: #{now - start}s") if action["CheckTime"] + after_find = Time.now + log_info("Time to find element: #{after_find - before_find}s") if action["CheckTime"] error = nil wait_time = (action["CheckTime"] ? action["CheckTime"] : @timeout) - while (Time.now - start) < wait_time + while (Time.now - after_find) < wait_time begin @platform == "iOS" ? @driver.action.move_to(el) : @@ -588,7 +588,7 @@ def click_and_hold(action) end begin @driver.action.click_and_hold(el).perform - log_info("Time for click and hold: #{Time.now - start}s") if action["CheckTime"] + log_info("Time for click and hold: #{Time.now - after_find}s") if action["CheckTime"] return rescue => e error = e From eabd1f0deecfa26b18be455c7e72f71f247bb08a Mon Sep 17 00:00:00 2001 From: Edgars Eglitis Date: Thu, 11 Jul 2024 16:20:44 +0300 Subject: [PATCH 2/3] fix: ensure click is always executed once --- lib/core/device.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/core/device.rb b/lib/core/device.rb index 6b008d7c..1f970d09 100644 --- a/lib/core/device.rb +++ b/lib/core/device.rb @@ -457,7 +457,7 @@ def click(action) wait_time = (action["CheckTime"] ? action["CheckTime"] : @timeout) - while (Time.now - after_find) < wait_time + loop do begin @platform == "iOS" ? @driver.action.move_to(el) : @@ -483,6 +483,7 @@ def click(action) rescue => e error = e end + break if (Time.now - after_find) >= wait_time end if error && !action["NoRaise"] @@ -545,7 +546,7 @@ def press(action) wait_time = (action["CheckTime"] ? action["CheckTime"] : @timeout) - while (Time.now - after_find) < wait_time + loop do begin @driver.action.move_to(el).pointer_down(:left).release.perform log_info("Time for click: #{Time.now - after_find}s") if action["CheckTime"] @@ -553,6 +554,7 @@ def press(action) rescue => e error = e end + break if (Time.now - after_find) >= wait_time end if error && !action["NoRaise"] path = take_error_screenshot() @@ -578,7 +580,7 @@ def click_and_hold(action) wait_time = (action["CheckTime"] ? action["CheckTime"] : @timeout) - while (Time.now - after_find) < wait_time + loop do begin @platform == "iOS" ? @driver.action.move_to(el) : @@ -593,6 +595,7 @@ def click_and_hold(action) rescue => e error = e end + break if (Time.now - after_find) >= wait_time end if error && !action["NoRaise"] path = take_error_screenshot() From 7e9e1ace95892aa96578424ad7ec1560778b3b3f Mon Sep 17 00:00:00 2001 From: Edgars Eglitis Date: Thu, 11 Jul 2024 16:24:09 +0300 Subject: [PATCH 3/3] fix: adjust click loop timeout --- lib/core/device.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/core/device.rb b/lib/core/device.rb index 1f970d09..36f47bc6 100644 --- a/lib/core/device.rb +++ b/lib/core/device.rb @@ -483,7 +483,7 @@ def click(action) rescue => e error = e end - break if (Time.now - after_find) >= wait_time + break if (Time.now - before_find) >= wait_time end if error && !action["NoRaise"] @@ -554,7 +554,7 @@ def press(action) rescue => e error = e end - break if (Time.now - after_find) >= wait_time + break if (Time.now - before_find) >= wait_time end if error && !action["NoRaise"] path = take_error_screenshot() @@ -595,7 +595,7 @@ def click_and_hold(action) rescue => e error = e end - break if (Time.now - after_find) >= wait_time + break if (Time.now - before_find) >= wait_time end if error && !action["NoRaise"] path = take_error_screenshot()