-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_ios_simple.py
More file actions
171 lines (135 loc) Β· 6.58 KB
/
test_ios_simple.py
File metadata and controls
171 lines (135 loc) Β· 6.58 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/env python3
"""
Simple iOS test for Liveboard application.
This test connects to the device and navigates through the app.
"""
import time
import os
import sys
def test_ios_connection():
"""Test iOS device connection and Liveboard app navigation."""
print("π Starting iOS Liveboard test...")
# Get device configuration from environment
device_udid = os.getenv('DEVICE_UDID', '00008030-000151561A85402E')
device_name = os.getenv('DEVICE_NAME', 'iPhone SE')
platform_version = os.getenv('PLATFORM_VERSION', '17.2')
team_id = os.getenv('TEAM_ID', '2FHJSTZ57U')
print(f"π± Device: {device_name}")
print(f"π UDID: {device_udid}")
print(f"π± iOS: {platform_version}")
print(f"π₯ Team ID: {team_id}")
start_time = time.time()
try:
# Try to import and use Appium
from appium import webdriver
from appium.webdriver.webdriver import WebDriver
from appium.webdriver.common.appiumby import AppiumBy
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.remote.remote_connection import RemoteConnection
# Configure iOS capabilities
capabilities = {
'platformName': 'iOS',
'platformVersion': platform_version,
'deviceName': device_name,
'udid': device_udid,
'bundleId': 'com.liveboard.LiveBoard',
'automationName': 'XCUITest',
'newCommandTimeout': 300,
'wdaLaunchTimeout': 60000,
'wdaConnectionTimeout': 60000,
'xcuitestTeamId': team_id,
'updateWDABundleId': f"{team_id}.WebDriverAgentRunner"
}
print("π Connecting to Appium server...")
# Create driver with newer Appium syntax
from appium.options.ios.xcuitest.base import XCUITestOptions
options = XCUITestOptions()
options.platform_name = "iOS"
options.platform_version = platform_version
options.device_name = device_name
options.udid = device_udid
options.bundle_id = "com.inconceptlabs.liveboard"
options.automation_name = "XCUITest"
options.new_command_timeout = 600
options.wda_launch_timeout = 180000
options.wda_connection_timeout = 180000
# Add team ID and WDA bundle ID using set_capability
options.set_capability("xcuitestTeamId", team_id)
options.set_capability("updateWDABundleId", f"{team_id}.WebDriverAgentRunner")
options.set_capability("showXcodeLog", True)
options.set_capability("usePrebuiltWDA", True)
driver = WebDriver('http://localhost:4723/wd/hub', options=options)
driver.implicitly_wait(10)
print("β
Connected to iOS device successfully!")
# Take initial screenshot
timestamp = int(time.time())
screenshot_name = f"ios_test_launch_{timestamp}.png"
driver.save_screenshot(screenshot_name)
print(f"πΈ Screenshot saved: {screenshot_name}")
# Wait for app to load
time.sleep(5)
# Try to find any elements on screen
print("π Looking for UI elements...")
# Get page source for debugging
try:
page_source = driver.page_source
print("β
Successfully retrieved page source")
# Look for common iOS elements
elements = driver.find_elements(AppiumBy.CLASS_NAME, "XCUIElementTypeButton")
print(f"Found {len(elements)} buttons")
elements = driver.find_elements(AppiumBy.CLASS_NAME, "XCUIElementTypeTextField")
print(f"Found {len(elements)} text fields")
elements = driver.find_elements(AppiumBy.CLASS_NAME, "XCUIElementTypeStaticText")
print(f"Found {len(elements)} text elements")
except Exception as e:
print(f"β οΈ Could not analyze page elements: {e}")
# Try to interact with the app
print("π― Attempting to interact with app...")
# Find all clickable elements
try:
clickable_elements = driver.find_elements(AppiumBy.CLASS_NAME, "XCUIElementTypeButton")
if clickable_elements:
print(f"Found {len(clickable_elements)} clickable elements")
# Click on first few elements
for i, element in enumerate(clickable_elements[:3]):
try:
element_name = element.get_attribute("name") or f"Button {i+1}"
if element.is_enabled() and element.is_displayed():
print(f"π Clicking: {element_name}")
element.click()
time.sleep(2)
# Take screenshot after click
screenshot_name = f"ios_test_click_{i+1}_{timestamp}.png"
driver.save_screenshot(screenshot_name)
print(f"πΈ Screenshot saved: {screenshot_name}")
except Exception as e:
print(f"β οΈ Could not click element {i+1}: {e}")
else:
print("No clickable elements found")
except Exception as e:
print(f"β οΈ Error finding clickable elements: {e}")
# Final screenshot
screenshot_name = f"ios_test_final_{timestamp}.png"
driver.save_screenshot(screenshot_name)
print(f"πΈ Final screenshot saved: {screenshot_name}")
# Cleanup
driver.quit()
print("β
Test completed successfully!")
duration = time.time() - start_time
print(f"β
Test completed successfully in {duration:.2f} seconds!")
return True
except ImportError as e:
print(f"β Import error: {e}")
print("Make sure Appium Python client is installed: pip install Appium-Python-Client")
duration = time.time() - start_time
print(f"β Test failed in {duration:.2f} seconds")
return False
except Exception as e:
print(f"β Test failed: {e}")
duration = time.time() - start_time
print(f"β Test failed in {duration:.2f} seconds")
return False
if __name__ == "__main__":
success = test_ios_connection()
sys.exit(0 if success else 1)