Skip to content

Commit efe2786

Browse files
CodeRabbit fixes
1 parent 2b68e91 commit efe2786

File tree

3 files changed

+46
-35
lines changed

3 files changed

+46
-35
lines changed

app/src/androidTest/kotlin/com/itsaky/androidide/PermissionsInfoScreenTest.kt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,18 @@ class PermissionsInfoScreenTest : TestCase() {
5252
val root = InstrumentationRegistry.getInstrumentation().uiAutomation
5353
.rootInActiveWindow ?: return false
5454
val nodes = root.findAccessibilityNodeInfosByText(text)
55-
for (node in nodes) {
56-
if (node.text?.toString().equals(text, ignoreCase = true)) {
57-
val result = node.performAction(AccessibilityNodeInfo.ACTION_CLICK)
55+
var result = false
56+
try {
57+
for (node in nodes) {
58+
if (!result && node.text?.toString().equals(text, ignoreCase = true)) {
59+
result = node.performAction(AccessibilityNodeInfo.ACTION_CLICK)
60+
}
5861
node.recycle()
59-
root.recycle()
60-
return result
6162
}
62-
node.recycle()
63+
} finally {
64+
root.recycle()
6365
}
64-
root.recycle()
65-
return false
66+
return result
6667
}
6768

6869
@Test
@@ -101,7 +102,7 @@ class PermissionsInfoScreenTest : TestCase() {
101102
}
102103

103104
@Test
104-
fun test_privacyDialog_notShownOnSecondVisit() = run {
105+
fun test_privacyDialog_dismissedAfterAccept() = run {
105106
step("Wait for app") {
106107
device.uiDevice.waitForIdle()
107108
}

app/src/androidTest/kotlin/com/itsaky/androidide/helper/GrantRequiredPermissionsUiHelper.kt

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,22 @@ private fun clickFirstGrantButton() {
7272

7373
val nodes = root.findAccessibilityNodeInfosByText(grantText)
7474
var clicked = false
75-
for (node in nodes) {
76-
if (node.text?.toString().equals(grantText, ignoreCase = true)
77-
&& node.isClickable
78-
&& node.isEnabled
79-
&& node.isVisibleToUser
80-
) {
81-
node.performAction(AccessibilityNodeInfo.ACTION_CLICK)
82-
clicked = true
75+
try {
76+
for (node in nodes) {
77+
if (!clicked
78+
&& node.text?.toString().equals(grantText, ignoreCase = true)
79+
&& node.isClickable
80+
&& node.isEnabled
81+
&& node.isVisibleToUser
82+
) {
83+
node.performAction(AccessibilityNodeInfo.ACTION_CLICK)
84+
clicked = true
85+
}
8386
node.recycle()
84-
break
8587
}
86-
node.recycle()
88+
} finally {
89+
root.recycle()
8790
}
88-
root.recycle()
8991

9092
if (!clicked) {
9193
throw AssertionError("No '$grantText' button found")

app/src/androidTest/kotlin/com/itsaky/androidide/helper/OnboardingPermissionsInfoHelper.kt

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,35 @@ fun TestContext<Unit>.passPermissionsInfoSlideWithPrivacyDialog() {
3636
}
3737
}
3838
step("Continue from permissions information slide") {
39-
flakySafely(timeoutMs = 3_000) {
40-
// The Next button is in the system gesture exclusion zone. Use accessibility
41-
// ACTION_CLICK to bypass coordinate-based touch injection.
42-
val root = InstrumentationRegistry.getInstrumentation().uiAutomation
43-
.rootInActiveWindow
44-
?: throw AssertionError("No active window for accessibility")
45-
val nodes = root.findAccessibilityNodeInfosByText("NEXT")
46-
var clicked = false
39+
// After dismissing the dialog, the accessibility tree transitions from 2 windows
40+
// to 1. Use UIAutomator's waitForExists (which handles window transitions) to
41+
// wait for the NEXT button to become reachable, then click via accessibility.
42+
val d = device.uiDevice
43+
val nextObj = d.findObject(UiSelector().descriptionContains("NEXT"))
44+
if (!nextObj.waitForExists(3_000)) {
45+
throw AssertionError("NEXT button not found on permissions info slide")
46+
}
47+
48+
val uiAutomation = InstrumentationRegistry.getInstrumentation().uiAutomation
49+
val root = uiAutomation.rootInActiveWindow
50+
?: throw AssertionError("No active window for accessibility")
51+
val nodes = root.findAccessibilityNodeInfosByText("NEXT")
52+
var clicked = false
53+
try {
4754
for (node in nodes) {
48-
if (node.contentDescription?.toString()?.contains("NEXT", ignoreCase = true) == true) {
55+
val desc = node.contentDescription?.toString() ?: ""
56+
val text = node.text?.toString() ?: ""
57+
if (!clicked && (desc.contains("NEXT", ignoreCase = true) || text.contains("NEXT", ignoreCase = true))) {
4958
clicked = node.performAction(AccessibilityNodeInfo.ACTION_CLICK)
50-
node.recycle()
51-
break
5259
}
5360
node.recycle()
5461
}
62+
} finally {
5563
root.recycle()
56-
if (!clicked) {
57-
throw AssertionError("NEXT button not found on permissions info slide")
58-
}
59-
device.uiDevice.waitForIdle()
6064
}
65+
if (!clicked) {
66+
throw AssertionError("NEXT button found by UIAutomator but accessibility click failed")
67+
}
68+
d.waitForIdle()
6169
}
6270
}

0 commit comments

Comments
 (0)