From dbc58fd492107ad7704811b005c2b8112b5a4a00 Mon Sep 17 00:00:00 2001 From: UchihaMadaraaa Date: Tue, 27 May 2025 16:00:36 +0530 Subject: [PATCH] TTN-23587 bare minimum changes to get the repo back in running state --- .gitignore | 1 + android.py | 44 ++++++++++++++++---------- androidWeb.py | 53 ++++++++++++++++---------------- ios.py | 80 ++++++++++++++++++++++++++++++------------------ iosWeb.py | 60 ++++++++++++++++++++++++------------ requirements.txt | 4 +-- 6 files changed, 147 insertions(+), 95 deletions(-) diff --git a/.gitignore b/.gitignore index a1c2a23..4c1a033 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* +.idea/ diff --git a/android.py b/android.py index 89e0d20..61547db 100644 --- a/android.py +++ b/android.py @@ -1,7 +1,8 @@ from appium import webdriver -from appium.webdriver.common.mobileby import MobileBy +from appium.webdriver.common.appiumby import AppiumBy from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC +from appium.options.android import UiAutomator2Options import time import os @@ -31,57 +32,66 @@ def startingTest(): else: accesskey = os.environ.get("LT_ACCESS_KEY") + driver = None try: - driver = webdriver.Remote(desired_capabilities=desired_caps, command_executor="https://" + - username+":"+accesskey+"@mobile-hub.lambdatest.com/wd/hub") + options = UiAutomator2Options() + for key, value in desired_caps.items(): + options.set_capability(key, value) + + driver = webdriver.Remote( + command_executor="https://" + username + ":" + accesskey + "@mobile-hub.lambdatest.com/wd/hub", + options=options + ) colorElement = WebDriverWait(driver, 20).until(EC.element_to_be_clickable( - (MobileBy.ID, "com.lambdatest.proverbial:id/color"))) + (AppiumBy.ID, "com.lambdatest.proverbial:id/color"))) colorElement.click() textElement = WebDriverWait(driver, 20).until( - EC.element_to_be_clickable((MobileBy.ID, "com.lambdatest.proverbial:id/Text"))) + EC.element_to_be_clickable((AppiumBy.ID, "com.lambdatest.proverbial:id/Text"))) textElement.click() toastElement = WebDriverWait(driver, 20).until(EC.element_to_be_clickable( - (MobileBy.ID, "com.lambdatest.proverbial:id/toast"))) + (AppiumBy.ID, "com.lambdatest.proverbial:id/toast"))) toastElement.click() notification = WebDriverWait(driver, 20).until(EC.element_to_be_clickable( - (MobileBy.ID, "com.lambdatest.proverbial:id/notification"))) + (AppiumBy.ID, "com.lambdatest.proverbial:id/notification"))) notification.click() geolocation = WebDriverWait(driver, 20).until(EC.element_to_be_clickable( - (MobileBy.ID, "com.lambdatest.proverbial:id/geoLocation"))) + (AppiumBy.ID, "com.lambdatest.proverbial:id/geoLocation"))) geolocation.click() time.sleep(5) driver.back() home = WebDriverWait(driver, 20).until(EC.element_to_be_clickable( - (MobileBy.ID, "com.lambdatest.proverbial:id/buttonPage"))) + (AppiumBy.ID, "com.lambdatest.proverbial:id/buttonPage"))) home.click() speedTest = WebDriverWait(driver, 20).until(EC.element_to_be_clickable( - (MobileBy.ID, "com.lambdatest.proverbial:id/speedTest"))) + (AppiumBy.ID, "com.lambdatest.proverbial:id/speedTest"))) speedTest.click() time.sleep(5) driver.back() browser = WebDriverWait(driver, 20).until(EC.element_to_be_clickable( - (MobileBy.ID, "com.lambdatest.proverbial:id/webview"))) + (AppiumBy.ID, "com.lambdatest.proverbial:id/webview"))) browser.click() url = WebDriverWait(driver, 20).until(EC.element_to_be_clickable( - (MobileBy.ID, "com.lambdatest.proverbial:id/url"))) + (AppiumBy.ID, "com.lambdatest.proverbial:id/url"))) url.send_keys("https://www.lambdatest.com") find = WebDriverWait(driver, 20).until(EC.element_to_be_clickable( - (MobileBy.ID, "com.lambdatest.proverbial:id/find"))) + (AppiumBy.ID, "com.lambdatest.proverbial:id/find"))) find.click() driver.quit() - except: - driver.quit() - + except Exception as e: + if driver: + driver.quit() + print(f"Test failed: {e}") -startingTest() +if __name__ == "__main__": + startingTest() diff --git a/androidWeb.py b/androidWeb.py index 7f49fa8..a4dda49 100644 --- a/androidWeb.py +++ b/androidWeb.py @@ -1,14 +1,12 @@ from appium import webdriver -from appium.webdriver.common.mobileby import By -from selenium.webdriver.support.ui import WebDriverWait -from selenium.webdriver.support import expected_conditions as EC +from appium.options.android import UiAutomator2Options import time import os desired_caps = { "deviceName": "Galaxy .*", "platformName": "Android", - "platformVersion": "10", + "platformVersion": "14", "isRealMobile": True, "build": "Python Vanilla Android", "name": "Sample Test - Python", @@ -32,31 +30,34 @@ def startingTest(): accesskey = os.environ.get("LT_ACCESS_KEY") try: - driver = webdriver.Remote(desired_capabilities=desired_caps, command_executor="https://" + - username+":"+accesskey+"@mobile-hub.lambdatest.com/wd/hub") + options = UiAutomator2Options() + for key, value in desired_caps.items(): + options.set_capability(key, value) + driver = webdriver.Remote( + command_executor="https://" + username + ":" + accesskey + "@mobile-hub.lambdatest.com/wd/hub", + options=options + ) driver.get("https://mfml.in/api/getInfo") - colorElement = WebDriverWait(driver, 30).until(EC.element_to_be_clickable( - (By.ID, "resolution"))) - colorElement.click() - - textElement = WebDriverWait(driver, 30).until( - EC.element_to_be_clickable((By.ID, "location"))) - textElement.click() - - toastElement = WebDriverWait(driver, 30).until(EC.element_to_be_clickable( - (By.ID, "details"))) - toastElement.click() - - notification = WebDriverWait(driver, 30).until(EC.element_to_be_clickable( - (By.ID, "timezone"))) - notification.click() - - time.sleep(5) + time.sleep(3) + print("Available contexts:", driver.contexts) + + try: + driver.execute_script('document.getElementById("resolution").click();') + print("Clicked 'resolution' using JS.") + driver.execute_script('document.getElementById("location").click();') + print("Clicked 'location' using JS.") + driver.execute_script('document.getElementById("details").click();') + print("Clicked 'details' using JS.") + driver.execute_script('document.getElementById("timezone").click();') + print("Clicked 'timezone' using JS.") + except Exception as js_e: + print(f"JS click failed: {js_e}") driver.quit() - except: + except Exception as e: + print(f"Test failed: {e}") driver.quit() - -startingTest() +if __name__ == "__main__": + startingTest() diff --git a/ios.py b/ios.py index 7217452..f4963aa 100644 --- a/ios.py +++ b/ios.py @@ -1,13 +1,14 @@ from appium import webdriver -from appium.webdriver.common.mobileby import MobileBy +from appium.webdriver.common.appiumby import AppiumBy from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC +from appium.options.ios import XCUITestOptions import time import os desired_caps = { "deviceName": "iPhone 12", - "platformName": "ios", + "platformName": "iOS", "platformVersion": "14", "isRealMobile": True, "app": "lt://proverbial-ios", # Enter app_url here @@ -31,48 +32,67 @@ def startingTest(): else: accesskey = os.environ.get("LT_ACCESS_KEY") + driver = None try: - driver = webdriver.Remote(desired_capabilities=desired_caps, command_executor="https://" + - username+":"+accesskey+"@mobile-hub.lambdatest.com/wd/hub") - time.sleep(3) - colorElement = WebDriverWait(driver, 20).until( - EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID, "color"))) + options = XCUITestOptions() + for key, value in desired_caps.items(): + options.set_capability(key, value) + + driver = webdriver.Remote( + command_executor="https://" + username + ":" + accesskey + "@mobile-hub.lambdatest.com/wd/hub", + options=options + ) + colorElement = WebDriverWait(driver, 20).until(EC.element_to_be_clickable( + (AppiumBy.ACCESSIBILITY_ID, "color"))) colorElement.click() + textElement = WebDriverWait(driver, 20).until( - EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID, "Text"))) + EC.element_to_be_clickable((AppiumBy.ACCESSIBILITY_ID, "Text"))) textElement.click() - toastElement = WebDriverWait(driver, 20).until( - EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID, "toast"))) + + toastElement = WebDriverWait(driver, 20).until(EC.element_to_be_clickable( + (AppiumBy.ACCESSIBILITY_ID, "toast"))) toastElement.click() - notification = WebDriverWait(driver, 20).until( - EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID, "notification"))) + + notification = WebDriverWait(driver, 20).until(EC.element_to_be_clickable( + (AppiumBy.ACCESSIBILITY_ID, "notification"))) notification.click() - time.sleep(3) - geolocation = WebDriverWait(driver, 20).until( - EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID, "geoLocation"))) + + geolocation = WebDriverWait(driver, 20).until(EC.element_to_be_clickable( + (AppiumBy.ACCESSIBILITY_ID, "geoLocation"))) geolocation.click() - time.sleep(5) + time.sleep(15) + driver.back() - home = WebDriverWait(driver, 20).until( - EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID, "Home"))) + + home = WebDriverWait(driver, 30, poll_frequency=1, ignored_exceptions=[Exception]).until( + EC.presence_of_element_located((AppiumBy.ACCESSIBILITY_ID, "Home")) + ) home.click() - speedTest = WebDriverWait(driver, 20).until( - EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID, "speedTest"))) + + speedTest = WebDriverWait(driver, 20).until(EC.element_to_be_clickable( + (AppiumBy.ACCESSIBILITY_ID, "speedTest"))) speedTest.click() time.sleep(5) + driver.back() - browser = WebDriverWait(driver, 20).until( - EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID, "Browser"))) + + browser = WebDriverWait(driver, 20).until(EC.element_to_be_clickable( + (AppiumBy.ACCESSIBILITY_ID, "Browser"))) browser.click() - url = WebDriverWait(driver, 20).until( - EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID, "url"))) + + url = WebDriverWait(driver, 20).until(EC.element_to_be_clickable( + (AppiumBy.ACCESSIBILITY_ID, "url"))) url.send_keys("https://www.lambdatest.com") - find = WebDriverWait(driver, 20).until( - EC.element_to_be_clickable((MobileBsy.ACCESSIBILITY_ID, "find"))) + + find = WebDriverWait(driver, 20).until(EC.element_to_be_clickable( + (AppiumBy.ACCESSIBILITY_ID, "find"))) find.click() driver.quit() - except: - driver.quit() - + except Exception as e: + if driver: + driver.quit() + print(f"Test failed: {e}") -startingTest() +if __name__ == "__main__": + startingTest() diff --git a/iosWeb.py b/iosWeb.py index c9bbb52..603edf5 100644 --- a/iosWeb.py +++ b/iosWeb.py @@ -1,5 +1,6 @@ from appium import webdriver -from appium.webdriver.common.mobileby import By +from appium.options.ios import XCUITestOptions +from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC import time @@ -30,28 +31,47 @@ def startingTest(): else: accesskey = os.environ.get("LT_ACCESS_KEY") - driver = webdriver.Remote(desired_capabilities=desired_caps, command_executor="https://" + - username+":"+accesskey+"@mobile-hub.lambdatest.com/wd/hub") + try: + options = XCUITestOptions() + for key, value in desired_caps.items(): + options.set_capability(key, value) + driver = webdriver.Remote( + command_executor="https://" + username + ":" + accesskey + "@mobile-hub.lambdatest.com/wd/hub", + options=options + ) - driver.get("https://mfml.in/api/getInfo") + driver.get("https://mfml.in/api/getInfo") + time.sleep(3) + print("Available contexts:", driver.contexts) + + # Wait for and click resolution + resolution = WebDriverWait(driver, 30).until( + EC.element_to_be_clickable((By.ID, "resolution"))) + resolution.click() + print("Clicked 'resolution' using Selenium.") - colorElement = WebDriverWait(driver, 30).until(EC.element_to_be_clickable( - (By.ID, "resolution"))) - colorElement.click() + # Wait for and click location + location = WebDriverWait(driver, 30).until( + EC.element_to_be_clickable((By.ID, "location"))) + location.click() + print("Clicked 'location' using Selenium.") - textElement = WebDriverWait(driver, 30).until( - EC.element_to_be_clickable((By.ID, "location"))) - textElement.click() + # Wait for and click details + details = WebDriverWait(driver, 30).until( + EC.element_to_be_clickable((By.ID, "details"))) + details.click() + print("Clicked 'details' using Selenium.") - toastElement = WebDriverWait(driver, 30).until(EC.element_to_be_clickable( - (By.ID, "details"))) - toastElement.click() + # Wait for and click timezone + timezone = WebDriverWait(driver, 30).until( + EC.element_to_be_clickable((By.ID, "timezone"))) + timezone.click() + print("Clicked 'timezone' using Selenium.") - notification = WebDriverWait(driver, 30).until(EC.element_to_be_clickable( - (By.ID, "timezone"))) - notification.click() - time.sleep(5) - driver.quit() + driver.quit() + except Exception as e: + print(f"Test failed: {e}") + driver.quit() - -startingTest() +if __name__ == "__main__": + startingTest() diff --git a/requirements.txt b/requirements.txt index 22dfa57..515845f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -Appium-Python-Client==0.52;python_version < '3.0' -Appium-Python-Client==1.0.2;python_version >= '3.0' \ No newline at end of file +Appium-Python-Client==3.1.1 +selenium==4.18.1 \ No newline at end of file