It takes 5-6 seconds to find some UI control (as example a button).
Two questions:
1) Why is it so slow?
2) Is there a way to make it faster or some alternative solution for finding UI control (in scope of monkeyrunner testing)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I looked into Android source code a little bit and found that when you search for a control using findViewById in monkeyrunner, it actually iterates through all controls on all running windows in Android.
So, if you have some Activity which is paused (and not visible), by not destroyed, findViewById will spend time searching through it.
I have several ideas for now
a) Use getFocusedWindowName API on HierarhyViewer to check that correct window is displayed.
Try to search this window first and after specify it as parent in findViewById(id, parent) method. This way, we won’t search through all windows on Android.
2) Try to bypass interface provided by com.android.chimpchat.hierarchyviewer.HierarchyViewer and go directly to DeviceBridge class (which provides a little bit lower level for the same protocol). In such case, instead of acquiring all controls for all windows, we can precisely point which window should be searched.
As Romain pointed out. HierarchyViewer may change in the future. However, I don’t see any other replacement for this, as part of testing automation.