Reputation: 133
I am having a weird issue setting the testID together with the accessibilityLabel for my React Native application, the purpose of this is to have the "accessibility id" on iOS and Android app visible with Appium Inspector (Appium Desktop), the issue is the following:
here is the code that I have
export enum TestID {
ImageLogo = 'ImageLogo'
}
export const LogoComponent: React.FC = () => {
return (
<Image
testID={TestID.ImageLogo}
accessibilityLabel={TestID.ImageLogo}
/>
);
};
Also, I've tried to setup the accessible attribute to false/true without success The React Native version that I am using is the following:
"react": "16.13.1",
"react-native": "0.63.2",
Upvotes: 5
Views: 13762
Reputation: 644
I have faced the issue that the element and IDs do not appear in Appium.
the solution is using replace @react-navigation/stack to @react-navigation/native-stack
for more details: 1-https://github.com/appium/appium/issues/14825#issuecomment-1690850085
2-https://reactnavigation.org/docs/native-stack-navigator/
Upvotes: 0
Reputation: 94
This question was hard for me too. But the response is:
Use test:id/
in front of your ID, like this
And later, use that test:id/identifier
for select the element into the test.
Upvotes: 2
Reputation: 1348
Upgrade to React Native 0.64 - it has proper support for testID
on Android. Note that because testID
on Android maps to the resource-id
of the View, Appium requires your testIDs to be formatted in the canonical style for resource IDs: <package>:id/<identifier>
.
In our app, we do the following for our test IDs:
<Text testID="test:id/hello-text">Hello</Text>
If you're using the wd
library to talk to appium, you can then do:
await driver.elementById("test:id/hello-text")
Upvotes: 9
Reputation: 59
Try using the below testID for your components:
export default function testID(id) {
return Platform.OS === 'android'
? { accessible: true, accessibilityLabel: id }
: { testID: id }
}
<Text {...testID('hello-text')} >hello world</Text>
Upvotes: 5