-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Button text matching fails on Android due to default all-caps styling #1135
Comments
Yes, but, why not use id matchers? |
An |
This is why matching by text is a terrible that should be discouraged. Case-insensitive search might introduce the opposite, where a "DEFAULT" button and "default" text field are both matched incorrectly. I don't think this should be pushed. Whoever is using text-based matching should do the work themselves to support this behavior, or move to a proper way to match their views. |
In my case it is awesome when i am using app string dynamically to identify a button or label rather than hardcoing them in automation scripts |
@LeoNatan they will not be matched incorrectly, but correctly. On Android all permutations of the casing of the word "default" are the same, because what end up on the screen is "DEFAULT". |
I mean other elements. Not all elements are caps. If you have a label with "default" and a button with "DEFAULT", you would hit both views. |
The plan is to apply this logic only to button objects, where the all-caps styling is enabled. |
If you query a button object for its text in code, does it return the caps string or the original string? |
I suppose that if it had returned the original string out of the box we wouldn't be dealing with this issue right now. |
So why not write a custom matcher that checks the original string? |
The original string doesn't exist anywhere in the view object IIRC. |
I'm willing to give it a shot. If it takes more than 1 hour, drop it. |
After putting in some effort into solving this, here are the conclusions:
All in all, this makes it really hard for the custom matcher to distinguish plaintext views from "button" views. The only lead here is the accessibility roles/traits that are inherently set to "button" on the JS side. It is likely that this info is somehow propagated to the native side, but its not trivial to find out how and thus it is not a <1hr task. (tl;dr Won't fix) |
Jesus, so they hardcode the uppercase string in Android. This is why RN is terrible. 🤦♂️ |
Yes. It's VERY unfortunate. |
Description
Starting SDK v21 (Material Design), by default, text set in native
Button
views appear all-caps. This is according to the guidelines, so RN doesn't provide an API to override that, and - as a matter of fact, it isn't easy to override that in native Android as well.Therefore, looking up a button element by text using Detox API typically fails on Android while it works on iOS, since the provided text typically isn't all-caps.
Steps to Reproduce
Create a single-screen app with a single button with the text 'tap me'.
The following test code will fail:
Device and verbose Detox logs
Typically error saying the element doesn't exist in the hierarchy.
The text was updated successfully, but these errors were encountered: