Skip to content

Commit b3c4d6e

Browse files
authored
appium: font (#373)
1 parent d399791 commit b3c4d6e

8 files changed

Lines changed: 97 additions & 17 deletions

File tree

appium/test_font.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from appium.webdriver.webdriver import WebDriver
2+
from util.button import get_label
3+
from util.config import read_theme_config
4+
from util.message import ASSUMPTION_OUTDATED, CHANGE_NOT_SAVED, UI_NOT_UPDATED
5+
from util.window import find_element_by_id, find_elements_by_id, open_theme_config
6+
7+
TEXT_FONT_FAMILY_ID = "TextFontFamily"
8+
FONT_HELVETICA = "Helvetica"
9+
FONT_SERIF = "serif"
10+
FONT_EMOJI = "Apple Color Emoji"
11+
12+
13+
def test_font_selection(driver: WebDriver, app: str):
14+
open_theme_config(driver)
15+
find_element_by_id(driver, "Font").click()
16+
17+
def get_font_values() -> list[str]:
18+
return [
19+
get_label(element)
20+
for element in find_elements_by_id(driver, TEXT_FONT_FAMILY_ID)
21+
]
22+
23+
def read_config_value() -> dict[str, str]:
24+
return read_theme_config(app)[f"Font/{TEXT_FONT_FAMILY_ID}"]
25+
26+
font_button = find_element_by_id(driver, TEXT_FONT_FAMILY_ID)
27+
font_button.click()
28+
emoji_elements = find_elements_by_id(driver, FONT_EMOJI)
29+
assert len(emoji_elements) == 1, ASSUMPTION_OUTDATED
30+
31+
search = find_element_by_id(driver, "search")
32+
search.click()
33+
search.send_keys("helvetica")
34+
emoji_elements = find_elements_by_id(driver, FONT_EMOJI)
35+
assert len(emoji_elements) == 0, UI_NOT_UPDATED
36+
37+
find_element_by_id(driver, FONT_HELVETICA).click()
38+
find_element_by_id(driver, "select").click()
39+
assert get_font_values() == [FONT_HELVETICA], UI_NOT_UPDATED
40+
assert read_config_value() == {"0": FONT_HELVETICA}, CHANGE_NOT_SAVED
41+
42+
find_element_by_id(driver, f"{TEXT_FONT_FAMILY_ID}_plus").click()
43+
find_elements_by_id(driver, TEXT_FONT_FAMILY_ID)[1].click()
44+
find_element_by_id(driver, "GenericFontFamiliesTab").click()
45+
find_element_by_id(driver, FONT_SERIF).click()
46+
find_element_by_id(driver, "select").click()
47+
assert get_font_values() == [FONT_HELVETICA, FONT_SERIF], UI_NOT_UPDATED
48+
assert read_config_value() == {"0": FONT_HELVETICA, "1": FONT_SERIF}, (
49+
CHANGE_NOT_SAVED
50+
)

appium/test_key.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from appium.webdriver.webdriver import WebDriver
22
from selenium.webdriver.common.keys import Keys
3-
from util.button import get_undo_redo
3+
from util.button import get_label, get_undo_redo
44
from util.config import read_global_config
5-
from util.key import get_label, press
5+
from util.key import press
66
from util.message import (
77
BUTTON_SHOULD_BE_DISABLED,
88
BUTTON_SHOULD_BE_ENABLED,

appium/test_list.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
from appium.webdriver.webdriver import WebDriver
2-
from util.button import get_undo_redo
2+
from util.button import get_label, get_undo_redo
33
from util.config import read_config, read_global_config
44
from util.enum import get_enum_value, select_enum_option
5-
from util.key import get_label
6-
from util.list import click_minus, click_plus
5+
from util.list import click_minus, click_plus, click_up
76
from util.message import (
87
ASSUMPTION_OUTDATED,
98
BUTTON_SHOULD_BE_DISABLED,
@@ -80,6 +79,14 @@ def read_config_value() -> dict[str, str]:
8079
assert get_provider_values() == provider_values, UI_NOT_UPDATED
8180
assert read_config_value() == config_after_minus, CHANGE_NOT_SAVED
8281

82+
click_up(driver, PROVIDER_ORDER, 1)
83+
provider_values.reverse()
84+
assert get_provider_values() == provider_values, UI_NOT_UPDATED
85+
assert read_config_value() == {
86+
"0": config_after_minus["1"],
87+
"1": config_after_minus["0"],
88+
}, CHANGE_NOT_SAVED
89+
8390

8491
def test_clear_list_and_reset(driver: WebDriver, app: str):
8592
def count() -> int:

appium/util/button.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@ def get_undo_redo(driver: WebDriver) -> tuple[WebElement, WebElement]:
1313
assert redo.is_enabled() is False, BUTTON_SHOULD_BE_DISABLED
1414

1515
return undo, redo
16+
17+
18+
def get_label(button: WebElement) -> str:
19+
"""Get the label attribute of a button."""
20+
return button.get_attribute("label")

appium/util/color.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from appium.webdriver.common.appiumby import AppiumBy
22
from selenium.webdriver.common.keys import Keys
33
from selenium.webdriver.remote.webelement import WebElement
4+
from util.button import get_label
45
from util.key import press
56
from util.window import find_element_by_id
67

@@ -20,7 +21,7 @@ def set_color_value(element: WebElement, value: str):
2021
# Slider mode
2122
buttons = driver.find_elements(AppiumBy.CLASS_NAME, "XCUIElementTypeButton")
2223
for button in buttons:
23-
if button.get_attribute("label") == "Color Sliders":
24+
if get_label(button) == "Color Sliders":
2425
button.click()
2526
break
2627

appium/util/key.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from appium.webdriver.webdriver import WebDriver
22
from selenium.webdriver.common.actions.action_builder import ActionBuilder
3-
from selenium.webdriver.remote.webelement import WebElement
43

54

65
def press(driver: WebDriver, keys: list[str]):
@@ -10,7 +9,3 @@ def press(driver: WebDriver, keys: list[str]):
109
for key in reversed(keys):
1110
action.key_action.key_up(key)
1211
action.perform()
13-
14-
15-
def get_label(button: WebElement) -> str:
16-
return button.get_attribute("label")

appium/util/list.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@
22
from util.window import find_element_by_id
33

44

5+
def _click(driver: WebDriver, option_id: str, index: int, action: str):
6+
find_element_by_id(driver, f"{option_id}_{index}_{action}").click()
7+
8+
59
def click_minus(driver: WebDriver, option_id: str, index: int):
6-
find_element_by_id(driver, f"{option_id}_{index}_minus").click()
10+
_click(driver, option_id, index, "minus")
711

812

913
def click_plus(driver: WebDriver, option_id: str, index: int):
10-
find_element_by_id(driver, f"{option_id}_{index}_plus").click()
14+
_click(driver, option_id, index, "plus")
15+
16+
17+
def click_up(driver: WebDriver, option_id: str, index: int):
18+
_click(driver, option_id, index, "up")

src/config/FontView.swift

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,13 @@ struct FontView: OptionViewProtocol {
5858
Text(localize(font))
5959
}
6060
}
61+
.accessibilityIdentifier(data["Option"] as? String ?? "")
6162
.sheet(isPresented: $selectorIsOpen) {
6263
VStack {
6364
TabView {
6465
VStack {
6566
TextField(NSLocalizedString("Search", comment: ""), text: $searchInput)
67+
.accessibilityIdentifier("search")
6668
TextField(NSLocalizedString("Preview", comment: ""), text: $previewInput)
6769
Text(previewInput).font(Font.custom(selectedFontFamily ?? font, size: 32)).frame(
6870
height: 64)
@@ -73,27 +75,36 @@ struct FontView: OptionViewProtocol {
7375
Spacer()
7476
Text(localize(family))
7577
}
78+
.accessibilityElement(children: .combine)
79+
.accessibilityIdentifier(family)
7680
}
7781
}.contextMenu(forSelectionType: String.self) { items in
7882
} primaryAction: { items in
7983
// Double click
8084
select()
8185
}
8286
}.padding()
83-
.tabItem { Text("Font family") }
87+
.tabItem {
88+
Text("Font family")
89+
.accessibilityIdentifier("FontFamilyTab")
90+
}
8491

8592
VStack {
8693
List(selection: $selectedFontFamily) {
8794
ForEach(genericFamilies, id: \.self) { family in
8895
Text(family)
96+
.accessibilityIdentifier(family)
8997
}
9098
}.contextMenu(forSelectionType: String.self) { items in
9199
} primaryAction: { items in
92100
// Double click
93101
select()
94102
}
95103
}.padding()
96-
.tabItem { Text("Generic font families") }
104+
.tabItem {
105+
Text("Generic font families")
106+
.accessibilityIdentifier("GenericFontFamiliesTab")
107+
}
97108
}
98109

99110
HStack {
@@ -102,13 +113,16 @@ struct FontView: OptionViewProtocol {
102113
} label: {
103114
Text("Cancel")
104115
}
116+
.accessibilityIdentifier("cancel")
105117
Spacer()
106118
Button {
107119
select()
108120
} label: {
109121
Text("Select")
110-
}.buttonStyle(.borderedProminent)
111-
.disabled(selectedFontFamily == nil)
122+
}
123+
.accessibilityIdentifier("select")
124+
.buttonStyle(.borderedProminent)
125+
.disabled(selectedFontFamily == nil)
112126
}.padding([.leading, .trailing, .bottom])
113127
}
114128
.padding(.top)

0 commit comments

Comments
 (0)