ru.stqa.selenium.wait.RepeatableActions Maven / Gradle / Ivy
/*
* Copyright 2013 Alexei Barantsev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package ru.stqa.selenium.wait;
import org.openqa.selenium.*;
import java.util.List;
public final class RepeatableActions {
private RepeatableActions() {
// Utility class
}
/**
* @deprecated in favour of {{@link #findElement(By)}}
*/
@Deprecated
public static RepeatableAction performFindElement(final By locator) {
return findElement(locator);
}
public static RepeatableAction findElement(final By locator) {
return new AbstractRepeatableAction() {
@Override
public WebElement apply(SearchContext context) {
return context.findElement(locator);
}
@Override
public boolean shouldIgnoreException(Throwable t) {
return t instanceof NoSuchElementException;
}
};
}
/**
* @deprecated in favour of {{@link #findElements(By)}}
*/
@Deprecated
public static RepeatableAction> performFindElements(final By locator) {
return findElements(locator);
}
public static RepeatableAction> findElements(final By locator) {
return new AbstractRepeatableAction>() {
@Override
public List apply(SearchContext context) {
return context.findElements(locator);
}
@Override
public boolean shouldIgnoreException(Throwable t) {
return t instanceof NoSuchElementException;
}
@Override
public boolean shouldIgnoreResult(List result) {
return result.isEmpty();
}
};
}
/**
* @deprecated in favour of {{@link #click()}}
*/
@Deprecated
public static RepeatableAction performClick() {
return click();
}
public static RepeatableAction click() {
return new AbstractRepeatableAction() {
@Override
public Boolean apply(WebElement element) {
element.click();
return true;
}
@Override
public boolean shouldIgnoreException(Throwable t) {
return t instanceof ElementNotVisibleException;
}
};
}
/**
* @deprecated in favour of {{@link #submit()}}
*/
@Deprecated
public static RepeatableAction performSubmit() {
return submit();
}
public static RepeatableAction submit() {
return new AbstractRepeatableAction() {
@Override
public Boolean apply(WebElement element) {
element.submit();
return true;
}
@Override
public boolean shouldIgnoreException(Throwable t) {
return t instanceof ElementNotVisibleException;
}
};
}
/**
* @deprecated in favour of {{@link #sendKeys(CharSequence...)}}
*/
@Deprecated
public static RepeatableAction performSendKeys(final CharSequence... keysToSend) {
return sendKeys(keysToSend);
}
public static RepeatableAction sendKeys(final CharSequence... keysToSend) {
return new AbstractRepeatableAction() {
@Override
public Boolean apply(WebElement element) {
element.sendKeys(keysToSend);
return true;
}
@Override
public boolean shouldIgnoreException(Throwable t) {
return t instanceof ElementNotVisibleException;
}
};
}
/**
* @deprecated in favour of {{@link #clear()}}
*/
@Deprecated
public static RepeatableAction performClear() {
return clear();
}
public static RepeatableAction clear() {
return new AbstractRepeatableAction() {
@Override
public Boolean apply(WebElement element) {
element.clear();
return true;
}
@Override
public boolean shouldIgnoreException(Throwable t) {
return t instanceof ElementNotVisibleException;
}
};
}
public static RepeatableAction checkIsSelected() {
return new AbstractRepeatableAction() {
@Override
public Boolean apply(WebElement element) {
return element.isSelected();
}
@Override
public boolean shouldIgnoreException(Throwable t) {
return t instanceof ElementNotVisibleException;
}
};
}
public static RepeatableAction checkIsEnabled() {
return new AbstractRepeatableAction() {
@Override
public Boolean apply(WebElement element) {
return element.isEnabled();
}
@Override
public boolean shouldIgnoreException(Throwable t) {
return t instanceof ElementNotVisibleException;
}
};
}
/**
* @deprecated in favour of {{@link #switchToAlert()}}
*/
@Deprecated
public static RepeatableAction performSwitchToAlert() {
return switchToAlert();
}
public static RepeatableAction switchToAlert() {
return new AbstractRepeatableAction() {
@Override
public Alert apply(WebDriver driver) {
return driver.switchTo().alert();
}
@Override
public boolean shouldIgnoreException(Throwable t) {
return t instanceof NoAlertPresentException;
}
};
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy