7

我正在尝试将 UI 测试集成到一个相当大的反应原生项目中。但是只要我想记录 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>

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

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

4

1 回答 1

9

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

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

<TouchableOpacity onPress={onPressFn} accessible={false}>
  <View style={styles.buttonContainer} testID="button">
    <Text style={styles.buttonText}>
      {children}
    </Text>
  </View>
</TouchableOpacity>
于 2018-09-18T12:32:31.717 回答