Skip to content

Commit

Permalink
fix up!
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzk1 committed Feb 18, 2025
1 parent 6522d84 commit f32360e
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.apache.gravitino.integration.test.web.ui;

import java.util.concurrent.TimeUnit;
import org.apache.gravitino.integration.test.web.ui.pages.MetalakePage;
import org.apache.gravitino.integration.test.web.ui.utils.BaseWebIT;
import org.junit.jupiter.api.Assertions;
Expand Down Expand Up @@ -104,7 +103,11 @@ public void testCreateMultipleMetalakes() throws InterruptedException {
int twoPagesCount = 11;

for (int i = 0; i < twoPagesCount; i++) {
driver.manage().timeouts().implicitlyWait(ACTION_SLEEP_MILLIS, TimeUnit.MICROSECONDS);
try {
Thread.sleep(ACTION_SLEEP * 1000);
} catch (Exception e) {
LOG.error(e.getMessage(), e);
}
String name = "metalake_" + (i + 1);
createMetalakeAction(name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import org.apache.gravitino.integration.test.web.ui.utils.BaseWebIT;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
Expand Down Expand Up @@ -684,14 +683,16 @@ public boolean verifyShowTableTitle(String title) {
*/
public boolean verifyShowPropertiesItemInList(
String item, String key, String value, Boolean isHighlight) {
driver.manage().timeouts().implicitlyWait(ACTION_SLEEP_MILLIS, TimeUnit.MICROSECONDS);
WebDriverWait wait = new WebDriverWait(driver, ACTION_SLEEP);
String xpath;
if (isHighlight) {
xpath = "//div[@data-refer='props-" + item + "-" + key + "-highlight']";
} else {
xpath = "//div[@data-refer='props-" + item + "-" + key + "']";
}
WebElement propertyElement = driver.findElement(By.xpath(xpath));
WebElement propertyElement =
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpath)));

boolean match = Objects.equals(propertyElement.getText(), value);

if (!match) {
Expand All @@ -702,55 +703,47 @@ public boolean verifyShowPropertiesItemInList(
}

public boolean verifyShowDataItemInList(String itemName, Boolean isColumnLevel) {
try {
driver.manage().timeouts().implicitlyWait(ACTION_SLEEP_MILLIS, TimeUnit.MICROSECONDS);
String xpath =
"//div[@data-refer='table-grid']//div[contains(@class, 'MuiDataGrid-main')]/div[contains(@class, 'MuiDataGrid-virtualScroller')]/div/div[@role='rowgroup']//div[@data-field='name']";
if (isColumnLevel) {
xpath = xpath + "//p";
}
List<WebElement> list = driver.findElements(By.xpath(xpath));
List<String> texts = new ArrayList<>();
for (WebElement element : list) {
texts.add(element.getText());
}

if (!texts.contains(itemName)) {
LOG.error("table list: {} does not include itemName: {}", texts, itemName);
return false;
}
WebDriverWait wait = new WebDriverWait(driver, ACTION_SLEEP);
String xpath =
"//div[@data-refer='table-grid']//div[contains(@class, 'MuiDataGrid-main')]/div[contains(@class, 'MuiDataGrid-virtualScroller')]/div/div[@role='rowgroup']//div[@data-field='name']";
if (isColumnLevel) {
xpath = xpath + "//p";
}
List<WebElement> list =
wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath(xpath)));
List<String> texts = new ArrayList<>();
for (WebElement element : list) {
texts.add(element.getText());
}

return true;
} catch (Exception e) {
LOG.error(e.getMessage(), e);
if (!texts.contains(itemName)) {
LOG.error("table list: {} does not include itemName: {}", texts, itemName);
return false;
}

return true;
}

public boolean verifyNoDataItemInList(String itemName, Boolean isColumnLevel) {
try {
driver.manage().timeouts().implicitlyWait(ACTION_SLEEP_MILLIS, TimeUnit.MICROSECONDS);
String xpath =
"//div[@data-refer='table-grid']//div[contains(@class, 'MuiDataGrid-main')]/div[contains(@class, 'MuiDataGrid-virtualScroller')]/div/div[@role='rowgroup']//div[@data-field='name']";
if (isColumnLevel) {
xpath = xpath + "//p";
}
List<WebElement> list = driver.findElements(By.xpath(xpath));
List<String> texts = new ArrayList<>();
for (WebElement element : list) {
texts.add(element.getText());
}

if (texts.contains(itemName)) {
LOG.error("table list: {} does not include itemName: {}", texts, itemName);
return false;
}
String xpath =
"//div[@data-refer='table-grid']//div[contains(@class, 'MuiDataGrid-main')]/div[contains(@class, 'MuiDataGrid-virtualScroller')]/div/div[@role='rowgroup']//div[@data-field='name']";
if (isColumnLevel) {
xpath = xpath + "//p";
}
WebDriverWait wait = new WebDriverWait(driver, ACTION_SLEEP);
List<WebElement> list =
wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath(xpath)));
List<String> texts = new ArrayList<>();
for (WebElement element : list) {
texts.add(element.getText());
}

return true;
} catch (Exception e) {
LOG.error(e.getMessage(), e);
if (texts.contains(itemName)) {
LOG.error("table list: {} does not include itemName: {}", texts, itemName);
return false;
}

return true;
}

public boolean verifyTableColumns() {
Expand Down Expand Up @@ -835,106 +828,83 @@ public boolean verifyTablePropertiesOverview(List<String> cols) {
}

public boolean verifyBackHomePage() {
try {
WebDriverWait wait = new WebDriverWait(driver, MAX_TIMEOUT);
wait.until(ExpectedConditions.visibilityOf(metalakePageTitle));
boolean matchTitle = Objects.equals(metalakePageTitle.getText(), "Metalakes");
if (!matchTitle) {
LOG.error(
"metalakePageTitle: {} does not match with Metalakes", metalakePageTitle.getText());
return false;
}
return true;
} catch (Exception e) {
LOG.error(e.getMessage(), e);
WebDriverWait wait = new WebDriverWait(driver, MAX_TIMEOUT);
wait.until(ExpectedConditions.visibilityOf(metalakePageTitle));
boolean matchTitle = Objects.equals(metalakePageTitle.getText(), "Metalakes");
if (!matchTitle) {
LOG.error("metalakePageTitle: {} does not match with Metalakes", metalakePageTitle.getText());
return false;
}
return true;
}

public boolean verifyRefreshPage() {
try {
WebDriverWait wait = new WebDriverWait(driver, MAX_TIMEOUT);
wait.until(
webDriver ->
((JavascriptExecutor) webDriver)
.executeScript("return document.readyState")
.equals("complete"));
wait.until(ExpectedConditions.visibilityOf(metalakeNameLink));
boolean isDisplayed = metalakeNameLink.isDisplayed();
if (!isDisplayed) {
LOG.error("No match with link, get {}", metalakeNameLink.getText());
return false;
}
return true;
} catch (Exception e) {
LOG.error(e.getMessage(), e);
WebDriverWait wait = new WebDriverWait(driver, MAX_TIMEOUT);
wait.until(
webDriver ->
((JavascriptExecutor) webDriver)
.executeScript("return document.readyState")
.equals("complete"));
wait.until(ExpectedConditions.visibilityOf(metalakeNameLink));
boolean isDisplayed = metalakeNameLink.isDisplayed();
if (!isDisplayed) {
LOG.error("No match with link, get {}", metalakeNameLink.getText());
return false;
}
return true;
}

public boolean verifyCreatedCatalogs(List<String> catalogNames) {
try {
List<WebElement> list =
tableGrid.findElements(
By.xpath(
"./div[contains(@class, 'MuiDataGrid-main')]/div[contains(@class, 'MuiDataGrid-virtualScroller')]/div/div[@role='rowgroup']//div[@data-field='name']"));
List<String> texts = new ArrayList<>();
for (WebElement webElement : list) {
String rowItemColName = webElement.getText();
texts.add(rowItemColName);
}
if (!texts.containsAll(catalogNames)) {
LOG.error("table list: {} does not containsAll catalogNames: {}", texts, catalogNames);
return false;
}
return true;
} catch (Exception e) {
LOG.error(e.getMessage(), e);
List<WebElement> list =
tableGrid.findElements(
By.xpath(
"./div[contains(@class, 'MuiDataGrid-main')]/div[contains(@class, 'MuiDataGrid-virtualScroller')]/div/div[@role='rowgroup']//div[@data-field='name']"));
List<String> texts = new ArrayList<>();
for (WebElement webElement : list) {
String rowItemColName = webElement.getText();
texts.add(rowItemColName);
}
if (!texts.containsAll(catalogNames)) {
LOG.error("table list: {} does not containsAll catalogNames: {}", texts, catalogNames);
return false;
}
return true;
}

public boolean verifyTreeNodes(List<String> treeNodes) {
try {
driver.manage().timeouts().implicitlyWait(ACTION_SLEEP_MILLIS, TimeUnit.MICROSECONDS);
List<WebElement> list =
driver.findElements(
By.xpath(
"//div[@data-refer='tree-view']//div[@class='ant-tree-list-holder']/div/div[@class='ant-tree-list-holder-inner']/div[contains(@class, 'ant-tree-treenode')]"));
List<String> texts = new ArrayList<>();
for (WebElement webElement : list) {
String nodeName =
webElement.findElement(By.xpath(".//span[@class='ant-tree-title']")).getText();
texts.add(nodeName);
}
if (!treeNodes.containsAll(texts)) {
LOG.error("tree nodes list: {} does not containsAll treeNodes: {}", texts, treeNodes);
return false;
}
return true;
} catch (Exception e) {
LOG.error(e.getMessage(), e);
WebDriverWait wait = new WebDriverWait(driver, ACTION_SLEEP);
List<WebElement> list =
wait.until(
ExpectedConditions.visibilityOfAllElementsLocatedBy(
By.xpath(
"//div[@data-refer='tree-view']//div[@class='ant-tree-list-holder']/div/div[@class='ant-tree-list-holder-inner']/div[contains(@class, 'ant-tree-treenode')]")));
List<String> texts = new ArrayList<>();
for (WebElement webElement : list) {
String nodeName =
webElement.findElement(By.xpath(".//span[@class='ant-tree-title']")).getText();
texts.add(nodeName);
}
if (!treeNodes.containsAll(texts)) {
LOG.error("tree nodes list: {} does not containsAll treeNodes: {}", texts, treeNodes);
return false;
}
return true;
}

public boolean verifySelectedNode(String nodeName) {
try {
Thread.sleep(ACTION_SLEEP_MILLIS);
WebElement selectedNode =
driver.findElement(
By.xpath(
"//div[@data-refer='tree-view']//div[contains(@class, 'ant-tree-treenode-selected')]//span[@class='ant-tree-title']"));
waitShowText(nodeName, selectedNode);
if (!selectedNode.getText().equals(nodeName)) {
LOG.error(
"selectedNode: {} does not match with nodeName: {}", selectedNode.getText(), nodeName);
return false;
}
return true;
} catch (Exception e) {
LOG.error(e.getMessage(), e);

WebDriverWait wait = new WebDriverWait(driver, ACTION_SLEEP);

WebElement selectedNode =
wait.until(
ExpectedConditions.visibilityOfElementLocated(
By.xpath(
"//div[@data-refer='tree-view']//div[contains(@class, 'ant-tree-treenode-selected')]//span[@class='ant-tree-title']")));
if (!selectedNode.getText().equals(nodeName)) {
LOG.error(
"selectedNode: {} does not match with nodeName: {}", selectedNode.getText(), nodeName);
return false;
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.apache.gravitino.integration.test.web.ui.utils.BaseWebIT;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
Expand Down Expand Up @@ -133,10 +132,11 @@ public void setMetalakeCommentField(String commentField) {
}

public void setQueryParams(String queryParams) {
driver.manage().timeouts().implicitlyWait(ACTION_SLEEP_MILLIS, TimeUnit.MICROSECONDS);
WebDriverWait wait = new WebDriverWait(driver, ACTION_SLEEP);
WebElement queryInputElement =
wait.until(ExpectedConditions.elementToBeClickable(queryMetalakeInput));
clearQueryInput();
queryMetalakeInput.sendKeys(queryParams);
driver.manage().timeouts().implicitlyWait(ACTION_SLEEP_MILLIS, TimeUnit.MICROSECONDS);
queryInputElement.sendKeys(queryParams);
}

public void clearQueryInput() {
Expand Down Expand Up @@ -184,9 +184,10 @@ public void clickEditMetalakeBtn(String name) {
public void clickMetalakeLink(String name) {
try {
setQueryParams(name);
driver.manage().timeouts().implicitlyWait(ACTION_SLEEP_MILLIS, TimeUnit.MICROSECONDS);
WebDriverWait wait = new WebDriverWait(driver, ACTION_SLEEP);
String xpath = "//a[@data-refer='metalake-link-" + name + "']";
WebElement metalakeLink = metalakeTableGrid.findElement(By.xpath(xpath));
WebElement metalakeLink =
wait.until(ExpectedConditions.elementToBeClickable(By.xpath(xpath)));
clickAndWait(metalakeLink);
} catch (Exception e) {
LOG.error(e.getMessage(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.google.common.base.Function;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.concurrent.TimeUnit;
import org.apache.gravitino.integration.test.util.BaseIT;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -49,8 +48,8 @@ public class BaseWebIT extends BaseIT {
// https://www.selenium.dev/documentation/webdriver/waits/#implicit-waits
protected static final long MAX_IMPLICIT_WAIT = 30;
protected static final long MAX_TIMEOUT = 60;
protected static final long EACH_TEST_SLEEP_MILLIS = 5_000;
protected static final long ACTION_SLEEP_MILLIS = 5_000;
protected static final long EACH_TEST_SLEEP = 1;
protected static final long ACTION_SLEEP = 1;

protected boolean waitShowText(final String text, final Object locator) {
try {
Expand Down Expand Up @@ -83,12 +82,10 @@ protected void clickAndWait(final Object locator) throws InterruptedException {
wait.until(ExpectedConditions.elementToBeClickable(locatorElement(locator)));

locatorElement(locator).click();
driver.manage().timeouts().implicitlyWait(ACTION_SLEEP_MILLIS, TimeUnit.MICROSECONDS);
} catch (ElementClickInterceptedException e) {
// if the previous click did not effected then try clicking in another way
Actions action = new Actions(driver);
action.moveToElement(locatorElement(locator)).click().build().perform();
driver.manage().timeouts().implicitlyWait(ACTION_SLEEP_MILLIS, TimeUnit.MICROSECONDS);
}
}

Expand All @@ -106,7 +103,11 @@ WebElement locatorElement(final Object locatorOrElement) {

@BeforeEach
public void beforeEachTest() {
driver.manage().timeouts().implicitlyWait(EACH_TEST_SLEEP_MILLIS, TimeUnit.MICROSECONDS);
try {
Thread.sleep(EACH_TEST_SLEEP * 1000);
} catch (Exception e) {
LOG.error(e.getMessage(), e);
}
}

@BeforeAll
Expand Down

0 comments on commit f32360e

Please sign in to comment.