Create Test for ios calendar app with python and appium
import time
from appium import webdriver
def test_open_calendar_app():
# Define desired capabilities for the Appium session
desired_caps = {
'platformName': 'iOS',
'platformVersion': '14.5',
'deviceName': 'iPhone 12',
'app': 'com.apple.mobilecal',
'automationName': 'XCUITest'
}
# Start an Appium session with the desired capabilities
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
# Wait for the app to load
time.sleep(5)
# Click on the "Create new event" button
new_event_button = driver.find_element_by_accessibility_id("Add")
new_event_button.click()
# Wait for the new event screen to load
time.sleep(2)
# Click on the "Starts" field
starts_field = driver.find_element_by_accessibility_id("starts")
starts_field.click()
# Wait for the date picker to load
time.sleep(2)
# Get the current date and time
current_time = time.localtime()
current_year = current_time.tm_year
current_month = current_time.tm_mon
current_day = current_time.tm_mday
# Calculate the date for next week
next_week = time.mktime((current_year, current_month, current_day + 7, 0, 0, 0, 0, 0, 0))
next_week_year = time.localtime(next_week).tm_year
next_week_month = time.localtime(next_week).tm_mon
next_week_day = time.localtime(next_week).tm_mday
# Select the date for next week
date_picker = driver.find_element_by_class_name("XCUIElementTypeDatePicker")
year_picker = date_picker.find_element_by_class_name("XCUIElementTypePickerWheel")
year_picker.adjust(to_picker_value=str(next_week_year))
month_picker = date_picker.find_elements_by_class_name("XCUIElementTypePickerWheel")[1]
month_picker.adjust(to_picker_value=str(next_week_month))
day_picker = date_picker.find_elements_by_class_name("XCUIElementTypePickerWheel")[2]
day_picker.adjust(to_picker_value=str(next_week_day))
# Verify that the selected date is correct
starts_field_text = starts_field.get_attribute("value")
expected_date_text = f"{next_week_month}/{next_week_day}/{next_week_year}"
assert starts_field_text == expected_date_text, \
f"Expected date {expected_date_text}, but got {starts_field_text}"
# Quit the Appium session
driver.quit()
Last updated