microsoft / react-native-windows

A framework for building native Windows apps with React.
https://microsoft.github.io/react-native-windows/
Other
16.25k stars 1.14k forks source link

testID doesn't work as expected in nested Text #3417

Open licanhua opened 4 years ago

licanhua commented 4 years ago

This is found when authoring E2E test case, <Text testID={MEASURE_IN_WINDOW_RESULT}> is set but finally the automationid is overwritten by its content, so E2E test case can't find MEASURE_IN_WINDOW_RESULT

export function DirectManipulationTestPage() {
    const [measureInWindowState, setMeasureInWindowState] = useState('');

    return (
        <View ref={viewRef} style={styles.container}>
            <Text style={styles.text}>MeasureInWindowResult:
                <Text testID={MEASURE_IN_WINDOW_RESULT}>
                    {measureInWindowState}
                </Text>
            </Text>
            <Button title='Call MeasureInWindow'
                onPress={() => {
                    viewRef.current && viewRef.current.measureInWindow((x, y, width, height) => {
                        setMeasureInWindowState(`x=${x};y=${y};width=${width};height=${height}`);
                    })
                }}
                testID={MEASURE_IN_WINDOW_BUTTON} />

        </View >);
}
chrisglein commented 4 years ago

This seems like it needs support on Run or some other XAML internal to get this to work. As is we can't add automation to Run (which nested Text uses). Tagging this as "needs WinUI 3" unless we have a near term clever workaround.

rectified95 commented 4 years ago

Unfortunately, fixing onPress for nested Text in #3373 doesn't make this go away in any way. Until the XAML Run component supports automation, this cannot really be done. I've noticed that the specific problem instance referenced in the issue description has been worked around by removing the nestedness; however, the issue still occurs, if the Text tags are rearranged. FYI @chrisglein

chrisglein commented 4 years ago

Yep, it was suspected we'd need WinUI3 fixes to enable this. We'll handle when we can do that.