Should "LazyElement" concept be removed?
Closed this issue · 1 comments
alechenninger commented
This would mean moving all of the element subtype factories back into AbstractView
. The advantage is that there is no longer need to lazily initialize the elements. However, the ElementInvocationHandler would have to accept a View instead of an ElementContext directly. (Or a Supplier...)
alechenninger commented
Removing this does impact custom elements. Right now, a custom element can add it's own static factory method that looks just like any other element ... something like:
public class MyView extends AbstractView {
private CustomElement customElement = customElement(By.id("id"));
}
// CustomElementImpl.java
public class CustomElementImpl extends AbstractView implements CustomElement {
public static CustomElement customElement(Locator locator) {
return Elements.element(CustomElement.class, locator, new CustomElementImpl());
}
// snip
... and it will still get initialized on setContext.
Alternatively, something like this might work:
public class MyView extends AbstractView {
private CustomElement customElement = element(By.id("id"), customElement());
}
// CustomElement.java
public interface CustomElement extends Element {
public static ElementDescription<CustomElement> customElement() {
return new ElementDescription<>(CustomElement.class, CustomElementImpl::new);
}
Given that...
- This is uglier for custom elements even if you get creative
- You still need proxies because context is null at instantiation
- Changing this would completely break everyone's page objects
I'm thinking no.