Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 5 additions & 28 deletions src/main/java/aquality/selenium/elements/Element.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
import aquality.selenium.localization.LocalizationManager;
import aquality.selenium.logger.Logger;
import aquality.selenium.waitings.ConditionalWait;
import org.openqa.selenium.*;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.remote.RemoteWebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;

/**
* Abstract class, describing wrapper of WebElement.
Expand Down Expand Up @@ -79,17 +81,6 @@ public RemoteWebElement getElement(Long timeout) {
}
}

@Override
public boolean isEnabled(long timeout) {
return ConditionalWait.waitForTrue(y -> getElement().isEnabled()
&& !hasState(PopularClassNames.DISABLED), timeout);
}

@Override
public boolean isEnabled() {
return isEnabled(timeoutCondition);
}

@Override
public By getLocator() {
return locator;
Expand Down Expand Up @@ -122,20 +113,11 @@ public void sendKeys(Keys key) {

@Override
public void waitAndClick() {
waitForElementClickable();
waitForEnabled(getDefaultTimeout());
info(getLocManager().getValue(LOG_CLICKING));
click();
}

@Override
public void waitForElementClickable() {
waitForElementClickable(timeoutCondition);
}

@Override
public void waitForElementClickable(Long timeout) {
ConditionalWait.waitFor(ExpectedConditions.elementToBeClickable(getLocator()), timeout);
}

@Override
public void click() {
Expand Down Expand Up @@ -278,11 +260,6 @@ public MouseActions getMouseActions() {
return new MouseActions(this, getElementType(), getName());
}

@Override
public boolean hasState(String className) {
return getAttribute(Attributes.CLASS.toString()).toLowerCase().contains(className.toLowerCase());
}

@Override
public <T extends IElement> T findChildElement(By childLoc, ElementType type, ElementState state) {
return new ElementFactory().findChildElement(this, childLoc, type, state);
Expand Down
39 changes: 31 additions & 8 deletions src/main/java/aquality/selenium/elements/ElementStateProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,53 @@ public boolean isDisplayed() {
}

@Override
public boolean isExist() {
return waitForExist(ZERO_TIMEOUT);
public boolean waitForDisplayed(long timeout) {
return !findElements(timeout, ElementState.DISPLAYED).isEmpty();
}

@Override
public boolean waitForDisplayed(long timeout) {
return !findElements(timeout, ElementState.DISPLAYED).isEmpty();
public boolean waitForNotDisplayed(long timeout) {
return ConditionalWait.waitForTrue(driver -> !isDisplayed(), timeout);
}

@Override
public boolean waitForExist(long timeout) {
return !findElements(timeout, ElementState.EXISTS_IN_ANY_STATE).isEmpty();
public boolean isExist() {
return waitForExist(ZERO_TIMEOUT);
}

@Override
public boolean waitForNotDisplayed(long timeout) {
return ConditionalWait.waitForTrue(driver -> !isDisplayed(), timeout);
public boolean waitForExist(long timeout) {
return !findElements(timeout, ElementState.EXISTS_IN_ANY_STATE).isEmpty();
}

@Override
public boolean waitForNotExist(long timeout) {
return ConditionalWait.waitForTrue(driver -> !isExist(), timeout);
}


@Override
public boolean isEnabled() {
return waitForEnabled(ZERO_TIMEOUT);
}

@Override
public boolean waitForEnabled(long timeout) {
return ConditionalWait.waitForTrue(y -> {
List<WebElement> webElements = findElements(timeout, ElementState.EXISTS_IN_ANY_STATE);
if(!webElements.isEmpty()){
WebElement webElement = webElements.get(0);
return webElement.isEnabled() && !webElement.getAttribute(Attributes.CLASS.toString()).contains(PopularClassNames.DISABLED);
}
return false;
}, timeout);
}

@Override
public boolean waitForNotEnabled(long timeout) {
return ConditionalWait.waitForTrue(driver -> !isEnabled(), timeout);
}

private List<WebElement> findElements(long timeout, ElementState state) {
return ElementFinder.getInstance().findElements(getLocator(), timeout, state);
}
Expand Down
26 changes: 0 additions & 26 deletions src/main/java/aquality/selenium/elements/interfaces/IElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,6 @@ public interface IElement extends IParent, IElementWithState {
*/
RemoteWebElement getElement(Long timeout);

/**
* Check that the element is enabled (performed by a class member)
*
* @param timeout Timeout for waiting
* @return true if enabled
*/
boolean isEnabled(long timeout);

/**
* Check that the element is enabled (performed by a class member)
*
* @return true if enabled
*/
boolean isEnabled();

/**
* Get element locator
*
Expand Down Expand Up @@ -69,17 +54,6 @@ public interface IElement extends IParent, IElementWithState {
*/
void waitAndClick();

/**
* Wait until element is clickable.
*/
void waitForElementClickable();

/**
* Wait until element is clickable.
* @param timeout Timeout for waiting
*/
void waitForElementClickable(Long timeout);

/**
* Click on the item.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,24 @@ public interface IElementStateProvider {
boolean isDisplayed();

/**
* Is an element exist in DOM (without visibility check)
* @return true if element exist, false otherwise
* Waits for is element displayed on the page.
* @param timeout Timeout for waiting
* @return true if element displayed after waiting, false otherwise
*/
boolean isExist();
boolean waitForDisplayed(long timeout);

/**
* Waits for is element displayed on the page.
* @param timeout Timeout for waiting
* @return true if element displayed after waiting, false otherwise
*/
boolean waitForDisplayed(long timeout);
boolean waitForNotDisplayed(long timeout);

/**
* Is an element exist in DOM (without visibility check)
* @return true if element exist, false otherwise
*/
boolean isExist();

/**
* Waits until element is exist in DOM (without visibility check).
Expand All @@ -33,16 +40,31 @@ public interface IElementStateProvider {
boolean waitForExist(long timeout);

/**
* Waits for is element displayed on the page.
* Waits until element does not exist in DOM (without visibility check).
*
* @return true if element does not exist after waiting, false otherwise
*/
boolean waitForNotExist(long timeout);

/**
* Check that the element is enabled (performed by a class member)
*
* @return true if enabled
*/
boolean isEnabled();

/**
* Check that the element is enabled (performed by a class member)
*
* @param timeout Timeout for waiting
* @return true if element displayed after waiting, false otherwise
* @return true if enabled
*/
boolean waitForNotDisplayed(long timeout);
boolean waitForEnabled(long timeout);

/**
* Waits until element does not exist in DOM (without visibility check).
* Waits until element does not enabled in DOM
*
* @return true if element does not exist after waiting, false otherwise
* @return true if element does not enabled after waiting, false otherwise
*/
boolean waitForNotExist(long timeout);
boolean waitForNotEnabled(long timeout);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public interface IElementWithState extends IElementStateProvider {
/**
* Provides ability to define of element's state (whether it is displayed, exist or not) and respective waiting functions
* Provides ability to define of element's state (whether it is displayed, exists or not) and respective waiting functions
* @return provider to define element's state
*/
IElementStateProvider state();
Expand All @@ -20,10 +20,6 @@ default boolean isDisplayed() {
return state().isDisplayed();
}

default boolean isExist() {
return state().isExist();
}

default boolean waitForDisplayed(long timeout) {
return state().waitForDisplayed(timeout);
}
Expand All @@ -40,6 +36,11 @@ default boolean waitForNotDisplayed() {
return waitForNotDisplayed(getDefaultTimeout());
}


default boolean isExist() {
return state().isExist();
}

default boolean waitForExist(long timeout) {
return state().waitForExist(timeout);
}
Expand All @@ -56,10 +57,24 @@ default boolean waitForNotExist() {
return waitForNotExist(getDefaultTimeout());
}

/**
* Checks element's class attribute to contain specified className
* @param className ClassName parameter
* @return true if required className contained in class attribute, false otherwise
*/
boolean hasState(String className);

default boolean isEnabled() {
return state().isEnabled();
}

default boolean waitForEnabled(long timeout) {
return state().waitForEnabled(timeout);
}

default boolean waitForEnabled() {
return waitForEnabled(getDefaultTimeout());
}

default boolean waitForNotEnabled(long timeout) {
return state().waitForNotEnabled(timeout);
}

default boolean waitForNotEnabled() {
return waitForNotEnabled(getDefaultTimeout());
}
}
4 changes: 4 additions & 0 deletions src/test/java/tests/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ protected void beforeMethod() {
public void afterTest(){
BrowserManager.getBrowser().quit();
}

protected void navigate(TheInternetPage page) {
BrowserManager.getBrowser().navigate().to(page.getAddress());
}
}
Loading