使用 react native 进行 UI 测试。如何修复时间戳事件匹配错误:找不到匹配元素

Mar*_*tek 6 xcode ios react-native xcuitest

我正在尝试将 UI 测试集成到一个相当大的 React Native 项目中。但是一旦我想记录 ui 测试,我就会收到警告

Timestamped Event Matching Error: Failed to find matching element

这是我正在点击的 ui 元素。

<TouchableOpacity style={containerStyle}
                  onPress={this.props.onPress}
                  accessibilityLabel='back_button_touchable'
                  accessible={true}
                  testID='back_button_touchable'
                  underlayColor='#99d9f4'>
                <Image style={iconStyle} source={require('../white-arrow.png')}/>
                <Text style={styles.text}>{this.props.text}</Text>
</TouchableOpacity>
Run Code Online (Sandbox Code Playgroud)

我刚刚建立了一个新的 React Native 项目,并试图让 ui 测试运行,这很好。所以这让我想到了一个问题,即现有代码/构建设置以某种方式阻止了元素检索。

有什么想法可以禁用或阻止 ui 测试?

Les*_*Les 8

对于其他正在为此寻找答案的人 - 我发现 RN 中的 Touchable 元素在 UI 测试方面存在问题。

如果您在 Touchable 上设置了 access={false},那么 testID 在录制时会作用于子 Text & View 元素。

<TouchableOpacity onPress={onPressFn} accessible={false}>
  <View style={styles.buttonContainer} testID="button">
    <Text style={styles.buttonText}>
      {children}
    </Text>
  </View>
</TouchableOpacity>
Run Code Online (Sandbox Code Playgroud)