Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add accessibilityLabel to OtpInput for Improved Cross-Platform Testability #70

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

JulienLeal
Copy link

@JulienLeal JulienLeal commented Sep 18, 2024

This pull request adds an accessibilityLabel prop to the Pressable component within the OtpInput component. The change is minimal but significantly enhances the testability of the component across both Android and iOS platforms when using automated testing tools like Appium.

Changes Made:

  1. Added accessibilityLabel="otp-input" to the Pressable component in OtpInput.tsx.

Reason for Change:
While using Appium for end-to-end testing, I encountered difficulties locating the OtpInput element on Android devices, especially on platforms like BrowserStack. The testID prop maps to resource-id on Android, which can cause inconsistencies due to varying package names across environments.

By adding the accessibilityLabel prop:

  • On Android, it sets the content-desc attribute, allowing the element to be located using the accessibility id locator strategy in Appium.

  • On iOS, it maps to accessibilityIdentifier, which is also accessible via the accessibility id strategy.

Issue Observed:

  • On local emulators, tests work correctly because the environment is consistent.
  • On BrowserStack's real devices, tests fail to locate the OtpInput element due to variations in device configurations and package names, causing resource-id based locators to fail.

@JulienLeal JulienLeal changed the title feat: add accessibilityLabel otp-input Add accessibilityLabel to OtpInput for Improved Cross-Platform Testability Sep 18, 2024
@JulienLeal
Copy link
Author

@anday013 bump

@anday013
Copy link
Owner

Hi @JulienLeal . I appreciate your contribution; however, it's a misuse of accessibility props, as they are not meant for this. So, we need to come up either with a proper value for accessibilityLabel or some workaround for test id, so you can access it on your E2E tests

@JulienLeal
Copy link
Author

JulienLeal commented Sep 22, 2024

Hi @anday013,

Thank you for your feedback. I understand that using accessibility props in this way isn't ideal.

However, React Native's mapping of testID can vary across different environments on real devices. I tried the workaround described here: https://dev.to/nextlevelbeard/an-end-to-the-abuse-of-accessibility-ids-5d2j, which worked on some Android devices but had inconsistent results across various Android versions.

Given this inconsistency, I chose to use accessibilityLabel as the locator strategy for e2E. Some reference: https://www.waldo.com/blog/appium-accessibility-id.

What do you think about passing accessibilityLabel as a parameter? This way, users can decide whether to use it and specify its value, instead of hardcoding "otp-input".

@anday013
Copy link
Owner

@JulienLeal Sorry for the late response. I'm a bit busy these days. Passing by props seems fine to me :)

@anday013
Copy link
Owner

anday013 commented Nov 1, 2024

@JulienLeal, should I close this PR or you're planning to implement it?

@JulienLeal
Copy link
Author

Hi @anday013. I was on vacation. I'll implement in this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants