forked from LambdaTest/LT-appium-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathandroid.py
More file actions
99 lines (78 loc) · 3.25 KB
/
android.py
File metadata and controls
99 lines (78 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
from appium import webdriver
# 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
def startingTest():
# 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:
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 = wait.until(EC.element_to_be_clickable(
(AppiumBy.ID, "com.lambdatest.proverbial:id/Text")))
textElement.click()
toastElement = wait.until(EC.element_to_be_clickable(
(AppiumBy.ID, "com.lambdatest.proverbial:id/toast")))
toastElement.click()
notification = wait.until(EC.element_to_be_clickable(
(AppiumBy.ID, "com.lambdatest.proverbial:id/notification")))
notification.click()
geolocation = wait.until(EC.element_to_be_clickable(
(AppiumBy.ID, "com.lambdatest.proverbial:id/geoLocation")))
geolocation.click()
time.sleep(5)
driver.back()
home = wait.until(EC.element_to_be_clickable(
(AppiumBy.ID, "com.lambdatest.proverbial:id/buttonPage")))
home.click()
speedTest = wait.until(EC.element_to_be_clickable(
(AppiumBy.ID, "com.lambdatest.proverbial:id/speedTest")))
speedTest.click()
time.sleep(5)
driver.back()
browser = wait.until(EC.element_to_be_clickable(
(AppiumBy.ID, "com.lambdatest.proverbial:id/webview")))
browser.click()
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_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()
if __name__ == "__main__":
startingTest()