-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
API to get available view properties #445
Comments
This can be a cool feature, and as you said, will greatly expand the use cases covered by Detox. |
@rotemmiz Thanks for the answer. Could you point here some directions for any interested contributor? E.g. which files they would probably touch or existing methods they would probably use. |
Both will have to be implemented natively in Detox as Matchers, in here (iOS) and here (Android) Once these are are done, the code generator should be able to pick this up and and generate the JS API. |
Matching “props” to actual native properties is the hardest here. Starting with “simple” stuff like text should be easier. I say “simple” because that too can blow up in complexity—labels, text fields, text views, custom views, etc. |
Yep, props are not really necessary initially, just a plus for the future. |
do you know guys know when these can be done |
@saitejareddy07 we need someone to volunteer to work on it. |
I agree with you wix team has to consider this issues, Detox is completely uni-directional, it's not bi-directional |
Hello, Unfortunately we have not looked at implementing this yet. PRs are welcome. |
This would be perfect as its something that would help with tests being less flaky.*
|
Hi guys anyone have worked on this |
Looks like no one as of now. |
This would be a great feature - reading text from the screen to assert that correct values are displayed or just read the state... |
This is a workaround we use to get text from the element
|
@Kamahl19 nice hack, worked for me! |
@Kamahl19 Thats a really nice hack! Who would say that the error message contains the actual value, lol. Is the |
@MiroslavPetrik I am not sure 100% |
I do not know why the authors do not want to support In case you are really in need of getting text in test, this is an example of how I do it. You can get not just text but also potentially get width/height/X,Y coordinate/ parent views or anything in test. Basically you add return values in a bunch of async functions. My commit only works on Android since that's all what I need. I hope implementing on iOS should not be too difficult 😄 |
Any news with that? |
@Kamahl19 This doesn't work for me on Android, didn't try on iOS yet. Does it work for you in the current detox version? |
Hi @ronilitman We are using below code to fetch text export default readVisibleText; |
I took the initiative to edit above. This works with 12.7.0, at least for ios.
|
until wix/Detox#445 is handled
until wix/Detox#445 is handled
As mentioned elsewhere, we are working on an overhaul of how Detox works. This will become impossible once we move to that system (no direct access to the controls). |
@LeoNatan Can you elaborate on the overhaul (is it documented somewhere)? Will it become impossible to fetch a piece of text from the screen? We have many use cases where we need to read a number from the screen and verify that it's within a specific range. If this will become impossible in Detox, we'll need to move to a different E2E testing framework. We'd prefer to do the change before we put a lot of time in writing tests using Detox. |
There is no documentation. We will be using Apple's UI testing framework internally, which runs in a different process than the tested app. We will only have access to the following view properties: Those properties can be exposed to the user facing JS API somehow. However, we will not have direct access to the view object, and thus we will not be able to fetch any React information. If you are inspecting the text information, that is accessible using the |
The workaround presented in this issue dumps the UI tree and manually parses out the label. It looks like after the overhaul it will become easier rather than impossible since there is an official API that exposes the |
@LeoNatan How will Android be supported? |
@cs01 Yes, as long as it is one of the supported properties posted above, it will be possible to transfer them from native to JS. However, this requires that React Native support platform standard conventions, which sometimes they don't. For instance, a custom view cannot implement This was my initial reluctance to support a system as requested in this issue. Coupled with many people's lack of understanding that Detox runs in native exclusively, and that native views are not React views, and their props don't magically show up in native—I fear will introduce a lot of confusion. @plaa No plans to make extensive changes currently. |
In our tests, we very often need to get the value of an element and assert on it. We have adopted the workaround described in this issue for now, and it has been working nicely for us. This issue title is regarding getting props or visible text. Agreed that props is not possible since there are transformations done between the React Native code and Native code, but the visible text is available at the native layer. The UI tree used in this workaround is the Native tree, not the original React Component tree, and it seems to be useful for many others besides us. I hope there is some way we could get an official Detox API for this, and at the same time set expectations that only the Native values, not the original React code or props, will be accessible by Detox. |
Right, but unfortunately, title/label are not always enough. As I mentioned above, control values are not accessible for some RN cases, where people would expect them to be. But since we are designing a new internal API around this, we will think how to perhaps expose these properties. Perhaps it can be a second step, such as |
OK, let's keep open. |
What's the status on this? I'm interested on this. |
@LeoNatan There is some update on this? Would be very useful for my team |
We may have an update on this soon. |
Good news, this was recently implemented, and will soon find its way into a release. For now, see the API here: Thanks |
@LeoNatan Any solution for Android? We're currently running our tests only on Android, so this doesn't help us at all. 😞 The attributes are platform-dependent, but I'd suggest harmonizing some field e.g. |
Android will be implemented in the future. No timeline currently. I’m sure we’ll keep the attribute keys as similar as possible. |
I created #2083 so that it's possible for people to track when support on Android is implemented. Until then, will have to continue using detox-getprops. |
@LeoNatan on iOS with detox 16.8.2, I am getting: when running according to your doc link above: while: |
@oguennec It’s not deployed yet. Check out the pull request to follow the progress. |
Feature request
Allow get the current visible text or maybe any props from a matched element.
Use case
I'm using detox to run automated benchmarks for my repo react-native-css-in-js-benchmarks. I'm able to make detox tap on things to run the benchmark, but I see no way to pass the benchmark results from the app to detox.
So a way to get the printed result OR a method to pass data to detox would be great to expand detox use cases. Any thoughts about this?
Similar stack overflow question that I found: https://stackoverflow.com/questions/47351745/how-to-get-the-text-from-a-matched-view-using-detox
The text was updated successfully, but these errors were encountered: