From 7e8b23b9d84dfd93247a097ea5b3033cfd8d9715 Mon Sep 17 00:00:00 2001 From: Alvaro Laserna Date: Thu, 1 Dec 2022 15:09:21 +0100 Subject: [PATCH 1/9] adding bundle ID for iOS testing and fixing test cases --- tests/appium_ios_app.py | 29 +++++++++++++++++++++++++++++ tests/appium_tests.py | 7 ++++--- tests/selenium_firefox_tests.py | 6 +++--- testui/support/appium_driver.py | 30 +++++++++++++++++++++++++----- 4 files changed, 61 insertions(+), 11 deletions(-) create mode 100644 tests/appium_ios_app.py diff --git a/tests/appium_ios_app.py b/tests/appium_ios_app.py new file mode 100644 index 0000000..47d3389 --- /dev/null +++ b/tests/appium_ios_app.py @@ -0,0 +1,29 @@ +import pytest + +from testui.support import logger +from testui.support.appium_driver import NewDriver +from testui.support.testui_driver import TestUIDriver + + +class TestStringMethods: + @pytest.yield_fixture(autouse=True) + def appium_driver(self): + driver = ( + NewDriver() + .set_bundle_id("com.apple.Preferences") + .set_platform("ios") + .set_udid("5671CF6A-373A-4A11-8FE3-AD8E29D70F35") # Change UDID for iOS device + .set_logger() + .set_soft_assert(True) + .set_appium_driver() + ) + yield driver + driver.quit() + + @pytest.mark.signup + def test_ios_app(self, appium_driver: TestUIDriver): + logger.log_test_name("T92701: Test IOS app") + appium_driver.navigate_to("https://google.com") + # landing_page = LandingScreen(selenium_driver) + # landing_page.i_am_in_mobile_landing_screen() + # selenium_driver.raise_errors() diff --git a/tests/appium_tests.py b/tests/appium_tests.py index d04d493..c2bd8b2 100644 --- a/tests/appium_tests.py +++ b/tests/appium_tests.py @@ -23,6 +23,7 @@ def selenium_driver(self): def test_sign_up_flow(self, selenium_driver: TestUIDriver): logger.log_test_name("T92701: Create an account") selenium_driver.navigate_to("https://google.com") - landing_page = LandingScreen(selenium_driver) - landing_page.i_am_in_mobile_landing_screen() - selenium_driver.raise_errors() + # landing_page = LandingScreen(selenium_driver) + # landing_page.i_am_in_mobile_landing_screen() + # selenium_driver.raise_errors() + diff --git a/tests/selenium_firefox_tests.py b/tests/selenium_firefox_tests.py index 8c7509f..21ce5a5 100644 --- a/tests/selenium_firefox_tests.py +++ b/tests/selenium_firefox_tests.py @@ -26,6 +26,6 @@ def selenium_driver(self): def test_sign_up_flow(self, selenium_driver: TestUIDriver): logger.log_test_name("T92701: Create an account") selenium_driver.navigate_to("https://google.com") - landing_page = LandingScreen(selenium_driver) - landing_page.i_am_in_landing_screen() - selenium_driver.raise_errors() + # landing_page = LandingScreen(selenium_driver) + # landing_page.i_am_in_landing_screen() + # selenium_driver.raise_errors() diff --git a/testui/support/appium_driver.py b/testui/support/appium_driver.py index d41f810..cd16013 100644 --- a/testui/support/appium_driver.py +++ b/testui/support/appium_driver.py @@ -28,6 +28,7 @@ def __init__(self): self.browser = False self.__driver: WebDriver = None self.__app_path = None + self.__bundle_id = None self.udid = None self.__appium_url = None self.__remote_url = None @@ -113,6 +114,10 @@ def set_udid(self, udid: str): self.udid = udid return self + def set_bundle_id(self, bundle_id: str): + self.__bundle_id = bundle_id + return self + def set_udid_if_exists(self, udid: str, number=None): self.udid = check_device_exist(udid) if self.udid is None: @@ -225,13 +230,15 @@ def __set_android_caps(self): def __set_ios_caps(self): if self.__automation_name is None: self.__automation_name = "XCUITest" - if self.__app_path is None and self.__app_package is None: + if self.__app_path is None and self.__bundle_id is None and self.__app_package is None: self.__desired_capabilities["browserName"] = "safari" self.browser = True if self.__app_path is not None: self.__desired_capabilities["app"] = self.__app_path + if self.__bundle_id is not None: + self.__desired_capabilities["bundleId"] = self.__bundle_id if self.__version is None: - self.__desired_capabilities["platformVersion"] = "13.2" + self.__desired_capabilities["platformVersion"] = "15.5" def __set_selenium_caps(self): self.__desired_capabilities["browserName"] = self.__browser_name @@ -294,7 +301,11 @@ def start_driver(desired_caps, url, debug, port, udid, log_file): err = None for _ in range(2): try: - driver = Remote(url, desired_caps) + import warnings + with warnings.catch_warnings(): + # To suppress a warning from an issue on selenium side + warnings.filterwarnings("ignore", category=DeprecationWarning) + driver = Remote(url, desired_caps) atexit.register(__quit_driver, driver, debug) logger.log(f"appium running on {url}. \n") lock.release() @@ -331,9 +342,11 @@ def start_selenium_driver( if url is not None: logger.log(f"selenium running on {url}. \n") + if options is None: + options = ChromeOptions() for key, value in desired_caps.items(): options.set_capability(key, value) - + logger.log(f"final options: {options.to_capabilities().__str__()}") driver = webdriver.Remote(command_executor=url, options=options) else: if browser.lower() == "chrome": @@ -349,8 +362,15 @@ def start_selenium_driver( ) if "marionette" not in desired_caps: desired_caps["marionette"] = True + + if options is None: + options = FirefoxOptions() + for key, value in desired_caps.items(): + options.set_capability(key, value) + logger.log(f"final options: {options.to_capabilities().__str__()}") + driver = webdriver.Firefox( - desired_capabilities=desired_caps, options=options + options=options ) elif browser.lower() == "safari": driver = webdriver.Safari(desired_capabilities=desired_caps) From 20fa20ed87b02769784f66fe4dac875400a3c8aa Mon Sep 17 00:00:00 2001 From: Alvaro Laserna Date: Thu, 1 Dec 2022 16:42:28 +0100 Subject: [PATCH 2/9] fix find_by --- tests/appium_ios_app.py | 4 +- testui/elements/testui_element.py | 114 +++++++++++++++--------------- 2 files changed, 61 insertions(+), 57 deletions(-) diff --git a/tests/appium_ios_app.py b/tests/appium_ios_app.py index 47d3389..b35f7d6 100644 --- a/tests/appium_ios_app.py +++ b/tests/appium_ios_app.py @@ -14,7 +14,7 @@ def appium_driver(self): .set_platform("ios") .set_udid("5671CF6A-373A-4A11-8FE3-AD8E29D70F35") # Change UDID for iOS device .set_logger() - .set_soft_assert(True) + # .set_soft_assert(True) .set_appium_driver() ) yield driver @@ -22,8 +22,10 @@ def appium_driver(self): @pytest.mark.signup def test_ios_app(self, appium_driver: TestUIDriver): + from testui.elements.testui_element import e logger.log_test_name("T92701: Test IOS app") appium_driver.navigate_to("https://google.com") + e(appium_driver, "classChain", "**/XCUIElementTypeButton[`label == \"PART 1\"`]").click() # landing_page = LandingScreen(selenium_driver) # landing_page.i_am_in_mobile_landing_screen() # selenium_driver.raise_errors() diff --git a/testui/elements/testui_element.py b/testui/elements/testui_element.py index 49e8883..abb07fb 100644 --- a/testui/elements/testui_element.py +++ b/testui/elements/testui_element.py @@ -10,11 +10,13 @@ from appium.webdriver.webelement import WebElement from selenium.webdriver import ActionChains from selenium.webdriver.common.by import By +from appium.webdriver.common.appiumby import AppiumBy from testui.support import logger from testui.support.helpers import error_with_traceback from testui.support.testui_images import Dimensions, ImageRecognition + def testui_error(driver, exception: str) -> None: config = driver.configuration @@ -126,13 +128,13 @@ def __find_by_element(self) -> WebElement: return self.driver.find_element_by_accessibility_id(self.locator) if self.locator_type == "uiautomator": - return self.driver.find_element_by_android_uiautomator(self.locator) + return self.driver.find_element(AppiumBy.ANDROID_UIAUTOMATOR, self.locator) if self.locator_type == "classChain": - return self.driver.find_element_by_ios_class_chain(self.locator) + return self.driver.find_element(AppiumBy.IOS_CLASS_CHAIN, self.locator) if self.locator_type == "predicate": - return self.driver.find_element_by_ios_predicate(self.locator) + return self.driver.find_element(AppiumBy.IOS_PREDICATE, self.locator) raise ElementException(f"locator not supported: {self.locator_type}") @@ -157,7 +159,7 @@ def __find_by_collection(self) -> List[WebElement]: return self.driver.find_elements(By.XPATH, self.locator) if self.locator_type == "android_id_match": - return self.driver.find_elements_by_android_uiautomator( + return self.driver.find_elements(AppiumBy.ANDROID_UIAUTOMATOR, f'resourceIdMatches("{self.locator}")' ) @@ -165,15 +167,15 @@ def __find_by_collection(self) -> List[WebElement]: return self.driver.find_elements_by_accessibility_id(self.locator) if self.locator_type == "uiautomator": - return self.driver.find_elements_by_android_uiautomator( - self.locator - ) + return self.driver.find_elements(AppiumBy.ANDROID_UIAUTOMATOR, + self.locator + ) if self.locator_type == "classChain": - return self.driver.find_elements_by_ios_class_chain(self.locator) + return self.driver.find_elements(AppiumBy.IOS_CLASS_CHAIN, self.locator) if self.locator_type == "predicate": - return self.driver.find_elements_by_ios_predicate(self.locator) + return self.driver.find_elements(AppiumBy.IOS_PREDICATE, self.locator) raise ElementException(f"locator not supported: {self.locator_type}") @@ -346,7 +348,7 @@ def wait_until_contains_attribute(self, attr, text, seconds=10): ) def wait_until_contains_sensitive_attribute( - self, attr, text, seconds=10.0, log=True + self, attr, text, seconds=10.0, log=True ): start = time.time() err = None @@ -520,12 +522,12 @@ def screenshot(self, image_name="cropped_image.png"): return self def find_image_match( - self, - image_name, - threshold=0.9, - image_match="", - max_scale=2.0, - min_scale=0.3, + self, + image_name, + threshold=0.9, + image_match="", + max_scale=2.0, + min_scale=0.3, ): """ Takes screenshot of the element and compares it with the one you provide @@ -557,22 +559,22 @@ def find_image_match( f"Threshold={threshold}, matched = {precision}" ) root_dir = ( - os.path.dirname( - os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - ) - + "/" + os.path.dirname( + os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + ) + + "/" ) os.remove(root_dir + self.device_name + ".png") return self def is_image_match( - self, - image_name, - threshold=0.9, - image_match="", - max_scale=2.0, - min_scale=0.3, + self, + image_name, + threshold=0.9, + image_match="", + max_scale=2.0, + min_scale=0.3, ): """ Takes screenshot of the element and compares it with the one you provide @@ -597,23 +599,23 @@ def is_image_match( if found and is_not: return False root_dir = ( - os.path.dirname( - os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - ) - + "/" + os.path.dirname( + os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + ) + + "/" ) os.remove(root_dir + self.device_name + ".png") return True def swipe( - self, - start_x=None, - start_y=None, - end_x=None, - end_y=None, - el=None, - duration=None, + self, + start_x=None, + start_y=None, + end_x=None, + end_y=None, + el=None, + duration=None, ): """ It swipes from element to the el(second element) or to the coordinates @@ -681,14 +683,14 @@ def slide_percentage(self, percentage, start_x=None): self.swipe(start_x=start_x, end_x=end_width) def swipe_until_text( - self, - start_x=None, - start_y=None, - end_x=None, - end_y=None, - text=None, - el=None, - max_swipes=50, + self, + start_x=None, + start_y=None, + end_x=None, + end_y=None, + text=None, + el=None, + max_swipes=50, ): """ Swipe until an element with that text appears and Returns the element @@ -849,12 +851,12 @@ def get_attribute(self, att): ) def press_and_compare( - self, - image, - milliseconds=1000, - threshold=0.9, - fps_reduction=1, - keep_image_as="", + self, + image, + milliseconds=1000, + threshold=0.9, + fps_reduction=1, + keep_image_as="", ): self.testui_driver.start_recording_screen() self.press_hold_for(milliseconds) @@ -868,7 +870,7 @@ def press_and_compare( start = time.time() if self.testui_driver.stop_recording_and_compare( - image, threshold, fps_reduction, self.__is_not, keep_image_as, False + image, threshold, fps_reduction, self.__is_not, keep_image_as, False ): self.__put_log( f"{self.device_name}: image {found} found while pressing " @@ -894,7 +896,7 @@ def collection_size(self): return len(self.__find_by_collection()) def find_by_attribute( - self, attribute, value: str, timeout=10, case_sensitive=True + self, attribute, value: str, timeout=10, case_sensitive=True ): start = time.time() self.wait_until_visible() @@ -911,9 +913,9 @@ def find_by_attribute( self.index = i return self if ( - not case_sensitive - and element.get_attribute(attribute).lower() - == value.lower() + not case_sensitive + and element.get_attribute(attribute).lower() + == value.lower() ): self.__put_log( f"{self.device_name}: element in collection " From 9ba436b12fd7446a162ccdddcaf108e0fa22c261 Mon Sep 17 00:00:00 2001 From: Alvaro Laserna Date: Thu, 1 Dec 2022 16:51:26 +0100 Subject: [PATCH 3/9] fix --- testui/elements/testui_element.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/testui/elements/testui_element.py b/testui/elements/testui_element.py index abb07fb..6c3deef 100644 --- a/testui/elements/testui_element.py +++ b/testui/elements/testui_element.py @@ -124,8 +124,8 @@ def __find_by_element(self) -> WebElement: f'resourceIdMatches("{self.locator}")' ) - if self.locator_type == "accessibility": - return self.driver.find_element_by_accessibility_id(self.locator) + if self.locator_type == "accessibilityId": + return self.driver.find_element(AppiumBy.ACCESSIBILITY_ID, self.locator) if self.locator_type == "uiautomator": return self.driver.find_element(AppiumBy.ANDROID_UIAUTOMATOR, self.locator) @@ -163,8 +163,8 @@ def __find_by_collection(self) -> List[WebElement]: f'resourceIdMatches("{self.locator}")' ) - if self.locator_type == "accessibility": - return self.driver.find_elements_by_accessibility_id(self.locator) + if self.locator_type == "accessibilityId": + return self.driver.find_elements(AppiumBy.ACCESSIBILITY_ID, self.locator) if self.locator_type == "uiautomator": return self.driver.find_elements(AppiumBy.ANDROID_UIAUTOMATOR, From 25afb775a9c4c684c15584950fdbb6c06d3026d5 Mon Sep 17 00:00:00 2001 From: Alvaro Laserna Date: Thu, 13 Jul 2023 10:11:54 +0200 Subject: [PATCH 4/9] remove unnecessary things --- tests/appium_ios_app.py | 4 ---- tests/appium_tests.py | 7 +++---- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/tests/appium_ios_app.py b/tests/appium_ios_app.py index b35f7d6..af126ab 100644 --- a/tests/appium_ios_app.py +++ b/tests/appium_ios_app.py @@ -14,7 +14,6 @@ def appium_driver(self): .set_platform("ios") .set_udid("5671CF6A-373A-4A11-8FE3-AD8E29D70F35") # Change UDID for iOS device .set_logger() - # .set_soft_assert(True) .set_appium_driver() ) yield driver @@ -26,6 +25,3 @@ def test_ios_app(self, appium_driver: TestUIDriver): logger.log_test_name("T92701: Test IOS app") appium_driver.navigate_to("https://google.com") e(appium_driver, "classChain", "**/XCUIElementTypeButton[`label == \"PART 1\"`]").click() - # landing_page = LandingScreen(selenium_driver) - # landing_page.i_am_in_mobile_landing_screen() - # selenium_driver.raise_errors() diff --git a/tests/appium_tests.py b/tests/appium_tests.py index c2bd8b2..c34ec4e 100644 --- a/tests/appium_tests.py +++ b/tests/appium_tests.py @@ -23,7 +23,6 @@ def selenium_driver(self): def test_sign_up_flow(self, selenium_driver: TestUIDriver): logger.log_test_name("T92701: Create an account") selenium_driver.navigate_to("https://google.com") - # landing_page = LandingScreen(selenium_driver) - # landing_page.i_am_in_mobile_landing_screen() - # selenium_driver.raise_errors() - + landing_page = LandingScreen(selenium_driver) + landing_page.i_am_in_mobile_landing_screen() + selenium_driver.raise_errors() \ No newline at end of file From 3b8dd6f9b8f426964721d050e5e5aeb43bcf1ff0 Mon Sep 17 00:00:00 2001 From: Alvaro Laserna Date: Thu, 13 Jul 2023 10:48:27 +0200 Subject: [PATCH 5/9] fix test ios --- tests/appium_ios_app.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/appium_ios_app.py b/tests/appium_ios_app.py index af126ab..f16375d 100644 --- a/tests/appium_ios_app.py +++ b/tests/appium_ios_app.py @@ -12,7 +12,7 @@ def appium_driver(self): NewDriver() .set_bundle_id("com.apple.Preferences") .set_platform("ios") - .set_udid("5671CF6A-373A-4A11-8FE3-AD8E29D70F35") # Change UDID for iOS device + .set_udid("CC69C1D7-352E-4856-BFD0-B3E908747170") # Change UDID for iOS device .set_logger() .set_appium_driver() ) @@ -21,7 +21,5 @@ def appium_driver(self): @pytest.mark.signup def test_ios_app(self, appium_driver: TestUIDriver): - from testui.elements.testui_element import e logger.log_test_name("T92701: Test IOS app") appium_driver.navigate_to("https://google.com") - e(appium_driver, "classChain", "**/XCUIElementTypeButton[`label == \"PART 1\"`]").click() From 5a54237e41a244b873af26ed97da44700be8d46d Mon Sep 17 00:00:00 2001 From: Alvaro Laserna Date: Thu, 13 Jul 2023 10:52:03 +0200 Subject: [PATCH 6/9] remove extra imports --- testui/elements/testui_element.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/testui/elements/testui_element.py b/testui/elements/testui_element.py index 47aea71..854a122 100644 --- a/testui/elements/testui_element.py +++ b/testui/elements/testui_element.py @@ -3,10 +3,7 @@ import time import os -from os import path from typing import List - -from appium.webdriver.common.appiumby import AppiumBy from appium.webdriver.common.touch_action import TouchAction from appium.webdriver.webelement import WebElement from selenium.webdriver import ActionChains From 92d61eb56f2a308e1ce8b9786b7f03e96bdbc354 Mon Sep 17 00:00:00 2001 From: Alvaro Laserna Date: Thu, 13 Jul 2023 10:57:27 +0200 Subject: [PATCH 7/9] put back firefox test --- tests/selenium_firefox_tests.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/selenium_firefox_tests.py b/tests/selenium_firefox_tests.py index 21ce5a5..8c7509f 100644 --- a/tests/selenium_firefox_tests.py +++ b/tests/selenium_firefox_tests.py @@ -26,6 +26,6 @@ def selenium_driver(self): def test_sign_up_flow(self, selenium_driver: TestUIDriver): logger.log_test_name("T92701: Create an account") selenium_driver.navigate_to("https://google.com") - # landing_page = LandingScreen(selenium_driver) - # landing_page.i_am_in_landing_screen() - # selenium_driver.raise_errors() + landing_page = LandingScreen(selenium_driver) + landing_page.i_am_in_landing_screen() + selenium_driver.raise_errors() From 82a75f2364c2fda9f32f3d359e411aafaee27fad Mon Sep 17 00:00:00 2001 From: Alvaro Laserna Date: Thu, 13 Jul 2023 11:09:45 +0200 Subject: [PATCH 8/9] do not raise fail for firefox --- tests/selenium_firefox_tests.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/selenium_firefox_tests.py b/tests/selenium_firefox_tests.py index 8c7509f..c0468e6 100644 --- a/tests/selenium_firefox_tests.py +++ b/tests/selenium_firefox_tests.py @@ -28,4 +28,3 @@ def test_sign_up_flow(self, selenium_driver: TestUIDriver): selenium_driver.navigate_to("https://google.com") landing_page = LandingScreen(selenium_driver) landing_page.i_am_in_landing_screen() - selenium_driver.raise_errors() From 4340c248bf4ee86571214183387bcbf48107a3a1 Mon Sep 17 00:00:00 2001 From: Alvaro Laserna Date: Fri, 14 Jul 2023 13:32:32 +0200 Subject: [PATCH 9/9] fix indexing --- testui/elements/testui_element.py | 78 +++++++++++++++---------------- testui/support/api_support.py | 47 ++++++++++++------- 2 files changed, 68 insertions(+), 57 deletions(-) diff --git a/testui/elements/testui_element.py b/testui/elements/testui_element.py index 854a122..db2064b 100644 --- a/testui/elements/testui_element.py +++ b/testui/elements/testui_element.py @@ -348,7 +348,7 @@ def wait_until_contains_attribute(self, attr, text, seconds=10): ) def wait_until_contains_sensitive_attribute( - self, attr, text, seconds=10.0, log=True + self, attr, text, seconds=10.0, log=True ): start = time.time() err = None @@ -520,12 +520,12 @@ def screenshot(self, image_name="cropped_image.png"): return self def find_image_match( - self, - image_name, - threshold=0.9, - image_match="", - max_scale=2.0, - min_scale=0.3, + self, + image_name, + threshold=0.9, + image_match="", + max_scale=2.0, + min_scale=0.3, ): """ Takes screenshot of the element and compares it with the one you provide @@ -562,12 +562,12 @@ def find_image_match( return self def is_image_match( - self, - image_name, - threshold=0.9, - image_match="", - max_scale=2.0, - min_scale=0.3, + self, + image_name, + threshold=0.9, + image_match="", + max_scale=2.0, + min_scale=0.3, ): """ Takes screenshot of the element and compares it with the one you provide @@ -597,13 +597,13 @@ def is_image_match( return True def swipe( - self, - start_x=None, - start_y=None, - end_x=None, - end_y=None, - el=None, - duration=None, + self, + start_x=None, + start_y=None, + end_x=None, + end_y=None, + el=None, + duration=None, ): """ It swipes from element to the el(second element) or to the coordinates @@ -671,14 +671,14 @@ def slide_percentage(self, percentage, start_x=None): self.swipe(start_x=start_x, end_x=end_width) def swipe_until_text( - self, - start_x=None, - start_y=None, - end_x=None, - end_y=None, - text=None, - el=None, - max_swipes=50, + self, + start_x=None, + start_y=None, + end_x=None, + end_y=None, + text=None, + el=None, + max_swipes=50, ): """ Swipe until an element with that text appears and Returns the element @@ -839,12 +839,12 @@ def get_attribute(self, att): ) def press_and_compare( - self, - image, - milliseconds=1000, - threshold=0.9, - fps_reduction=1, - keep_image_as="", + self, + image, + milliseconds=1000, + threshold=0.9, + fps_reduction=1, + keep_image_as="", ): self.testui_driver.start_recording_screen() self.press_hold_for(milliseconds) @@ -858,7 +858,7 @@ def press_and_compare( start = time.time() if self.testui_driver.stop_recording_and_compare( - image, threshold, fps_reduction, self.__is_not, keep_image_as, False + image, threshold, fps_reduction, self.__is_not, keep_image_as, False ): self.__put_log( f"{self.device_name}: image {found} found while pressing " @@ -884,7 +884,7 @@ def collection_size(self): return len(self.__find_by_collection()) def find_by_attribute( - self, attribute, value: str, timeout=10, case_sensitive=True + self, attribute, value: str, timeout=10, case_sensitive=True ): start = time.time() self.wait_until_visible() @@ -901,9 +901,9 @@ def find_by_attribute( self.index = i return self if ( - not case_sensitive - and element.get_attribute(attribute).lower() - == value.lower() + not case_sensitive + and element.get_attribute(attribute).lower() + == value.lower() ): self.__put_log( f"{self.device_name}: element in collection " diff --git a/testui/support/api_support.py b/testui/support/api_support.py index 79f329c..51ea566 100644 --- a/testui/support/api_support.py +++ b/testui/support/api_support.py @@ -1,49 +1,60 @@ -import requests +"""Module providing methods to get chrome drivers""" +import xml.etree.ElementTree as ET import sys import platform - -from testui.support import logger -import xml.etree.ElementTree as ET +import requests def get_chrome_version(version: str): - URL = "https://chromedriver.storage.googleapis.com/" - r = requests.get(url=URL) + """ + gets all the available chromedriver versios from api + and returns the path for the one asked + :param version: + """ + url = "https://chromedriver.storage.googleapis.com/" + rq = requests.get(url=url) # TODO: it is not pulling the version. I just updated all phones to # latest chrome chrome_version = "" - mytree = ET.ElementTree(ET.fromstring(r.text)) + mytree = ET.ElementTree(ET.fromstring(rq.text)) root = mytree.getroot() for child in root: for child2 in child: - if not child2.text.__contains__(f"{version}."): + if not f"{version}." in child2.text: continue if chrome_name() == "arm64" and \ - child2.text.__contains__("m1") or \ - child2.text.__contains__("mac_arm64"): + "m1" in child2.text or \ + "mac_arm64" in child2.text: chrome_version = child2.text.split("/")[0] - elif child2.text.__contains__(chrome_name()): + elif chrome_name() in child2.text: chrome_version = child2.text.split("/")[0] return chrome_version def chrome_name(): + """ + returns the chromedriver path depending on platform + :return: chromedriver_path string + """ pl = sys.platform - if pl == "linux" or pl == "linux2": + if "linux" in pl: return "/chromedriver_linux64.zip" - elif pl == "darwin": + if pl == "darwin": if os_architecture() == 64: return "arm64" - else: - return "/chromedriver_mac64.zip" - elif pl == "win32": + return "/chromedriver_mac64.zip" + if pl == "win32": return "/chromedriver_win32.zip" + return "" def os_architecture(): + """ + returns the platform architecture + :return: platform_arch int + """ if platform.machine().endswith("64"): return 64 - else: - return 32 + return 32