1 package vid.automation.test.infra;
3 import org.junit.Assert;
4 import org.onap.sdc.ci.tests.utilities.GeneralUIUtils;
5 import org.openqa.selenium.*;
6 import org.openqa.selenium.support.ui.WebDriverWait;
8 import java.util.ArrayList;
10 import java.util.function.Function;
13 public static WebElement byId(String id) {
15 return GeneralUIUtils.getDriver().findElement(By.id(id));
16 } catch (Exception var2) {
21 public static WebElement byTestId(String dataTestId) {
23 return GeneralUIUtils.getDriver().findElement(getXpathForDataTestId(dataTestId));
24 } catch (Exception var2) {
29 public static WebElement byXpath(String xpath) {
31 return GeneralUIUtils.getWebElementBy(By.xpath(xpath));
32 } catch (Exception var2) {
37 public static WebElement byXpath(WebElement context, String xpath) {
39 return context.findElement(By.xpath(xpath));
40 } catch (Exception var2) {
45 public static WebElement byXpath(String xpath, int timeout) {
47 return GeneralUIUtils.getWebElementBy(By.xpath(xpath), timeout);
48 } catch (Exception var2) {
54 public static List<WebElement> multipleElementsByTestId(String dataTestId) {
56 return GeneralUIUtils.getWebElementsListByTestID(dataTestId);
57 } catch (Exception var2) {
62 public static WebElement byClassAndText(String className, String text) {
63 return byClassAndText(className, text, null);
66 public static WebElement byClassAndText(String className, String text, Integer timeoutInSeconds) {
67 WebElement result = null;
68 List<WebElement> elements;
69 if (timeoutInSeconds!=null) {
70 elements = GeneralUIUtils.getWebElementsListByContainsClassName(className, timeoutInSeconds);
73 elements = GeneralUIUtils.getWebElementsListByContainsClassName(className);
76 for(WebElement element : elements) {
77 if (element.getText().contains(text)) {
86 public static WebElement byCssSelectorAndText(String css, String text) {
87 WebElement element = GeneralUIUtils.getDriver().findElement(By.cssSelector(css));
89 if (element != null && element.getText().contains(text)) {
96 public static String selectedOptionText(String dataTestId) {
97 return GeneralUIUtils.getSelectedElementFromDropDown(dataTestId).getText();
100 public static Boolean isOptionSelectedInMultiSelect(String dataTestId, String option) {
101 return GeneralUIUtils.isOptionSelectedInMultiSelect(dataTestId, option);
104 public static List<WebElement> byClass(String className) {
105 return GeneralUIUtils.getWebElementsListByContainsClassName(className);
108 public static WebElement byCssSelector(String css) {
109 return GeneralUIUtils.getDriver().findElement(By.cssSelector(css));
112 public static List<String> tableHeaderValuesByTestId(String tableId) {
113 return tableValuesById(tableId, "thead", "th").get(0);
116 public static List<List<String>> tableBodyValuesByTestId(String tableId) {
117 return tableValuesById(tableId, "tbody", "td");
120 private static List<WebElement> rowsByTableId(String tableId,String section, String column) {
122 return GeneralUIUtils.getElemenetsFromTable(By.xpath("//table[@data-tests-id=\"" + tableId + "\"]/" + section + "/tr"));
123 } catch (Exception var2) {
128 private static List<List<String>> tableValuesById(String tableId, String section, String column) {
129 List<WebElement> rows = rowsByTableId(tableId, section, column);
131 List<List<String>> tableContent = new ArrayList<List<String>>();
132 for(WebElement row:rows) {
133 List<WebElement> columns = row.findElements(By.xpath(column));
134 tableContent.add(GeneralUIUtils.getWebElementListText(columns));
142 public static String alertText() {
143 WebDriverWait wait = new WebDriverWait(GeneralUIUtils.getDriver(), 2);
144 wait.until(alertIsPresent());
145 Alert alert = GeneralUIUtils.getDriver().switchTo().alert();
146 Assert.assertTrue(alert != null);
147 return alert.getText();
150 public static Function<WebDriver, Alert> alertIsPresent() {
151 return new Function<WebDriver, Alert>() {
152 public String toString() {
153 return "alert to be present";
157 public Alert apply(WebDriver driver) {
159 return driver.switchTo().alert();
160 } catch (NoAlertPresentException arg2) {
167 public static List<WebElement> listByTestId(String dataTestId) {
169 return GeneralUIUtils.getDriver().findElements(getXpathForDataTestId(dataTestId));
170 } catch (Exception var2) {
175 public static By getXpathForDataTestId(String dataTestId) {
176 return By.xpath("//*[@data-tests-id='" + dataTestId + "']");