diff --git a/tests/appium_ios_app.py b/tests/appium_ios_app.py new file mode 100644 index 0000000..f16375d --- /dev/null +++ b/tests/appium_ios_app.py @@ -0,0 +1,25 @@ +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("CC69C1D7-352E-4856-BFD0-B3E908747170") # Change UDID for iOS device + .set_logger() + .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") 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() diff --git a/testui/elements/testui_element.py b/testui/elements/testui_element.py index 4a24af8..db2064b 100644 --- a/testui/elements/testui_element.py +++ b/testui/elements/testui_element.py @@ -3,14 +3,12 @@ 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 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 @@ -123,7 +121,6 @@ def __find_by_element(self) -> WebElement: return self.driver.find_element(AppiumBy.ANDROID_UIAUTOMATOR, f"resourceIdMatches(\"{self.locator}\")" ) - if self.locator_type == "accessibility": return self.driver.find_element( AppiumBy.ACCESSIBILITY_ID, self.locator) @@ -174,7 +171,6 @@ def __find_by_collection(self) -> List[WebElement]: AppiumBy.ANDROID_UIAUTOMATOR, self.locator ) - if self.locator_type == "classChain": return self.driver.find_elements(AppiumBy.IOS_CLASS_CHAIN, self.locator) 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 diff --git a/testui/support/appium_driver.py b/testui/support/appium_driver.py index 1e23f72..371dcef 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 @@ -111,6 +112,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: @@ -224,13 +229,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 @@ -293,7 +300,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() @@ -330,9 +341,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": @@ -348,8 +361,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)