Inconsistent behavior when finding elements
alechenninger opened this issue · 1 comments
There are various means of retrieving elements:
- Defining proxy elements as fields with the
Elements
factory methods, which get initialized inAbstractView#setContext(ElementContext)
- Retrieving via the
ElementContext
API (getContext().element().button(By)
) - 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
Element
s can be told of their owningElementContext
(since they are instances created statically, they must be told about their context by reflectively initializing them when the owningView
'sElementContext
is set or changed).
Fixed by cef7d84