Skip to content

Commit

Permalink
improve methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ch3yne committed Mar 19, 2024
1 parent eb216b3 commit 35578e7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -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));
Expand All @@ -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));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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());
Expand Down
1 change: 1 addition & 0 deletions web/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ tasks {
clean {
delete(".node")
delete("build")
delete(".next")
delete("dist")
delete("node_modules")
delete("yarn-error.log")
Expand Down

0 comments on commit 35578e7

Please sign in to comment.