Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 68 additions & 56 deletions android.py
Original file line number Diff line number Diff line change
@@ -1,87 +1,99 @@
from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy
# FIXED: Changed MobileBy to AppiumBy
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.common import AppiumOptions
import time
import os

desired_caps = {
"deviceName": "Galaxy S20",
"platformName": "Android",
"platformVersion": "10",
"app": "lt://proverbial-android", # Enter app_url here
"isRealMobile": True,
"build": "Python Vanilla Android",
"name": "Sample Test - Python",
"network": False,
"visual": True,
"video": True
}


def startingTest():
if os.environ.get("LT_USERNAME") is None:
# Enter LT username here if environment variables have not been added
username = "username"
else:
username = os.environ.get("LT_USERNAME")
if os.environ.get("LT_ACCESS_KEY") is None:
# Enter LT accesskey here if environment variables have not been added
accesskey = "accesskey"
else:
accesskey = os.environ.get("LT_ACCESS_KEY")

# Credentials
username = "mahakgtestmuai"
accesskey = "LT_hO4AGcDjlTzKCdvNZZbWElYk7wuxuN1Vjm0Wvuw6zsLjENx"

# 1. Modern W3C Capabilities
options = AppiumOptions()
options.platform_name = "Android"

lt_options = {
"w3c": True,
"deviceName": "Galaxy S20",
"platformVersion": "10",
"isRealMobile": True,
"app": "lt://APP1016034271771502068985212",
"build": "Python Vanilla Android",
"name": "Sample Test - Python",
"network": True,
"visual": True,
"video": True
}
options.set_capability("lt:options", lt_options)

remote_url = f"https://{username}:{accesskey}@mobile-hub.lambdatest.com/wd/hub"

driver = None
try:
driver = webdriver.Remote(desired_capabilities=desired_caps, command_executor="https://" +
username+":"+accesskey+"@mobile-hub.lambdatest.com/wd/hub")
colorElement = WebDriverWait(driver, 20).until(EC.element_to_be_clickable(
(MobileBy.ID, "com.lambdatest.proverbial:id/color")))
print("Initializing Android session on LambdaTest...")
driver = webdriver.Remote(command_executor=remote_url, options=options)

print("Session started. Running Android tests...")
wait = WebDriverWait(driver, 20)

# FIXED: Changed (MobileBy.ID, ...) to (AppiumBy.ID, ...)
colorElement = wait.until(EC.element_to_be_clickable(
(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")))
textElement = wait.until(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")))
toastElement = wait.until(EC.element_to_be_clickable(
(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")))
notification = wait.until(EC.element_to_be_clickable(
(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")))
geolocation = wait.until(EC.element_to_be_clickable(
(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")))
home = wait.until(EC.element_to_be_clickable(
(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")))
speedTest = wait.until(EC.element_to_be_clickable(
(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")))
browser = wait.until(EC.element_to_be_clickable(
(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")))
url.send_keys("https://www.lambdatest.com")
url_field = wait.until(EC.element_to_be_clickable(
(AppiumBy.ID, "com.lambdatest.proverbial:id/url")))
url_field.send_keys("https://www.lambdatest.com")

find = WebDriverWait(driver, 20).until(EC.element_to_be_clickable(
(MobileBy.ID, "com.lambdatest.proverbial:id/find")))
find.click()
driver.quit()
except:
driver.quit()
find_btn = wait.until(EC.element_to_be_clickable(
(AppiumBy.ID, "com.lambdatest.proverbial:id/find")))
find_btn.click()

print("Android test completed successfully!")

except Exception as e:
print(f"Test failed with error: {e}")
finally:
if driver:
driver.quit()

startingTest()
if __name__ == "__main__":
startingTest()
89 changes: 49 additions & 40 deletions androidWeb.py
Original file line number Diff line number Diff line change
@@ -1,62 +1,71 @@
from appium import webdriver
from appium.webdriver.common.mobileby import By
# For Web tests, we use the standard Selenium 'By'
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from appium.options.common import AppiumOptions
import time
import os

desired_caps = {
"deviceName": "Galaxy .*",
"platformName": "Android",
"platformVersion": "10",
"isRealMobile": True,
"build": "Python Vanilla Android",
"name": "Sample Test - Python",
"network": False,
"visual": True,
"video": True
}


def startingTest():
# Credentials
username = "LT_Username"
accesskey = "LT_ACCESS_KEY"

# 1. Modern W3C Capabilities for Mobile Web
options = AppiumOptions()
options.platform_name = "Android"

lt_options = {
"w3c": True,
"deviceName": "Galaxy .*",
"platformVersion": "11",
"isRealMobile": True,
"browserName": "Chrome",
"build": "Python Vanilla Android Web",
"name": "Sample Web Test - Python",
"network": True,
"visual": True,
"video": True
}
options.set_capability("lt:options", lt_options)

if os.environ.get("LT_USERNAME") is None:
# Enter LT username here if environment variables have not been added
username = "username"
else:
username = os.environ.get("LT_USERNAME")
if os.environ.get("LT_ACCESS_KEY") is None:
# Enter LT accesskey here if environment variables have not been added
accesskey = "accesskey"
else:
accesskey = os.environ.get("LT_ACCESS_KEY")
remote_url = f"https://{username}:{accesskey}@mobile-hub.lambdatest.com/wd/hub"

driver = None
try:
driver = webdriver.Remote(desired_capabilities=desired_caps, command_executor="https://" +
username+":"+accesskey+"@mobile-hub.lambdatest.com/wd/hub")

print("Initializing Android Web session on LambdaTest...")
driver = webdriver.Remote(command_executor=remote_url, options=options)

print("Opening URL: https://mfml.in/api/getInfo")
driver.get("https://mfml.in/api/getInfo")
colorElement = WebDriverWait(driver, 30).until(EC.element_to_be_clickable(
(By.ID, "resolution")))

wait = WebDriverWait(driver, 30)

# 2. Fixed Element Locators (using standard By.ID)
print("Interacting with page elements...")

colorElement = wait.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 = wait.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 = wait.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 = wait.until(EC.element_to_be_clickable((By.ID, "timezone")))
notification.click()

time.sleep(5)
print("Web test completed successfully!")

driver.quit()
except:
driver.quit()

except Exception as e:
print(f"Test failed with error: {e}")
finally:
if driver:
print("Closing session...")
driver.quit()

startingTest()
if __name__ == "__main__":
startingTest()
Loading