diff --git a/selenium/che-selenium-core/src/main/java/org/eclipse/che/selenium/core/webdriver/SeleniumWebDriverHelper.java b/selenium/che-selenium-core/src/main/java/org/eclipse/che/selenium/core/webdriver/SeleniumWebDriverHelper.java index f43700a1f4..94c662378d 100644 --- a/selenium/che-selenium-core/src/main/java/org/eclipse/che/selenium/core/webdriver/SeleniumWebDriverHelper.java +++ b/selenium/che-selenium-core/src/main/java/org/eclipse/che/selenium/core/webdriver/SeleniumWebDriverHelper.java @@ -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 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 ignoredExceptionType, int timeoutInSec) { + webDriverWaitFactory + .get(timeoutInSec, ignoredExceptionType) + .until( + (ExpectedCondition) + driver -> { + action.run(); + return true; + }); + } } diff --git a/selenium/che-selenium-core/src/main/java/org/eclipse/che/selenium/core/webdriver/WebDriverWaitFactory.java b/selenium/che-selenium-core/src/main/java/org/eclipse/che/selenium/core/webdriver/WebDriverWaitFactory.java index adae1a4517..457cdbdc45 100644 --- a/selenium/che-selenium-core/src/main/java/org/eclipse/che/selenium/core/webdriver/WebDriverWaitFactory.java +++ b/selenium/che-selenium-core/src/main/java/org/eclipse/che/selenium/core/webdriver/WebDriverWaitFactory.java @@ -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 get(int timeoutInSec, Supplier 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 get( + int timeoutInSec, Class 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. */ diff --git a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/ProjectExplorer.java b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/ProjectExplorer.java index bdf7c149a0..c183f306db 100644 --- a/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/ProjectExplorer.java +++ b/selenium/che-selenium-test/src/main/java/org/eclipse/che/selenium/pageobject/ProjectExplorer.java @@ -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); } /**