Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
barancev committed Apr 3, 2017
1 parent cdeebdf commit a4b3166
Showing 1 changed file with 30 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ public String toString() {
* @param locator used to find the element
* @return the WebElement once it is located
*/
public static ExpectedCondition<WebElement> presenceOfElementLocated(
final By locator) {
public static ExpectedCondition<WebElement> presenceOfElementLocated(final By locator) {
return new ExpectedCondition<WebElement>() {
@Override
public WebElement apply(WebDriver driver) {
Expand All @@ -199,8 +198,7 @@ public String toString() {
* @param locator used to find the element
* @return the WebElement once it is located and visible
*/
public static ExpectedCondition<WebElement> visibilityOfElementLocated(
final By locator) {
public static ExpectedCondition<WebElement> visibilityOfElementLocated(final By locator) {
return new ExpectedCondition<WebElement>() {
@Override
public WebElement apply(WebDriver driver) {
Expand Down Expand Up @@ -283,8 +281,7 @@ public String toString() {
* @param element the WebElement
* @return the (same) WebElement once it is visible
*/
public static ExpectedCondition<WebElement> visibilityOf(
final WebElement element) {
public static ExpectedCondition<WebElement> visibilityOf(final WebElement element) {
return new ExpectedCondition<WebElement>() {
@Override
public WebElement apply(WebDriver driver) {
Expand Down Expand Up @@ -334,8 +331,8 @@ public String toString() {
* @param text to be present in the element
* @return true once the element contains the given text
*/
public static ExpectedCondition<Boolean> textToBePresentInElement(
final WebElement element, final String text) {
public static ExpectedCondition<Boolean> textToBePresentInElement(final WebElement element,
final String text) {

return new ExpectedCondition<Boolean>() {
@Override
Expand Down Expand Up @@ -365,8 +362,8 @@ public String toString() {
* @deprecated Use {@link #textToBePresentInElementLocated(By, String)} instead
*/
@Deprecated
public static ExpectedCondition<Boolean> textToBePresentInElement(
final By locator, final String text) {
public static ExpectedCondition<Boolean> textToBePresentInElement(final By locator,
final String text) {
return textToBePresentInElementLocated(locator, text);
}

Expand All @@ -378,8 +375,8 @@ public static ExpectedCondition<Boolean> textToBePresentInElement(
* @param text to be present in the element found by the locator
* @return true once the first element located by locator contains the given text
*/
public static ExpectedCondition<Boolean> textToBePresentInElementLocated(
final By locator, final String text) {
public static ExpectedCondition<Boolean> textToBePresentInElementLocated(final By locator,
final String text) {

return new ExpectedCondition<Boolean>() {
@Override
Expand Down Expand Up @@ -408,8 +405,8 @@ public String toString() {
* @param text to be present in the element's value attribute
* @return true once the element's value attribute contains the given text
*/
public static ExpectedCondition<Boolean> textToBePresentInElementValue(
final WebElement element, final String text) {
public static ExpectedCondition<Boolean> textToBePresentInElementValue(final WebElement element,
final String text) {

return new ExpectedCondition<Boolean>() {
@Override
Expand Down Expand Up @@ -441,8 +438,8 @@ public String toString() {
* @return true once the value attribute of the first element located by locator contains the
* given text
*/
public static ExpectedCondition<Boolean> textToBePresentInElementValue(
final By locator, final String text) {
public static ExpectedCondition<Boolean> textToBePresentInElementValue(final By locator,
final String text) {

return new ExpectedCondition<Boolean>() {
@Override
Expand Down Expand Up @@ -499,8 +496,7 @@ public String toString() {
* @param locator used to find the frame
* @return WebDriver instance after frame has been switched
*/
public static ExpectedCondition<WebDriver> frameToBeAvailableAndSwitchToIt(
final By locator) {
public static ExpectedCondition<WebDriver> frameToBeAvailableAndSwitchToIt(final By locator) {
return new ExpectedCondition<WebDriver>() {
@Override
public WebDriver apply(WebDriver driver) {
Expand Down Expand Up @@ -576,8 +572,7 @@ public String toString() {
* @param locator used to find the element
* @return true if the element is not displayed or the element doesn't exist or stale element
*/
public static ExpectedCondition<Boolean> invisibilityOfElementLocated(
final By locator) {
public static ExpectedCondition<Boolean> invisibilityOfElementLocated(final By locator) {
return new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver driver) {
Expand Down Expand Up @@ -609,8 +604,8 @@ public String toString() {
* @param text of the element
* @return true if no such element, stale element or displayed text not equal that provided
*/
public static ExpectedCondition<Boolean> invisibilityOfElementWithText(
final By locator, final String text) {
public static ExpectedCondition<Boolean> invisibilityOfElementWithText(final By locator,
final String text) {
return new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver driver) {
Expand Down Expand Up @@ -642,16 +637,11 @@ public String toString() {
* @param locator used to find the element
* @return the WebElement once it is located and clickable (visible and enabled)
*/
public static ExpectedCondition<WebElement> elementToBeClickable(
final By locator) {
public static ExpectedCondition<WebElement> elementToBeClickable(final By locator) {
return new ExpectedCondition<WebElement>() {

public ExpectedCondition<WebElement> visibilityOfElementLocated =
ExpectedConditions.visibilityOfElementLocated(locator);

@Override
public WebElement apply(WebDriver driver) {
WebElement element = visibilityOfElementLocated.apply(driver);
WebElement element = visibilityOfElementLocated(locator).apply(driver);
try {
if (element != null && element.isEnabled()) {
return element;
Expand All @@ -675,19 +665,15 @@ public String toString() {
* @param element the WebElement
* @return the (same) WebElement once it is clickable (visible and enabled)
*/
public static ExpectedCondition<WebElement> elementToBeClickable(
final WebElement element) {
public static ExpectedCondition<WebElement> elementToBeClickable(final WebElement element) {
return new ExpectedCondition<WebElement>() {

public ExpectedCondition<WebElement> visibilityOfElement =
ExpectedConditions.visibilityOf(element);

@Override
public WebElement apply(WebDriver driver) {
WebElement element = visibilityOfElement.apply(driver);
WebElement visibleElement = visibilityOf(element).apply(driver);
try {
if (element != null && element.isEnabled()) {
return element;
if (visibleElement != null && visibleElement.isEnabled()) {
return visibleElement;
}
return null;
} catch (StaleElementReferenceException e) {
Expand All @@ -708,8 +694,7 @@ public String toString() {
* @param element The element to wait for.
* @return false is the element is still attached to the DOM, true otherwise.
*/
public static ExpectedCondition<Boolean> stalenessOf(
final WebElement element) {
public static ExpectedCondition<Boolean> stalenessOf(final WebElement element) {
return new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver ignored) {
Expand Down Expand Up @@ -741,8 +726,7 @@ public String toString() {
* @param <T> return type of the condition provided
* @return the result of the provided condition
*/
public static <T> ExpectedCondition<T> refreshed(
final ExpectedCondition<T> condition) {
public static <T> ExpectedCondition<T> refreshed(final ExpectedCondition<T> condition) {
return new ExpectedCondition<T>() {
@Override
public T apply(WebDriver driver) {
Expand Down Expand Up @@ -1163,10 +1147,9 @@ public String toString() {
* @param value used as expected attribute value
* @return Boolean true when element has css or html attribute which contains the value
*/
public static ExpectedCondition<Boolean> attributeContains(
final By locator,
final String attribute,
final String value) {
public static ExpectedCondition<Boolean> attributeContains(final By locator,
final String attribute,
final String value) {
return new ExpectedCondition<Boolean>() {
private String currentValue = null;

Expand All @@ -1193,14 +1176,7 @@ public String toString() {
*/
public static ExpectedCondition<Boolean> attributeToBeNotEmpty(final WebElement element,
final String attribute) {
return new ExpectedCondition<Boolean>() {
private String currentValue = null;

@Override
public Boolean apply(WebDriver driver) {
return getAttributeOrCssValue(element, attribute).isPresent();
}
};
return driver -> getAttributeOrCssValue(element, attribute).isPresent();
}

private static Optional<String> getAttributeOrCssValue(WebElement element, String name) {
Expand Down Expand Up @@ -1525,8 +1501,7 @@ public String toString() {
* @param javaScript as executable js line
* @return true once js return string
*/
public static ExpectedCondition<Object> jsReturnsValue(
final String javaScript) {
public static ExpectedCondition<Object> jsReturnsValue(final String javaScript) {
return new ExpectedCondition<Object>() {
@Override
public Object apply(WebDriver driver) {
Expand Down

0 comments on commit a4b3166

Please sign in to comment.