Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public void clickAndHold(final UIElement element, final long millis) {
* @param element the target element to perform the action on.
*/
public void hoverOverElement(final UIElement element) {
Dimension size = element.getUnderlyingWebElement().getSize();
Dimension size = element.getLazyWebElement().getSize();
mouseMove(element, size.getWidth() / 2, size.getHeight() / 2);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public static <E extends UIElement> Function<E, Boolean> textEquals(final @NonNu
withNoWait(
uiElement,
element -> {
String textValue = element.getUnderlyingWebElement().getText();
String textValue = element.getLazyWebElement().getText();
return textValue != null && textValue.equals(text);
});
}
Expand All @@ -215,7 +215,7 @@ public static <E extends UIElement> Function<E, Boolean> textContains(
withNoWait(
uiElement,
element -> {
String textValue = element.getUnderlyingWebElement().getText();
String textValue = element.getLazyWebElement().getText();
return textValue != null && textValue.contains(substring);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,16 @@ public LazyWebElement getParent() {
return this.underlying.getParent();
}

@Override
public LazyWebElement getLazyWebElement() {
if (this.underlying == null) {
throw new UnsupportedOperationException(
"Cannot get underlying element for component [%s] with no underlying element"
.formatted(this.getClass().getSimpleName()));
}
return this.underlying;
}

@Override
public WebElement getUnderlyingWebElement() {
if (this.underlying == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ public Locator getLocator() {
return this.underlying.getLocator();
}

@Override
public LazyWebElement getLazyWebElement() {
return this.underlying;
}

@Override
public WebElement getUnderlyingWebElement() {
return this.underlying.getUnderlyingWebElement();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.applause.auto.data.enums.SwipeDirection;
import com.applause.auto.pageobjectmodel.elements.ContainerElement;
import com.applause.auto.pageobjectmodel.factory.LazyWebElement;
import com.applause.auto.pageobjectmodel.factory.Locator;
import java.util.List;
import org.openqa.selenium.By;
Expand All @@ -32,6 +33,7 @@
*/
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
public interface UIElement extends Locatable {

/**
* Gets a child UIElement of this UIElement. This can be either a subclass of BaseElement or
* BaseComponent.
Expand Down Expand Up @@ -208,7 +210,17 @@ default void swipeToElement(final SwipeDirection direction) {
String getAttribute(String attribute);

/**
* Gets the underlying web element
* Gets the underlying LazyWebElement
*
* @return The underlying LazyWebElement
*/
LazyWebElement getLazyWebElement();

/**
* Gets the underlying web element. This is the actual selenium WebElement object that is being
* wrapped by the Applause Library. This is useful for when you need to interact with the
* WebElement directly. In most cases, you should consider using the getLazyWebElement() method
* instead, as the LazyWebElement can handle lazy loading and StaleElementRefereceExceptions.
*
* @return The underlying WebElement
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ public void setWait(final Duration theTimeout, final Duration thePollingInterval
this.pollingInterval = thePollingInterval;
}

@Override
public LazyWebElement getLazyWebElement() {
return this;
}

@Override
public WebElement getUnderlyingWebElement() {
return runLazily(() -> underlying);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,7 @@ public WebElement findElementInChain() {
// If we have a parent
var parent = this.chain.isEmpty() ? null : this.chain.getLast();
if (parent != null) {
if (!parent.isInitialized()) {
parent.initialize();
}
var searchContext =
parent.getLocator().isShadowRoot()
? parent.getShadowRoot()
: parent.getUnderlyingWebElement();
var searchContext = parent.getLocator().isShadowRoot() ? parent.getShadowRoot() : parent;
return this.findElementInContext(
searchContext, this.underlying.getLocator(), this.underlying.getFormatArgs());
}
Expand All @@ -143,13 +137,7 @@ public List<WebElement> findElementsInChain() {
// If we have a parent
var parent = this.chain.isEmpty() ? null : this.chain.getLast();
if (parent != null) {
if (!parent.isInitialized()) {
parent.initialize();
}
var searchContext =
parent.getLocator().isShadowRoot()
? parent.getShadowRoot()
: parent.getUnderlyingWebElement();
var searchContext = parent.getLocator().isShadowRoot() ? parent.getShadowRoot() : parent;
return this.findElementsInContext(
searchContext, this.underlying.getLocator(), this.underlying.getFormatArgs());
}
Expand Down