-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathrun_ui_tests.sh
More file actions
executable file
·168 lines (148 loc) · 6.1 KB
/
Copy pathrun_ui_tests.sh
File metadata and controls
executable file
·168 lines (148 loc) · 6.1 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
#!/bin/bash
set -euo pipefail
if [[ -n "${DESTINATION:-}" ]]; then
TEST_DESTINATION="$DESTINATION"
elif [[ -n "${CI_DEVICE_UDID:-}" ]]; then
TEST_DESTINATION="platform=iOS Simulator,id=$CI_DEVICE_UDID"
elif [[ -n "${CI_DESTINATION:-}" ]]; then
TEST_DESTINATION="$CI_DESTINATION"
else
TEST_DESTINATION="platform=iOS Simulator,name=iPhone 17 Pro"
fi
MODE="${1:-smoke}"
SMOKE_TESTS=(
FeedAndSettingsUITests/testSmokeLaunchFeedAndSettings
FeedAndSettingsUITests/testSmokeOpenCustomBrowserFromFeed
)
FULL_TESTS=(
FeedAndSettingsUITests/testSmokeLaunchFeedAndSettings
FeedAndSettingsUITests/testSmokeOpenCustomBrowserFromFeed
FeedAndSettingsUITests/testSearchUsesMockedAlgoliaResults
FeedAndSettingsUITests/testCategoryMenuUsesMockedFeeds
FeedAndSettingsUITests/testLoginFailureAndSuccessUseMockedAuthentication
BrowserCommentsUITests/testCustomBrowserExpandedCommentsBlockMediaAutoplay
BrowserCommentsUITests/testCustomBrowserCollapsedCommentsRetainMediaAutoplay
BrowserCommentsUITests/testCustomBrowserCommentsSheetCollapsedPreview
BrowserCommentsUITests/testCustomBrowserExpandedCommentsChrome
BrowserCommentsUITests/testCustomBrowserTitlePillTapCollapsesExpandedComments
BrowserCommentsUITests/testCustomBrowserTitlePillDragCollapsesExpandedComments
BrowserCommentsUITests/testCustomBrowserTopChromeDragCollapsesExpandedComments
BrowserCommentsUITests/testCustomBrowserSheetContentDragCollapsesExpandedComments
BrowserCommentsUITests/testCustomBrowserCollapsedHandleDragExpandsComments
BrowserCommentsUITests/testCustomBrowserPreservesCommentScrollPositionAcrossCollapse
BrowserCommentsUITests/testCustomBrowserCommentsReturnToTopAfterLongScroll
BrowserCommentsUITests/testCustomBrowserLargeCommentListReturnsToTopAfterLongScroll
BrowserCommentsUITests/testCustomBrowserLargeCommentBranchCollapsesAndExpands
BrowserCommentsUITests/testCustomBrowserExpandedCommentPreservesScrollPosition
NavigationAndCommentsUITests/testSystemBackSwipeFromCustomBrowserCollapsedComments
NavigationAndCommentsUITests/testSystemBackSwipeFromCustomBrowserExpandedComments
NavigationAndCommentsUITests/testSystemBackSwipeFromComments
NavigationAndCommentsUITests/testOpenCommentsFromFeed
NavigationAndCommentsUITests/testLaunchesDirectCommentsRoute
NavigationAndCommentsUITests/testLaunchesDirectCollapsedStoryRoute
NavigationAndCommentsUITests/testLaunchesDirectExpandedStoryRoute
NavigationAndCommentsUITests/testNextCommentButtonStartsAtFirstCommentThenAdvances
NavigationAndCommentsUITests/testCollapsingCommentKeepsRootContextAvailable
NavigationAndCommentsUITests/testSwipingCommentRowCollapsesThread
)
FUNCTIONAL_TEST_SOURCES=(
HackersUITests/HackersUITests.swift
HackersUITests/BrowserCommentsUITests.swift
HackersUITests/NavigationAndCommentsUITests.swift
)
case "$MODE" in
smoke)
SELECTED_TESTS=("${SMOKE_TESTS[@]}")
;;
full|--full)
MODE=full
SELECTED_TESTS=("${FULL_TESTS[@]}")
;;
*)
echo "Unknown UI test mode: $MODE (expected smoke or full)" >&2
exit 2
;;
esac
/usr/bin/python3 - "${FUNCTIONAL_TEST_SOURCES[@]}" -- "${FULL_TESTS[@]}" <<'PY'
import re
import sys
separator = sys.argv.index("--")
source_paths = sys.argv[1:separator]
manifest = sys.argv[separator + 1:]
discovered = []
for source_path in source_paths:
source = open(source_path, encoding="utf-8").read()
classes = re.findall(
r"^final class ([A-Za-z0-9_]+): HackersUITestCase \{",
source,
re.MULTILINE,
)
if len(classes) != 1:
raise SystemExit(f"Expected one functional UI test class in {source_path}, found {classes!r}")
discovered.extend(
f"{classes[0]}/{test_name}"
for test_name in re.findall(r"^ func (test[A-Za-z0-9_]+)\(", source, re.MULTILINE)
)
if len(manifest) != len(set(manifest)):
raise SystemExit("Full UI test manifest contains duplicate test names")
if manifest != discovered:
missing = [name for name in discovered if name not in manifest]
stale = [name for name in manifest if name not in discovered]
raise SystemExit(
"Full UI test manifest does not match the functional UI test sources. "
f"Missing: {missing!r}; stale: {stale!r}; "
f"expected source order: {discovered!r}"
)
PY
TEST_SELECTION=()
EXPECTED_IDENTIFIERS=()
for test_identifier in "${SELECTED_TESTS[@]}"; do
TEST_SELECTION+=("-only-testing:HackersUITests/$test_identifier")
EXPECTED_IDENTIFIERS+=("$test_identifier()")
done
RESULT_BUNDLE_PATH="${RESULT_BUNDLE_PATH:-artifacts/xcresults/Hackers-UITests.xcresult}"
rm -rf "$RESULT_BUNDLE_PATH"
mkdir -p "$(dirname "$RESULT_BUNDLE_PATH")"
COMMAND=(
xcodebuild test
-project Hackers.xcodeproj
-scheme Hackers
-destination "$TEST_DESTINATION"
-resultBundlePath "$RESULT_BUNDLE_PATH"
)
COMMAND+=("${TEST_SELECTION[@]}")
"${COMMAND[@]}"
xcrun xcresulttool get test-results tests \
--path "$RESULT_BUNDLE_PATH" \
--compact | /usr/bin/python3 -c '
import json
import sys
mode = sys.argv[1]
expected = sys.argv[2:]
root = json.load(sys.stdin)
cases = []
def visit(node):
if isinstance(node, dict):
if node.get("nodeType") == "Test Case":
cases.append(node)
for value in node.values():
visit(value)
elif isinstance(node, list):
for value in node:
visit(value)
visit(root)
identifiers = [test.get("nodeIdentifier", test["name"]) for test in cases]
failures = [test["name"] for test in cases if test.get("result") != "Passed"]
if failures:
raise SystemExit("UI test result bundle contains non-passing cases: {}".format(", ".join(failures)))
if len(identifiers) != len(set(identifiers)):
raise SystemExit(f"{mode.capitalize()} result contains duplicate test cases: {identifiers!r}")
if sorted(identifiers) != sorted(expected):
missing = sorted(set(expected) - set(identifiers))
unexpected = sorted(set(identifiers) - set(expected))
raise SystemExit(
f"{mode.capitalize()} result mismatch. Missing: {missing!r}; "
f"unexpected: {unexpected!r}; got: {identifiers!r}"
)
print(f"Verified {len(identifiers)} {mode} UI test case(s) in the result bundle.")
' "$MODE" "${EXPECTED_IDENTIFIERS[@]}"