diff --git a/integration-test/src/test/java/com/datastrato/gravitino/integration/test/web/ui/MetalakePageTest.java b/integration-test/src/test/java/com/datastrato/gravitino/integration/test/web/ui/MetalakePageTest.java index b4e4a94a03f..43541370316 100644 --- a/integration-test/src/test/java/com/datastrato/gravitino/integration/test/web/ui/MetalakePageTest.java +++ b/integration-test/src/test/java/com/datastrato/gravitino/integration/test/web/ui/MetalakePageTest.java @@ -117,7 +117,7 @@ public void testCreateInvalidMetalake() { @Test @Order(7) - public void testLinkToCatalogsPage() { + public void testLinkToCatalogsPage() throws InterruptedException { String name = "a_test_link"; createMetalakeAction(name); metalakePage.clickMetalakeLink(name); diff --git a/integration-test/src/test/java/com/datastrato/gravitino/integration/test/web/ui/pages/MetalakePage.java b/integration-test/src/test/java/com/datastrato/gravitino/integration/test/web/ui/pages/MetalakePage.java index a9582ede924..2b85cd524a4 100644 --- a/integration-test/src/test/java/com/datastrato/gravitino/integration/test/web/ui/pages/MetalakePage.java +++ b/integration-test/src/test/java/com/datastrato/gravitino/integration/test/web/ui/pages/MetalakePage.java @@ -105,7 +105,6 @@ public void clearQueryInput() { public void clickDeleteMetalakeBtn(String name) { try { String xpath = "//button[@data-refer='delete-metalake-" + name + "']"; - waitClickable(By.xpath(xpath), AbstractWebIT.MAX_TIMEOUT); clickAndWait(By.xpath(xpath)); } catch (Exception e) { LOG.error(e.getMessage(), e); @@ -115,7 +114,6 @@ public void clickDeleteMetalakeBtn(String name) { public void clickViewMetalakeBtn(String name) { try { String xpath = "//button[@data-refer='view-metalake-" + name + "']"; - waitClickable(By.xpath(xpath), AbstractWebIT.MAX_TIMEOUT); clickAndWait(By.xpath(xpath)); } catch (Exception e) { LOG.error(e.getMessage(), e); @@ -125,7 +123,6 @@ public void clickViewMetalakeBtn(String name) { public void clickEditMetalakeBtn(String name) { try { String xpath = "//button[@data-refer='edit-metalake-" + name + "']"; - waitClickable(By.xpath(xpath), AbstractWebIT.MAX_TIMEOUT); clickAndWait(By.xpath(xpath)); } catch (Exception e) { LOG.error(e.getMessage(), e); @@ -135,7 +132,6 @@ public void clickEditMetalakeBtn(String name) { public void clickMetalakeLink(String name) { try { String xpath = "//a[@href='/ui/metalakes?metalake=" + name + "']"; - waitClickable(By.xpath(xpath), AbstractWebIT.MAX_TIMEOUT); clickAndWait(By.xpath(xpath)); } catch (Exception e) { LOG.error(e.getMessage(), e); @@ -243,8 +239,7 @@ public boolean verifyEmptyMetalake() { public boolean verifyChangePagination() { try { - waitElementClickable(nextPageBtn, AbstractWebIT.MAX_TIMEOUT); - clickElementAndWait(nextPageBtn); + clickAndWait(nextPageBtn); // Check if the previous page button is available return prevPageBtn.isEnabled() && performPrevPageAction(); } catch (Exception e) { @@ -254,8 +249,7 @@ public boolean verifyChangePagination() { private boolean performPrevPageAction() { try { - waitElementClickable(prevPageBtn, AbstractWebIT.MAX_TIMEOUT); - clickElementAndWait(prevPageBtn); + clickAndWait(prevPageBtn); return true; } catch (Exception e) { return false; @@ -282,7 +276,7 @@ public boolean verifyQueryMetalake(String name) { } } - public boolean verifyLinkToCatalogsPage(String name) { + public boolean verifyLinkToCatalogsPage(String name) throws InterruptedException { try { String xpath = "//a[@data-refer='metalake-name-link']"; WebElement nameLink = driver.findElement(By.xpath(xpath)); @@ -292,12 +286,12 @@ public boolean verifyLinkToCatalogsPage(String name) { return nameLink.isDisplayed() && isUrl; } catch (Exception e) { + LOG.error(e.getMessage(), e); return false; } finally { // Back to homepage String xpath = "//*[@data-refer='back-home-btn']"; - WebElement backHomeBtn = driver.findElement(By.xpath(xpath)); - backHomeBtn.click(); + clickAndWait(By.xpath(xpath)); } } } diff --git a/integration-test/src/test/java/com/datastrato/gravitino/integration/test/web/ui/utils/AbstractWebIT.java b/integration-test/src/test/java/com/datastrato/gravitino/integration/test/web/ui/utils/AbstractWebIT.java index 0b6cf1166ee..2bd2da544f8 100644 --- a/integration-test/src/test/java/com/datastrato/gravitino/integration/test/web/ui/utils/AbstractWebIT.java +++ b/integration-test/src/test/java/com/datastrato/gravitino/integration/test/web/ui/utils/AbstractWebIT.java @@ -12,6 +12,7 @@ import org.junit.jupiter.api.BeforeAll; import org.openqa.selenium.By; import org.openqa.selenium.ElementClickInterceptedException; +import org.openqa.selenium.InvalidArgumentException; import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.TimeoutException; import org.openqa.selenium.WebDriver; @@ -53,21 +54,20 @@ protected WebElement pollingWait(final By locator, final long maxTimeout) { return wait.until((Function<WebDriver, WebElement>) driver -> driver.findElement(locator)); } - protected void clickAndWait(final By locator) throws InterruptedException { - WebElement element = pollingWait(locator, MAX_IMPLICIT_WAIT); - try { - element.click(); - Thread.sleep(SLEEP_MILLIS); - } catch (ElementClickInterceptedException e) { - Actions action = new Actions(driver); - action.moveToElement(element).click().build().perform(); - Thread.sleep(SLEEP_MILLIS); - LOG.error(e.getMessage(), e); + protected void clickAndWait(final Object locatorOrElement) throws InterruptedException { + WebElement element; + if (locatorOrElement instanceof By) { + element = pollingWait((By) locatorOrElement, MAX_IMPLICIT_WAIT); + } else if (locatorOrElement instanceof WebElement) { + element = (WebElement) locatorOrElement; + } else { + throw new InvalidArgumentException("The provided argument is neither a By nor a WebElement"); } - } - - protected void clickElementAndWait(final WebElement element) throws InterruptedException { try { + WebDriverWait wait = new WebDriverWait(driver, MAX_TIMEOUT); + wait.until(ExpectedConditions.visibilityOf(element)); + wait.until(ExpectedConditions.elementToBeClickable(element)); + element.click(); Thread.sleep(SLEEP_MILLIS); } catch (ElementClickInterceptedException e) { @@ -78,19 +78,6 @@ protected void clickElementAndWait(final WebElement element) throws InterruptedE } } - protected void waitClickable(final By locator, final long timeout) { - WebElement element = pollingWait(locator, MAX_IMPLICIT_WAIT); - WebDriverWait wait = new WebDriverWait(driver, timeout); - wait.until(ExpectedConditions.visibilityOf(element)); - wait.until(ExpectedConditions.elementToBeClickable(element)); - } - - protected void waitElementClickable(final WebElement element, final long timeout) { - WebDriverWait wait = new WebDriverWait(driver, timeout); - wait.until(ExpectedConditions.visibilityOf(element)); - wait.until(ExpectedConditions.elementToBeClickable(element)); - } - @BeforeAll public static void startUp() { driver = WebDriverManager.getWebDriver(getGravitinoServerPort()); diff --git a/web/build.gradle.kts b/web/build.gradle.kts index f522d9b0504..04031e65eab 100644 --- a/web/build.gradle.kts +++ b/web/build.gradle.kts @@ -54,6 +54,7 @@ tasks { clean { delete(".node") delete("build") + delete(".next") delete("dist") delete("node_modules") delete("yarn-error.log")