Mauro Avellaneda
Mauro Avellaneda

Reputation: 93

Find element by ID testing with detox - React Native

I am trying to test that an specific ID has certain attributes but I haven’t succeeded finding it. Instead, it finds many others id with the same attributes which tells me that its not stopping in the ID I am leading the test to stop. Also, I couldn’t find a guide for testing with detox that is clear for to start with it

```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();````

But the error that I get is:


    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.```

Upvotes: 0

Views: 5404

Answers (1)

tgransden
tgransden

Reputation: 21

It looks from the error message like you have multiple elements visible with a label of Points: 320 so you will need to be more specific in your tests about which one you expect to be visible.

The best way is to assign testIDs to elements to uniquely identify them https://reactnative.dev/docs/view or you can use atIndex to choose the n'th occurence of the element - https://github.com/wix/Detox/blob/master/docs/APIRef.Matchers.md#atindexindex

Upvotes: 2

Related Questions