SafeAreaView 不允许 Appium 在 React Native 上找到子视图的可访问性 ID

toi*_*ski 6 testing android ios appium react-native

我正在为通过 Appium 运行的 React Native(0.60 版)应用程序进行一些端到端测试。

我有几个按钮环绕在 a 周围,SafeAreaView以避免最新的 iOS 设备(例如 iPhone X、iPad Pro 等)出现问题。这是组件render()功能的关键部分:

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={{ bottom: "never" }}>{Buttons}</SafeAreaView>
Run Code Online (Sandbox Code Playgroud)

如您所见,可访问性 ID 是通过setTestid()函数设置的,该函数仅执行以下操作:

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

    return {
        accessibilityLabel: id,
        accessible: true
    }
}

export const setTestId = (id: string) => {
    return getPlatformTestId(id)
}
Run Code Online (Sandbox Code Playgroud)

现在的问题是:如果我运行该应用程序并尝试在 Appium 上搜索 ID,sizeOverlayAddToCartButton我找不到任何东西。如果我删除<SafeAreaView>并直接返回Buttons,则发现 ID 没有任何问题。同样有趣的是,如果我使用应用程序辅助功能检查器(它是 Xcode 的一部分)而不是 Appium,无论我使用<SafeAreaView>.

有人知道为什么这不起作用吗?我在网上找不到任何兼容性问题