package vid.automation.test.infra; import org.junit.Assert; import org.onap.sdc.ci.tests.utilities.GeneralUIUtils; import org.openqa.selenium.*; import org.openqa.selenium.support.ui.WebDriverWait; import java.util.ArrayList; import java.util.List; import java.util.function.Function; public class Get { public static WebElement byId(String id) { try { return GeneralUIUtils.getDriver().findElement(By.id(id)); } catch (Exception var2) { return null; } } public static WebElement byTestId(String dataTestId) { try { return GeneralUIUtils.getDriver().findElement(getXpathForDataTestId(dataTestId)); } catch (Exception var2) { return null; } } public static WebElement byXpath(String xpath) { try { return GeneralUIUtils.getWebElementBy(By.xpath(xpath)); } catch (Exception var2) { return null; } } public static WebElement byXpath(WebElement context, String xpath) { try { return context.findElement(By.xpath(xpath)); } catch (Exception var2) { return null; } } public static WebElement byXpath(String xpath, int timeout) { try { return GeneralUIUtils.getWebElementBy(By.xpath(xpath), timeout); } catch (Exception var2) { return null; } } public static List multipleElementsByTestId(String dataTestId) { try { return GeneralUIUtils.getWebElementsListByTestID(dataTestId); } catch (Exception var2) { return null; } } public static WebElement byClassAndText(String className, String text) { return byClassAndText(className, text, null); } public static WebElement byClassAndText(String className, String text, Integer timeoutInSeconds) { WebElement result = null; List elements; if (timeoutInSeconds!=null) { elements = GeneralUIUtils.getWebElementsListByContainsClassName(className, timeoutInSeconds); } else { elements = GeneralUIUtils.getWebElementsListByContainsClassName(className); } for(WebElement element : elements) { if (element.getText().contains(text)) { result = element; break; } } return result; } public static WebElement byCssSelectorAndText(String css, String text) { WebElement element = GeneralUIUtils.getDriver().findElement(By.cssSelector(css)); if (element != null && element.getText().contains(text)) { return element; } return null; } public static String selectedOptionText(String dataTestId) { return GeneralUIUtils.getSelectedElementFromDropDown(dataTestId).getText(); } public static List byClass(String className) { return GeneralUIUtils.getWebElementsListByContainsClassName(className); } public static WebElement byCssSelector(String css) { return GeneralUIUtils.getDriver().findElement(By.cssSelector(css)); } public static List tableHeaderValuesByTestId(String tableId) { return tableValuesById(tableId, "thead", "th").get(0); } public static List> tableBodyValuesByTestId(String tableId) { return tableValuesById(tableId, "tbody", "td"); } private static List rowsByTableId(String tableId,String section, String column) { try { return GeneralUIUtils.getElemenetsFromTable(By.xpath("//table[@data-tests-id=\"" + tableId + "\"]/" + section + "/tr")); } catch (Exception var2) { return null; } } private static List> tableValuesById(String tableId, String section, String column) { List rows = rowsByTableId(tableId, section, column); if(rows != null) { List> tableContent = new ArrayList>(); for(WebElement row:rows) { List columns = row.findElements(By.xpath(column)); tableContent.add(GeneralUIUtils.getWebElementListText(columns)); } return tableContent; } else { return null; } } public static String alertText() { WebDriverWait wait = new WebDriverWait(GeneralUIUtils.getDriver(), 2); wait.until(alertIsPresent()); Alert alert = GeneralUIUtils.getDriver().switchTo().alert(); Assert.assertTrue(alert != null); return alert.getText(); } public static Function alertIsPresent() { return new Function() { public String toString() { return "alert to be present"; } @Override public Alert apply(WebDriver driver) { try { return driver.switchTo().alert(); } catch (NoAlertPresentException arg2) { return null; } } }; } public static List listByTestId(String dataTestId) { try { return GeneralUIUtils.getDriver().findElements(getXpathForDataTestId(dataTestId)); } catch (Exception var2) { return null; } } public static By getXpathForDataTestId(String dataTestId) { return By.xpath("//*[@data-tests-id='" + dataTestId + "']"); } }