vendredi 6 septembre 2019

SafeAreaView doesn't let Appium find accessibility ID of children Views on React Native

I am working on some end-to-end tests for a React Native (version 0.60) application which are run via Appium.

I have a couple of buttons which are wrapped around a SafeAreaView to avoid problems with the latest iOS devices (e.g. iPhone X, iPad Pro, etc...). This is the key part of the Component render() function:

const Buttons = (
    <StickyContainer visible={isSizeSelected} width={width} style={containerStyle}>
        {showAddToWishlist && (
            <Button
                outline
                fixedWidth
                uppercase
                tx="product.addToWishlist"
                onPress={() => this.onPressAddTo(ProductAction.AddToWishlist)}
                icon="heartBlack"
                margin={margin}
                showSpinner={isAddingToWishlist}
            />
        )}
        {showAddToShoppingBag && (
            <Button
                primary
                fixedWidth
                uppercase
                tx="product.addToCart"
                onPress={() => this.onPressAddTo(ProductAction.AddToShoppingBag)}
                showSpinner={isAddingToShoppingBag}
                {...setTestId("sizeOverlayAddToCartButton")}
            />
        )}
    </StickyContainer>
)

return <SafeAreaView forceInset=>{Buttons}</SafeAreaView>

As you can see, the accessibility IDs are set through the setTestid() function which is doing nothing more than this:

const getPlatformTestId = (id: string) => {
    if (IS_IOS) {
        return {
            testID: id
        }
    }

    return {
        accessibilityLabel: id,
        accessible: true
    }
}

export const setTestId = (id: string) => {
    return getPlatformTestId(id)
}

Now the problem: if I run the app and I try to search on Appium for the ID sizeOverlayAddToCartButton I can't find anything. If I remove the <SafeAreaView> and I return directly Buttons the ID is found without any problem. It's also interesting that if I use the app Accessibility Inspector (it's part of Xcode) instead of Appium, the ID is always found no matter if I use the <SafeAreaView>.

Does someone know why this is not working? I can't find any compatibility issue online

Aucun commentaire:

Enregistrer un commentaire