[Selenium] Create method for performing specified functionality with ignoring provided exception (#11246)
parent
9f59bb800b
commit
7f65fe4424
|
|
@ -42,6 +42,7 @@ import org.eclipse.che.selenium.core.action.ActionsFactory;
|
|||
import org.eclipse.che.selenium.core.utils.WaitUtils;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.NoSuchElementException;
|
||||
import org.openqa.selenium.WebDriverException;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.interactions.Actions;
|
||||
import org.openqa.selenium.support.ui.ExpectedCondition;
|
||||
|
|
@ -1461,4 +1462,36 @@ public class SeleniumWebDriverHelper {
|
|||
public void pressEnter() {
|
||||
getAction().sendKeys(ENTER).perform();
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits until {@code action} stop throwing exception of {@code ignoredExceptionType} and during
|
||||
* {@code DEFAULT_TIMEOUT}.
|
||||
*
|
||||
* @param action action which should stop throwing of certain exception during timeout
|
||||
* @param ignoredExceptionType exception which should be ignored when action is performed
|
||||
*/
|
||||
public void waitNoExceptions(
|
||||
Runnable action, Class<? extends WebDriverException> ignoredExceptionType) {
|
||||
waitNoExceptions(action, ignoredExceptionType, DEFAULT_TIMEOUT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits until {@code action} stop throwing exception of {@code ignoredExceptionType} during
|
||||
* {@code timeoutInSec}.
|
||||
*
|
||||
* @param action action which should stop throwing of certain exception during timeout
|
||||
* @param ignoredExceptionType exception which should be ignored when action is being performed
|
||||
* @param timeoutInSec waiting time in seconds
|
||||
*/
|
||||
public void waitNoExceptions(
|
||||
Runnable action, Class<? extends WebDriverException> ignoredExceptionType, int timeoutInSec) {
|
||||
webDriverWaitFactory
|
||||
.get(timeoutInSec, ignoredExceptionType)
|
||||
.until(
|
||||
(ExpectedCondition<Boolean>)
|
||||
driver -> {
|
||||
action.run();
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,15 +39,36 @@ public class WebDriverWaitFactory {
|
|||
return new WebDriverWait(seleniumWebDriver, timeoutInSec);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of the {@link FluentWait} with specified {@code timeoutInSec} and error
|
||||
* message supplier.
|
||||
*
|
||||
* @param timeoutInSec waiting time in seconds.
|
||||
* @param messageSupplier error message supplier
|
||||
* @return
|
||||
*/
|
||||
public FluentWait<WebDriver> get(int timeoutInSec, Supplier<String> messageSupplier) {
|
||||
return new WebDriverWait(seleniumWebDriver, timeoutInSec).withMessage(messageSupplier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of the {@link WebDriverWait} with specified {@code timeout} and frequency
|
||||
* of attempts.
|
||||
* Creates an instance of the {@link FluentWait} with specified {@code timeoutInSec} and ignoring
|
||||
* exception of {@code ignoringExceptionType}.
|
||||
*
|
||||
* @param timeoutInSec waiting time for condition in seconds.
|
||||
* @param timeoutInSec waiting time in seconds.
|
||||
* @param ignoredExceptionType exception which is ignoring during timeout.
|
||||
* @return
|
||||
*/
|
||||
public FluentWait<WebDriver> get(
|
||||
int timeoutInSec, Class<? extends Throwable> ignoredExceptionType) {
|
||||
return new WebDriverWait(seleniumWebDriver, timeoutInSec).ignoring(ignoredExceptionType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of the {@link WebDriverWait} with specified {@code timeoutInSec} and
|
||||
* frequency of attempts.
|
||||
*
|
||||
* @param timeoutInSec waiting time in seconds.
|
||||
* @param delayBetweenAttemptsInSec delay between attempts.
|
||||
* @return instance of the {@link WebDriverWait} initialized by specified values.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -482,19 +482,10 @@ public class ProjectExplorer {
|
|||
*/
|
||||
public void waitAndSelectItem(String path, int timeout) {
|
||||
waitItem(path);
|
||||
try {
|
||||
waitAndGetItem(path, timeout).click();
|
||||
}
|
||||
// sometimes an element in the project explorer may not be attached to the DOM. We should
|
||||
// refresh all items.
|
||||
catch (StaleElementReferenceException ex) {
|
||||
LOG.debug(ex.getLocalizedMessage(), ex);
|
||||
|
||||
waitProjectExplorer();
|
||||
clickOnRefreshTreeButton();
|
||||
waitItem(path);
|
||||
waitAndGetItem(path, timeout).click();
|
||||
}
|
||||
seleniumWebDriverHelper.waitNoExceptions(
|
||||
() -> waitAndGetItem(path, timeout).click(),
|
||||
StaleElementReferenceException.class,
|
||||
LOAD_PAGE_TIMEOUT_SEC);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -553,22 +544,13 @@ public class ProjectExplorer {
|
|||
waitAndSelectItem(path);
|
||||
waitItemIsSelected(path);
|
||||
|
||||
try {
|
||||
action.moveToElement(waitAndGetItem(path)).perform();
|
||||
action.doubleClick().perform();
|
||||
}
|
||||
// sometimes an element in the project explorer may not be attached to the DOM. We should
|
||||
// refresh all items.
|
||||
catch (StaleElementReferenceException ex) {
|
||||
LOG.debug(ex.getLocalizedMessage(), ex);
|
||||
|
||||
clickOnRefreshTreeButton();
|
||||
waitAndSelectItem(path);
|
||||
waitItemIsSelected(path);
|
||||
action.moveToElement(waitAndGetItem(path)).perform();
|
||||
action.doubleClick().perform();
|
||||
}
|
||||
loader.waitOnClosed();
|
||||
seleniumWebDriverHelper.waitNoExceptions(
|
||||
() -> {
|
||||
action.moveToElement(waitAndGetItem(path)).perform();
|
||||
action.doubleClick().perform();
|
||||
},
|
||||
StaleElementReferenceException.class,
|
||||
LOAD_PAGE_TIMEOUT_SEC);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue