From 9d062b01bcc3e17371dfe36ba4c756c6e255bbb7 Mon Sep 17 00:00:00 2001 From: anonym Date: Mon, 1 Apr 2024 00:51:47 +0200 Subject: [PATCH] Test suite: debug log consistently in wait/find_any/wait_any/wait_vanish It seems we tried to be clever and ignore the log option in find() when logging the "found" message, since most methods want to log that, but in wait_vanish() that becomes spammy. So let's not be clever, and log what we want explicitly in each method. --- features/support/helpers/screen.rb | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/features/support/helpers/screen.rb b/features/support/helpers/screen.rb index 615ffdebc0c..af39c26be12 100644 --- a/features/support/helpers/screen.rb +++ b/features/support/helpers/screen.rb @@ -150,7 +150,7 @@ class Screen end m = Match.new(image, self, *p) - debug_log("Screen: found #{image} at (#{m.middle.join(', ')})") + debug_log("Screen: found #{image} at (#{m.middle.join(', ')})") if opts[:log] m end @@ -158,7 +158,9 @@ class Screen opts[:log] = true if opts[:log].nil? debug_log("Screen: waiting for #{pattern}") if opts[:log] try_for(timeout, delay: 0) do - return find(pattern, **opts) + m = find(pattern, **opts.clone.update(log: false)) + debug_log("Screen: found #{m.image} at (#{m.middle.join(', ')})") if opts[:log] + return m end rescue Timeout::Error raise FindFailed, "cannot find #{pattern} on the screen" @@ -190,11 +192,11 @@ class Screen def find_any(patterns, **opts) opts[:log] = true if opts[:log].nil? - if opts[:log] - debug_log("Screen: trying to find any of #{patterns.join(', ')}") - end + debug_log("Screen: trying to find any of #{patterns.join(', ')}") if opts[:log] patterns.each do |pattern| - return find(pattern, **opts.clone.update(log: false)) + m = find(pattern, **opts.clone.update(log: false)) + debug_log("Screen: found #{m.image} at (#{m.middle.join(', ')})") if opts[:log] + return m rescue FindFailed # Ignore. We'll throw an appropriate exception after having # looped through all patterns and found none of them. @@ -214,7 +216,9 @@ class Screen opts[:log] = true if opts[:log].nil? debug_log("Screen: waiting for any of #{patterns.join(', ')}") if opts[:log] try_for(time, delay: 0, log: false) do - return find_any(patterns, **opts.clone.update(log: false)) + m = find_any(patterns, **opts.clone.update(log: false)) + debug_log("Screen: found #{m.image} at (#{m.middle.join(', ')})") if opts[:log] + return m end rescue Timeout::Error raise FindFailed, "can not find any of the patterns #{patterns} " \ -- 2.11.4.GIT