Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with matching child nodes for the Compose Screen #25

Closed
AJIEKCX opened this issue Apr 1, 2022 · 3 comments
Closed

Problems with matching child nodes for the Compose Screen #25

AJIEKCX opened this issue Apr 1, 2022 · 3 comments

Comments

@AJIEKCX
Copy link

AJIEKCX commented Apr 1, 2022

Hi, I have a problem with matching child nodes for the ComposeScreen. It works in simple cases but for the current screen it won’t work:

fun SimpleScreen() {
   Scaffold(Modifier.testTag(TestTag.SimpleScreen.Tag)) {
       Card {
           Text(
               "TestTitle",
               Modifier
                   .padding(16.dp)
                   .testTag(TestTag.SimpleScreen.Title)
           )
       }
   }
}

The following PageObject can’t find our title at this screen:

class KSimpleScreen(semanticsProvider: SemanticsNodeInteractionsProvider) : ComposeScreen<KSimpleScreen>(
   semanticsProvider = semanticsProvider,
   viewBuilderAction = { hasTestTag(TestTag.SimpleScreen.Tag) }
) {
   val title: KNode = child {
       hasTestTag(TestTag.SimpleScreen.Title)
   }
}

It can be fixed by deleting child and using hasAnyAncestor matcher:

val title: KNode = KNode(semanticsProvider) {
   hasAnyAncestor((androidx.compose.ui.test.hasTestTag(TestTag.SimpleScreen.Tag)))
   hasTestTag(TestTag.SimpleScreen.Title)
}

But it’s not convenient and it would be great if BaseNode had this matcher by default for the parent node or allowed to change this behavior.

@AJIEKCX
Copy link
Author

AJIEKCX commented Apr 1, 2022

Also there is another problem with nested page objects. Because BaseNode inherits only direct parent node matchers but not all ancestors:

override val delegate: ComposeDelegate by lazy(LazyThreadSafetyMode.NONE) {
   ComposeDelegate(
       nodeProvider = NodeProvider(
           nodeMatcher = NodeMatcher(
               matcher = if (parentNode == null) nodeMatcher.matcher else hasParent(parentNode.nodeMatcher.matcher) and nodeMatcher.matcher,
               position = nodeMatcher.position,
               useUnmergedTree = nodeMatcher.useUnmergedTree
           ),
           semanticsProvider = semanticsProvider
       ),
       parentDelegate = parentNode?.delegate
   )
}

And it can be a problem for some cases. I think we should combine matchers from all ancestor nodes.

@AJIEKCX
Copy link
Author

AJIEKCX commented Apr 5, 2022

I will try to work on this issue

@AJIEKCX
Copy link
Author

AJIEKCX commented Apr 5, 2022

I've done it in #28

@AJIEKCX AJIEKCX closed this as completed Jul 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant