【问题标题】:Assert that node exists containing text from two child nodes in Jetpack Compose断言该节点存在,包含来自 Jetpack Compose 中两个子节点的文本
【发布时间】:2022-10-19 04:55:56
【问题描述】:

我有一个 lazyColumn() 组合,列表中的每个项目都包含两个文本视图元素。一项具有文本元素 FooBar

撰写语义树已将这两个文本合并到父节点中,因此composeRule.onRoot().printToLog() 输出Text = '[Foo, Bar]'

如何断言一个节点同时存在文本元素FooBar

我已经尝试了以下但得到could not find any node that satisfies: ((Text + EditableText contains 'Foo' (ignoreCase: false)) && (Text + EditableText contains 'Bar' (ignoreCase: false))

composeRule.onNode(hasText("Foo") and hasText("Bar"), useUnmergedTree = true).assertExists()

【问题讨论】:

    标签: android android-jetpack-compose


    【解决方案1】:

    我想也许你只需要将and 更改为or

    【讨论】:

    • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
    【解决方案2】:

    问题是您正在谈论合并树中的节点,然后使用未合并树搜索节点。删除unmergedTree = true

    composeRule.onNode(hasText("Foo") and hasText("Bar")).assertExists()
    

    要查看合并和未合并之间的区别,您可以使用 composeRule.onRoot(useUnmergedTree = true/false).printToLog()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-09
      • 2021-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-24
      相关资源
      最近更新 更多