I have a problem during testing my app on Android.
I have my automation tests using UiAutomator and I have a strange behavior, in a test When a click on an element is triggered the UI in the emulator gets updated correctly, but if I download to check the hierarchy in an XML file, it shows the page in the previous state, so the test fails because I didn't find the new element.
I give an example, (sorry but I cannot post the original code)
I have a button that if it is pressed the content of a box will change, the test starts with a click on the button, in the emulator you can see that the content in the box has changed, but in the next step, where I try to check the new content, the test fails because in the box seems to be present the old content. I verified by downloading XML of the hierarchy, and it confirms to me that the old content is still present, even though the UI has changed. Has anyone ever had the same problem?
This is the code that I use to create a selector:
fun getSelector(id:String):BySelector{
return By.res(id)
}
That is the code to get element:
fun getElement(id:String): UiObject2 {
val selector=getSelector(id)
val device: UiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
return element= device.findObject(selector)
}
and after I just run
element.click()
As I wrote interface reacts to the click and the content of the element changes as expected but the following test fails because when I try to verify the new text in the element it always shows me the previous text :
before click:
element=getElement(id_box)
text=element.text
text is "before click"
Now a button will click and the interface changes and the text inside the element is "after click"
element =getElement(id_button)
element.click()
I try to wait 30 sec and after if I do
element=getElement(id_box)
new_text=element.text
new_text is still "before click" and not "after click" as it is in the UI.
I hope it is clear , any help or ideas are welcome