darcy-framework/darcy-ui

Inconsistent behavior when finding elements

alechenninger opened this issue · 1 comments

There are various means of retrieving elements:

  1. Defining proxy elements as fields with the Elements factory methods, which get initialized in AbstractView#setContext(ElementContext)
  2. Retrieving via the ElementContext API (getContext().element().button(By))
  3. Retrieving via the Locator API (Locator#find(Class, Context))

Currently with the darcy-webdriver implementation, method 3 will throw an exception should the element not be found. The other methods will not. Method 2 behaved like method 3 until a recent commit. I believe now method 3 should behave like the others, so that all retrieved methods enjoy the same functionality of the Element API, which is that you may test for their presence without having to catch a NotFoundException (or equivalent).

However, the other methods ultimately relied on method 3 as a means of actually doing the work of finding the element. This is because methods 1 and 2 lazily load the element reference that method 3 retrieves. In order to fix this, we must push the lazy load functionality into implementations.

This has the happy side effect of reducing total code, and getting rid of the necessity of using dynamic proxies to lazily load elements.

Note: Element fields will still need proxies so that the Elements can be told of their owning ElementContext (since they are instances created statically, they must be told about their context by reflectively initializing them when the owning View's ElementContext is set or changed).