Test flow with Appium POM

Hi all. I use the page object model when writing my tests…
I have a couple of questions regarding writing the code with POM and what are the best ways to implement different scenarios. I am using java client.
if you can answer even one of them it will be great! thanks ahead for investing the time into reading this post.

When running tests with POM we use proxies, few questions regarding:

  1. When looking on appium’s logs I can see some actions which uses a referenced element.
    lets assume I have the following scenario(which is real):
    there is a screen with a toolbar and inside the toolbar there is a button.
    I have an instance named ‘screen’ (the page object), inside it a toolbar element (extends Widget class) and inside it a WebElement called button. (double nesting).
    How does the following action execute?
    WebElement myButton = screen.getBar().getButton(); //locating the toolbar and then the button.

    on the second line:

  • is myButton holding a referenced WebElement or it will look for it again?
  • when looking for it on the second row, is it looking just for the button locator and assuming the ‘bar’ ‘elementId’ is the same as before or the proxy is locating the whole ‘chain’ from scratch? (the toolbar element and the button element)
  1. I want to have an indication for knowing when I switched to a new screen; to achieve it I can either wait for a unique element on the ‘new’ screen or wait for an element from the ‘first’ screen to be stale.
    of corse that I can use the first option but some times I have the same pages or maybe different but with similar locators. so sometimes I want to use the latter.
    now, the problem, when using page object we are actually using proxies which wraps the Widget or WebElement we are using.
    in order to wait for an element to be stale I either need to locate it using ‘By’ instance instead of annotations or unwrap the WebElement from the proxy.
    when using ‘Widget’ element it is easy because we just call ‘widget.getWrappedElement()’ which comes from a selenium interface(WrapsElement).
    but, the case is harder to solve when trying to unwrap a WebElement proxy.
    I looked on the java client code and saw that when the proxy is being created it implements ‘WrapsElemet’ interface, the same as Widget; so, I tried to use casting and even use some static Proxy methods to unwrap the element but without any success. is there anyone who knows how to implement such a thing? I did not find any question regarding. I want to use selenium’s ’ stalenessOf​(WebElement element)’ expected condition.

  2. is there any useful way to handle a page that is constantly being rendered with new data or even just one time refresh, how can i know if it already was refreshed or not? I can wrap each command with try catch to allow stale element exception but is there any ‘nicer’ way?

Thanks for everyone!