Skip to content

Commit 76e1a30

Browse files
committed
Squashed commit of the following:
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
1 parent 8c725b5 commit 76e1a30

File tree

7 files changed

+15
-7
lines changed

7 files changed

+15
-7
lines changed

src/ImageHorizonLibrary/recognition/_recognize_images.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212

1313
class _RecognizeImages(object):
1414

15+
pixel_ratio = 0.0
16+
17+
def __get_pixel_ratio(self):
18+
self.pixel_ratio = ag.screenshot().size[0]/ag.size().width
19+
1520
def __normalize(self, path):
1621
if (not self.reference_folder or
1722
not isinstance(self.reference_folder, str) or
@@ -203,9 +208,11 @@ def try_locate(ref_image):
203208
center_point = ag.center(location)
204209
x = center_point.x
205210
y = center_point.y
206-
if self.has_retina:
207-
x = x / 2
208-
y = y / 2
211+
if self.pixel_ratio == 0.0:
212+
self.__get_pixel_ratio()
213+
if self.pixel_ratio>1:
214+
x = x / self.pixel_ratio
215+
y = y / self.pixel_ratio
209216
return (x, y)
210217

211218
def does_exist(self, reference_image):

tests/atest/calculator.robot

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
*** Settings ***
2-
Library ImageHorizonLibrary ${CURDIR}${/}reference_images${/}calculator screenshot_folder=${OUTPUT_DIR}
2+
Library ${CURDIR}${/}..${/}..${/}..${/}robotframework-imagehorizonlibrary${/}src${/}ImageHorizonLibrary ${CURDIR}${/}reference_images${/}calculator screenshot_folder=${OUTPUT_DIR}
33

44
*** Test cases ***
55

66
Calculator
77
Set Confidence 0.9
8-
Launch application python tests/atest/calculator/calculator.py
8+
Launch application python3 tests/atest/calculator/calculator.py
99
${location1}= Wait for inputs_folder timeout=30
1010
Click to the above of ${location1} 20
1111
Type 1010
1212
Click to the below of ${location1} 20
1313
Type 1001
14-
${location2}= Locate or_button.png
14+
${location2}= Locate or_button
1515
Click to the below of ${location2} 0
1616
Click to the below of ${location2} 50
17+
Sleep 0.1
1718
${result}= Copy
1819
Should be equal as integers ${result} 1011
19-
Click Image close_button.png
20+
Click Image close_button
2021
[Teardown] Terminate application
Loading
Loading
Loading

0 commit comments

Comments
 (0)