0

I am using Detox for E2E testing on a React Native app using the following specs:

React Native 0.55.4 Node 9.2.0 Detox 7.3.7

When I am on a page within my app I can scroll using the scrollView with the Matcher element(by.id('scrollView')) and I can click a button with the Matcher element(by.text('This Button')) but if I want to select the button element using chaining with the .and() method I get an error Cannot find UI element.

I cannot figure out why I can interact with these two elements independently, but when I link them they no longer work.

Here is a sanitized example of what the React Native code looks like:

Route.js

<ScrollView style={styles.container} testID={"scrollView"}>
 <View style={styles.header} />
   this.body()
</ScrollView>

this.body() does some validation but the render() is nothing special:

<View>
  <CustomButtonComponent />
</View>

The custom button component is another View with some Text and a Button element.

My only guess is that since I am using nested views/custom components maybe the Matcher logic cannot handle that. Any ideas? Maybe I don't understand the Documentation completely.

  • I tried getting `.and()` to work but I was unable to. Though both elements are visible when done separately. I was able to get it to work with `.withDescendent()`. That might suit your needs? – Andrew Jul 17 '18 at 17:36
  • Thanks for the help @Andrew, turns out I thought the `and()` method was for chaining elements but after going back over the documentation it looks like you are right. I am looking for something more like `withDescendant()` or `withAncestor()` – Kevin Lalka Jul 18 '18 at 13:39

1 Answers1

1

As @Andrew pointed out in his comment, my question is invalid because I misunderstood the documentation. If you want to Match based on a relationship to other elements use withDescendant() or withAncestor() instead of trying to chain with and().

  • I am glad that you managed to figure it out. I wasn't 100% sure if I was right so didn't want to put it as the answer. – Andrew Jul 18 '18 at 19:29