react-native-app-intro-slider icon indicating copy to clipboard operation
react-native-app-intro-slider copied to clipboard

Allow setting testID attributes

Open merunga opened this issue 6 years ago • 4 comments

Hi @Jacse , I'm testing my app with detox, and in order to get my tests working I have to select the next, prev, skip and done buttons by text, but it gets a little too much work when working with many languages, or when the designer decides to change the default labels.

I think that it could be possible to add attributes like skipButtonTestID, doneButtonTestID, prevButtonTestID and so on, in order to accomplish this. What do you think? Would you be interested in getting a PR for that?

merunga avatar Jul 27 '18 20:07 merunga

Do you mean adding those extra props so it's easier to test with Detox? I am not very fond of adding extra props that don't have any functional value.

Jacse avatar Jul 28 '18 19:07 Jacse

I think those props would have a functional value, as the docs say, they will be used to locate your component in end-to-end testing.

This isn't just a Detox requirement, any e2e testing tool, even native android and iOS ones, rely on this prop to be set. The issue here is that the prop has to be propagated to lower Views, otherwise would have no effect.

merunga avatar Jul 29 '18 16:07 merunga

Is this issue resolved? I also need to test with detox.

yestay90 avatar Sep 10 '19 05:09 yestay90

Hi guys,

I've just encountered the same issue and here's what I did to resolve it.

Taking advantage of the slides prop which is an array of objects we can add another obj prop inside of each object called testID for instance and use it on the renderItem method available.

{
    key: 'somethun',
    title: 'Title 1',
    text: 'Description.\nSay something cool',
    image: require('./assets/1.jpg'),
    backgroundColor: '#59b2ab',
    testID: 'somethun-1'
  },

Then we can read the testID (make sure testID reach the native element) on the renderItem method.

renderItem = item => <Text testID='item.testID'></Text>

On the detox test I had some synchronization issues and the way it work for me was manually disable it.

await device.disableSynchronization()
await waitFor(element(by.id('somethun-1')))
    .toBeVisible()
    .withTimeout(2000)
await element(by.id('somethun-1')).swipe('left')
await device.enableSynchronization();

I hope it helps. :)

ismaelocaramelo avatar Sep 25 '19 13:09 ismaelocaramelo