From 82a3635cf9a875d4d11fea879c94c3e6cdb3e2ca Mon Sep 17 00:00:00 2001 From: Edgars Eglitis Date: Tue, 13 Feb 2024 12:51:56 +0200 Subject: [PATCH 1/2] fix: speed up click/press/click_and_hold --- lib/core/device.rb | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/lib/core/device.rb b/lib/core/device.rb index 38b70964..966dd591 100644 --- a/lib/core/device.rb +++ b/lib/core/device.rb @@ -423,16 +423,11 @@ def end_record(action) # NoRaise def click(action) start = Time.now - return unless wait_for(action) - - action["Condition"] = nil - start_error = Time.now - el = wait_for(action) + return unless el now = Time.now - log_info("Time to find element: #{now - start - (now - start_error) / 2}s " + - "error #{(now - start_error)}") if action["CheckTime"] + log_info("Time to find element: #{now - start}s") if action["CheckTime"] error = nil wait_time = (action["CheckTime"] ? action["CheckTime"] : @timeout) @@ -490,16 +485,11 @@ def tap_by_coord(action) # NoRaise def press(action) start = Time.now - return unless wait_for(action) - - action["Condition"] = nil - start_error = Time.now - el = wait_for(action) + return unless el now = Time.now - log_info("Time to find element: #{now - start - (now - start_error) / 2}s " + - "error #{(now - start_error)}") if action["CheckTime"] + log_info("Time to find element: #{now - start}s") if action["CheckTime"] error = nil wait_time = (action["CheckTime"] ? action["CheckTime"] : @timeout) @@ -528,16 +518,11 @@ def press(action) # NoRaise def click_and_hold(action) start = Time.now - return unless wait_for(action) - - action["Condition"] = nil - start_error = Time.now - el = wait_for(action) + return unless el now = Time.now - log_info("Time to find element: #{now - start - (now - start_error) / 2}s " + - "error #{(now - start_error)}") if action["CheckTime"] + log_info("Time to find element: #{now - start}s") if action["CheckTime"] error = nil wait_time = (action["CheckTime"] ? action["CheckTime"] : @timeout) From 5020ab349503f42de0c6608c47e53acf1a330b41 Mon Sep 17 00:00:00 2001 From: Edgars Eglitis Date: Tue, 13 Feb 2024 12:56:25 +0200 Subject: [PATCH 2/2] fix: do not repeat conversion in loop --- lib/core/device.rb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/core/device.rb b/lib/core/device.rb index 966dd591..23e63115 100644 --- a/lib/core/device.rb +++ b/lib/core/device.rb @@ -918,16 +918,15 @@ def wait_for(action) wait_time = (action["CheckTime"] ? action["CheckTime"] : wait_time) index = action["Index"] + el = nil exception = "" start = Time.now - try = 0 - while (Time.now - start) < wait_time - if id.is_a?(String) + + if id.is_a?(String) + id = convert_value(id) + locator_strategy = convert_value(locator_strategy) + while (Time.now - start) < wait_time begin - id = convert_value(id) - locator_strategy = convert_value(locator_strategy) - try += 1 - el = nil if index els = @driver.find_elements(locator_strategy, id) if index.is_a?(String) && index == "last" @@ -944,7 +943,9 @@ def wait_for(action) exception = e sleep(0.2) end - else + end + else + while (Time.now - start) < wait_time i = 0 id.each do |locator| locator = convert_value(locator)