Skip to content

Commit 0fe48fe

Browse files
lukjj-public-pegaCopilot
authored andcommitted
ENHANCEMENT-472: fix flaky EmbeddedDataSingleRecordTest timing on CI
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d59d5e7 commit 0fe48fe

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

samples/android-cmp-app/src/androidInstrumentedTest/kotlin/com/pega/constellation/sdk/kmp/samples/androidcmpapp/test/ComposeTestUtils.kt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.pega.constellation.sdk.kmp.samples.androidcmpapp.test
22

33
import androidx.compose.ui.test.ComposeUiTest
44
import androidx.compose.ui.test.ExperimentalTestApi
5+
import androidx.compose.ui.test.SemanticsMatcher
56
import androidx.compose.ui.test.SemanticsNodeInteractionCollection
67
import androidx.compose.ui.test.SemanticsNodeInteractionsProvider
78
import androidx.compose.ui.test.assertCountEquals
@@ -18,15 +19,27 @@ import androidx.compose.ui.test.waitUntilNodeCount
1819
private const val DEFAULT_TIMEOUT = 5000L
1920

2021
@OptIn(ExperimentalTestApi::class)
21-
fun ComposeUiTest.waitForNode(text: String, substring: Boolean = false) {
22+
private fun ComposeUiTest.waitForMatcher(matcher: SemanticsMatcher, errorMessage: String) {
2223
runCatching {
23-
waitUntilExactlyOneExists(hasText(text, substring), timeoutMillis = DEFAULT_TIMEOUT)
24+
waitUntilExactlyOneExists(matcher, timeoutMillis = DEFAULT_TIMEOUT)
2425
}.onFailure {
25-
// additional assertion to provide better error message as waitUntil's exception is not very descriptive
26-
onNode(hasText(text, substring)).assertExists("Cannot find node with text '$text'")
26+
onNode(matcher).assertExists(errorMessage)
2727
}
2828
}
2929

30+
@OptIn(ExperimentalTestApi::class)
31+
fun ComposeUiTest.waitForNode(text: String, substring: Boolean = false) {
32+
waitForMatcher(hasText(text, substring), "Cannot find node with text '$text'")
33+
}
34+
35+
@OptIn(ExperimentalTestApi::class)
36+
fun ComposeUiTest.waitForDescendantNode(testTag: String, text: String, substring: Boolean = false) {
37+
waitForMatcher(
38+
hasAnyAncestor(hasTestTag(testTag)) and hasText(text, substring),
39+
"Cannot find node with text '$text' inside '$testTag'"
40+
)
41+
}
42+
3043
@OptIn(ExperimentalTestApi::class)
3144
fun ComposeUiTest.waitForNodes(text: String, count: Int, substring: Boolean = false) {
3245
runCatching {

samples/android-cmp-app/src/androidInstrumentedTest/kotlin/com/pega/constellation/sdk/kmp/samples/androidcmpapp/test/cases/EmbeddedDataSingleRecordTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import androidx.compose.ui.test.runComposeUiTest
1010
import com.pega.constellation.sdk.kmp.samples.androidcmpapp.test.ComposeTest
1111
import com.pega.constellation.sdk.kmp.samples.androidcmpapp.test.find
1212
import com.pega.constellation.sdk.kmp.samples.androidcmpapp.test.onAllDescendantsOf
13+
import com.pega.constellation.sdk.kmp.samples.androidcmpapp.test.waitForDescendantNode
1314
import com.pega.constellation.sdk.kmp.samples.androidcmpapp.test.waitForNode
1415
import com.pega.constellation.sdk.kmp.test.mock.PegaVersion
1516
import java.time.LocalDateTime
@@ -43,6 +44,8 @@ class EmbeddedDataSingleRecordTest : ComposeTest(PegaVersion.v25_1) {
4344

4445
// Check if the same values appears inside inputs in view "Embedded Data - Car single fields"
4546
val singleFieldsView = "group_[Embedded Data - Car single fields]"
47+
// Wait for data propagation before asserting
48+
waitForDescendantNode(singleFieldsView, "Audi")
4649
checkCarData(singleFieldsView, expectedDate, isDetailsView = false)
4750

4851
// Check if the same values appears inside "Embedded Data - Car Details"

0 commit comments

Comments
 (0)