63 / 66 · 09 Mobile & Cross-Platform Testing · Mobile Accessibility Testing← prev⊞ allnext →☰ Read as one page
11.4Dynamic Type (iOS) and Font Scaling (Android)
Users who increase system font size must not be punished with broken layouts. This is both an accessibility requirement and a legal obligation.
def test_dynamic_type_does_not_break_layout(driver):
"""App must remain usable at largest dynamic type setting."""
# Set accessibility font scale to maximum
if driver.capabilities["platformName"] == "iOS":
# iOS Dynamic Type: AX_EXTRA_EXTRA_EXTRA_LARGE
driver.execute_script("mobile: configureLocalization", {
"accessibilityPreferences": {
"preferredContentSizeCategory": "UICTContentSizeCategoryAccessibilityExtraExtraExtraLarge"
}
})
else:
# Android: maximum font scale is typically 2.0
driver.execute_script("mobile: shell", {
"command": "settings",
"args": ["put", "system", "font_scale", "2.0"]
})
# Navigate through critical screens
screens = ["home", "search", "product-detail", "cart", "checkout"]
for screen_id in screens:
driver.find_element(AppiumBy.ACCESSIBILITY_ID, f"{screen_id}-tab").click()
# Verify no text is clipped (truncated with ...)
text_elements = driver.find_elements(AppiumBy.CLASS_NAME, "XCUIElementTypeStaticText")
for text_el in text_elements:
label = text_el.get_attribute("label") or ""
# Check that critical text is not truncated
assert not label.endswith("...") or len(label) > 20, \
f"Text appears truncated at large font: '{label}' on {screen_id}"
# Verify no overlapping elements
all_rects = [el.rect for el in text_elements if el.is_displayed()]
for i, r1 in enumerate(all_rects):
for r2 in all_rects[i+1:]:
overlap = (
r1["x"] < r2["x"] + r2["width"] and
r1["x"] + r1["width"] > r2["x"] and
r1["y"] < r2["y"] + r2["height"] and
r1["y"] + r1["height"] > r2["y"]
)
if overlap:
overlap_area = (
min(r1["x"]+r1["width"], r2["x"]+r2["width"]) - max(r1["x"], r2["x"])
) * (
min(r1["y"]+r1["height"], r2["y"]+r2["height"]) - max(r1["y"], r2["y"])
)
assert overlap_area < 100, \
f"Significant element overlap detected on {screen_id} screen"