【问题标题】:Find element by ID testing with detox - React Native使用 detox 通过 ID 测试查找元素 - React Native
【发布时间】:2021-02-18 04:40:24
【问题描述】:

我正在尝试测试特定 ID 是否具有某些属性,但我没有成功找到它。相反,它会找到许多其他具有相同属性的 id,这告诉我它没有停止在我正在引导测试停止的 ID 中。 另外,我找不到明确的排毒测试指南

```it("is expected to have elements identifiable by testID", async () => {
await expect(element(by.id("assignment-36"))).toBeVisible();
await expect(element(by.label("Build a Web page"))).toBeVisible();
await expect(element(by.label("Points: 320"))).toBeVisible();````

但我得到的错误是:


    Test Failed: Multiple elements found for “MATCHER(label == “Points: 320”)”
    TIP: To print view hierarchy on failed actions/matches, use log-level verbose or higher.```

【问题讨论】:

    标签: react-native testing e2e-testing detox


    【解决方案1】:

    从错误消息中可以看出,您有多个元素可见,标签为Points: 320,因此您需要在测试中更具体地确定您希望哪个元素可见。

    最好的方法是将 testID 分配给元素以唯一标识它们 https://reactnative.dev/docs/view 或者您可以使用 atIndex 选择元素的第 n 次出现 - https://github.com/wix/Detox/blob/master/docs/APIRef.Matchers.md#atindexindex

    【讨论】:

      猜你喜欢
      • 2020-02-14
      • 1970-01-01
      • 2020-09-30
      • 1970-01-01
      • 2021-01-07
      • 1970-01-01
      • 2019-07-15
      • 2018-05-12
      • 2017-09-07
      相关资源
      最近更新 更多