Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 6cc09dd
Author: Dave Amies <[email protected]>
Date:   Sat Feb 26 14:09:19 2022 +1000

    My tweaks to atest to make it run locally

commit 2dd9d9d
Author: Dave Amies <[email protected]>
Date:   Sat Feb 26 14:07:38 2022 +1000

    Will now detect the screen scaling ratio and adjust

    This update will now detect the screen scaling ratio and adjust accordingly. I tested it using "tests/atest/calculator.robot" on a mac with a Retina display running OSX 12.0.1 I don't have a windows machine to test on, but based on comments in [pyautogui issue #589](asweigart/pyautogui#589) this should work for the various windows scaling ratios.
    This replaces the self.has_retina which wasn't working as it was returning false on my machine even though it does indeed have a retina display.
    __get_pixel_ratio should only get called the first time _locate is called, that was my experience in testing, though perhaps it should be called every time as windows users could potentially change their display scaling during the test. Also I don't know of an OS that supports it now but I guess it's possible in the future an OS may have a scaling factor less than 100% and this change won't support that either.
    Issue eficode#62
  • Loading branch information
noubar committed Oct 17, 2024
1 parent 8c725b5 commit 76e1a30
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 7 deletions.
13 changes: 10 additions & 3 deletions src/ImageHorizonLibrary/recognition/_recognize_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@

class _RecognizeImages(object):

pixel_ratio = 0.0

def __get_pixel_ratio(self):
self.pixel_ratio = ag.screenshot().size[0]/ag.size().width

def __normalize(self, path):
if (not self.reference_folder or
not isinstance(self.reference_folder, str) or
Expand Down Expand Up @@ -203,9 +208,11 @@ def try_locate(ref_image):
center_point = ag.center(location)
x = center_point.x
y = center_point.y
if self.has_retina:
x = x / 2
y = y / 2
if self.pixel_ratio == 0.0:
self.__get_pixel_ratio()
if self.pixel_ratio>1:
x = x / self.pixel_ratio
y = y / self.pixel_ratio
return (x, y)

def does_exist(self, reference_image):
Expand Down
9 changes: 5 additions & 4 deletions tests/atest/calculator.robot
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
*** Settings ***
Library ImageHorizonLibrary ${CURDIR}${/}reference_images${/}calculator screenshot_folder=${OUTPUT_DIR}
Library ${CURDIR}${/}..${/}..${/}..${/}robotframework-imagehorizonlibrary${/}src${/}ImageHorizonLibrary ${CURDIR}${/}reference_images${/}calculator screenshot_folder=${OUTPUT_DIR}

*** Test cases ***

Calculator
Set Confidence 0.9
Launch application python tests/atest/calculator/calculator.py
Launch application python3 tests/atest/calculator/calculator.py
${location1}= Wait for inputs_folder timeout=30
Click to the above of ${location1} 20
Type 1010
Click to the below of ${location1} 20
Type 1001
${location2}= Locate or_button.png
${location2}= Locate or_button
Click to the below of ${location2} 0
Click to the below of ${location2} 50
Sleep 0.1
${result}= Copy
Should be equal as integers ${result} 1011
Click Image close_button.png
Click Image close_button
[Teardown] Terminate application
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 76e1a30

Please sign in to comment.