Skip to content

Commit

Permalink
update all performTextInput() calls in UX tests to work around Compos…
Browse files Browse the repository at this point in the history
…e test's bug:

Detected multithreaded access to SnapshotStateObserver: previousThreadId=708), currentThread={id=942, name=Thread-510 @coroutine#850669}. Note that observation on multiple threads in layout/draw is not supported. Make sure your measure/layout/draw for each Owner (AndroidComposeView) is executed on the same thread.

https://issuetracker.google.com/issues/319395743
  • Loading branch information
sunny-chung committed Nov 5, 2024
1 parent e50c1fd commit 9abbfef
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,12 @@ suspend fun ComposeUiTest.createGraphqlRequest(request: UserRequestTemplate, env
val body = request.examples.first().body as GraphqlBody

onNodeWithTag(TestTag.RequestGraphqlDocumentTextField.name)
.performTextInput(body.document)
.performTextInput(this, body.document)

delayShort() // needed, otherwise document text field sometimes have no text inputted

onNodeWithTag(TestTag.RequestGraphqlVariablesTextField.name)
.performTextInput(body.variables)
.performTextInput(this, body.variables)

if (body.operationName != null) {
delayShort()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ class GrpcRequestResponseTest(testName: String, isSsl: Boolean, isMTls: Boolean)
if (request.examples.first().body is StringBody) {
onNodeWithTag(TestTag.RequestStringBodyTextField.name)
.assertIsDisplayedWithRetry(this)
.performTextInput((request.examples.first().body as StringBody).value)
.performTextInput(this, (request.examples.first().body as StringBody).value)
delayShort()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ suspend fun ComposeUiTest.createProjectIfNeeded() {
.performClickWithRetry(this)
waitUntilExactlyOneExists(hasTestTag(TestTag.ProjectNameAndSubprojectNameDialogTextField.name), 1500L)
onNodeWithTag(TestTag.ProjectNameAndSubprojectNameDialogTextField.name)
.performTextInput("Test Project ${KZonedInstant.nowAtLocalZoneOffset().format("HH:mm:ss")}")
.performTextInput(this, "Test Project ${KZonedInstant.nowAtLocalZoneOffset().format("HH:mm:ss")}")
waitForIdle()
onNodeWithTag(TestTag.ProjectNameAndSubprojectNameDialogDoneButton.name)
.performClickWithRetry(this)
Expand All @@ -140,7 +140,7 @@ suspend fun ComposeUiTest.createProjectIfNeeded() {
.performClickWithRetry(this)
waitUntilExactlyOneExists(hasTestTag(TestTag.ProjectNameAndSubprojectNameDialogTextField.name), 1500L)
onNodeWithTag(TestTag.ProjectNameAndSubprojectNameDialogTextField.name)
.performTextInput("Test Subproject")
.performTextInput(this, "Test Subproject")
waitForIdle()
onNodeWithTag(TestTag.ProjectNameAndSubprojectNameDialogDoneButton.name)
.assertIsDisplayedWithRetry(this)
Expand Down Expand Up @@ -428,7 +428,7 @@ suspend fun ComposeUiTest.createEnvironmentInEnvDialog(name: String) {
waitForIdle()

onNodeWithTag(TestTag.EnvironmentDialogEnvNameTextField.name)
.performTextInput(name)
.performTextInput(this, name)

waitUntil(3.seconds().millis) {
// one in list view and one in text field
Expand Down Expand Up @@ -512,7 +512,7 @@ suspend fun ComposeUiTest.createRequest(request: UserRequestTemplate, environmen

onNodeWithTag(TestTag.RequestUrlTextField.name)
.assertIsDisplayedWithRetry(this)
.performTextInput(request.url)
.performTextInput(this, request.url)

delayShort()

Expand Down Expand Up @@ -541,7 +541,7 @@ suspend fun ComposeUiTest.createRequest(request: UserRequestTemplate, environmen
if (body.isNotEmpty()) {
onNodeWithTag(TestTag.RequestStringBodyTextField.name)
.assertIsDisplayedWithRetry(this)
.performTextInput(body)
.performTextInput(this, body)
delayShort()
}
}
Expand Down Expand Up @@ -580,7 +580,7 @@ suspend fun ComposeUiTest.createRequest(request: UserRequestTemplate, environmen
)
)
.assertIsDisplayedWithRetry(this)
.performTextInput(it.key)
.performTextInput(this, it.key)
delayShort()
onNode(
hasTestTag(
Expand Down Expand Up @@ -608,7 +608,7 @@ suspend fun ComposeUiTest.createRequest(request: UserRequestTemplate, environmen
)
)
.assertIsDisplayedWithRetry(this)
.performTextInput(it.value)
.performTextInput(this, it.value)
delayShort()
}

Expand Down Expand Up @@ -729,7 +729,7 @@ suspend fun ComposeUiTest.createRequest(request: UserRequestTemplate, environmen
)
)
.assertIsDisplayedWithRetry(this)
.performTextInput(it.key)
.performTextInput(this, it.key)
delayShort()

onNode(
Expand All @@ -755,7 +755,7 @@ suspend fun ComposeUiTest.createRequest(request: UserRequestTemplate, environmen
)
)
.assertIsDisplayedWithRetry(this)
.performTextInput(it.value)
.performTextInput(this, it.value)
delayShort()
}
}
Expand Down Expand Up @@ -817,7 +817,7 @@ suspend fun ComposeUiTest.createRequest(request: UserRequestTemplate, environmen
)
)
.assertIsDisplayedWithRetry(this)
.performTextInput(it.key)
.performTextInput(this, it.key)
delayShort()
onNode(
hasTestTag(
Expand All @@ -842,7 +842,7 @@ suspend fun ComposeUiTest.createRequest(request: UserRequestTemplate, environmen
)
)
.assertIsDisplayedWithRetry(this)
.performTextInput(it.value)
.performTextInput(this, it.value)
delayShort()
}
}
Expand Down Expand Up @@ -874,11 +874,11 @@ suspend fun ComposeUiTest.createRequest(request: UserRequestTemplate, environmen
)
onNode(hasTestTag(buildTestTag(TestTagPart.RequestHeader, TestTagPart.Current, TestTagPart.Key, index)!!))
.assertIsDisplayedWithRetry(this)
.performTextInput(it.key)
.performTextInput(this, it.key)
delayShort()
onNode(hasTestTag(buildTestTag(TestTagPart.RequestHeader, TestTagPart.Current, TestTagPart.Value, index)!!))
.assertIsDisplayedWithRetry(this)
.performTextInput(it.value)
.performTextInput(this, it.value)
delayShort()
}
}
Expand All @@ -892,7 +892,7 @@ suspend fun ComposeUiTest.createRequest(request: UserRequestTemplate, environmen

onNode(hasTestTag(TestTag.RequestPreFlightScriptTextField.name))
.assertIsDisplayedWithRetry(this)
.performTextInput(baseExample.preFlight.executeCode)
.performTextInput(this, baseExample.preFlight.executeCode)

waitUntil {
onNode(hasTestTag(TestTag.RequestPreFlightScriptTextField.name))
Expand Down Expand Up @@ -1042,7 +1042,7 @@ suspend fun ComposeUiTest.sendPayload(payload: String, isCreatePayloadExample: B

onNodeWithTag(TestTag.RequestPayloadTextField.name)
.assertIsDisplayedWithRetry(this)
.performTextInput(payload)
.performTextInput(this, payload)

delayShort()

Expand Down Expand Up @@ -1185,3 +1185,12 @@ fun SemanticsNodeInteractionCollection.fetchSemanticsNodesWithRetry(host: Compos
}
}
}

/**
* To work around the bug: https://issuetracker.google.com/issues/319395743
*/
fun SemanticsNodeInteraction.performTextInput(host: ComposeUiTest, s: String) {
host.runOnUiThread {
performTextInput(s)
}
}

0 comments on commit 9abbfef

Please sign in to comment.