diff --git a/src/ImageHorizonLibrary/recognition/_recognize_images.py b/src/ImageHorizonLibrary/recognition/_recognize_images.py index b2ed9d5..d0a2bc4 100644 --- a/src/ImageHorizonLibrary/recognition/_recognize_images.py +++ b/src/ImageHorizonLibrary/recognition/_recognize_images.py @@ -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 @@ -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): diff --git a/tests/atest/calculator.robot b/tests/atest/calculator.robot index 8fd167d..7b7afe5 100755 --- a/tests/atest/calculator.robot +++ b/tests/atest/calculator.robot @@ -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 diff --git a/tests/atest/reference_images/calculator/close_button.png b/tests/atest/reference_images/calculator/close_button/close_button.png similarity index 100% rename from tests/atest/reference_images/calculator/close_button.png rename to tests/atest/reference_images/calculator/close_button/close_button.png diff --git a/tests/atest/reference_images/calculator/close_button/close_button_macos.png b/tests/atest/reference_images/calculator/close_button/close_button_macos.png new file mode 100644 index 0000000..c7d4ef2 Binary files /dev/null and b/tests/atest/reference_images/calculator/close_button/close_button_macos.png differ diff --git a/tests/atest/reference_images/calculator/inputs_folder/inputs_macos.png b/tests/atest/reference_images/calculator/inputs_folder/inputs_macos.png new file mode 100644 index 0000000..6df1a72 Binary files /dev/null and b/tests/atest/reference_images/calculator/inputs_folder/inputs_macos.png differ diff --git a/tests/atest/reference_images/calculator/or_button.png b/tests/atest/reference_images/calculator/or_button/or_button.png similarity index 100% rename from tests/atest/reference_images/calculator/or_button.png rename to tests/atest/reference_images/calculator/or_button/or_button.png diff --git a/tests/atest/reference_images/calculator/or_button/or_button_macos.png b/tests/atest/reference_images/calculator/or_button/or_button_macos.png new file mode 100644 index 0000000..509eeeb Binary files /dev/null and b/tests/atest/reference_images/calculator/or_button/or_button_macos.png differ