1 package vid.automation.test.infra;
3 import org.junit.Assert;
4 import org.openecomp.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(By.xpath("//*[@data-tests-id='" + 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(String xpath, int timeout) {
39 return GeneralUIUtils.getWebElementBy(By.xpath(xpath), timeout);
40 } catch (Exception var2) {
46 public static List<WebElement> multipleElementsByTestId(String dataTestId) {
48 return GeneralUIUtils.getWebElementsListByTestID(dataTestId);
49 } catch (Exception var2) {
54 public static WebElement byClassAndText(String className, String text) {
55 return byClassAndText(className, text, null);
58 public static WebElement byClassAndText(String className, String text, Integer timeoutInSeconds) {
59 WebElement result = null;
60 List<WebElement> elements;
61 if (timeoutInSeconds!=null) {
62 elements = GeneralUIUtils.getWebElementsListByContainsClassName(className, timeoutInSeconds);
65 elements = GeneralUIUtils.getWebElementsListByContainsClassName(className);
68 for(WebElement element : elements) {
69 if (element.getText().contains(text)) {
78 public static WebElement byCssSelectorAndText(String css, String text) {
79 WebElement element = GeneralUIUtils.getDriver().findElement(By.cssSelector(css));
81 if (element != null && element.getText().contains(text)) {
88 public static String selectedOptionText(String dataTestId) {
89 return GeneralUIUtils.getSelectedElementFromDropDown(dataTestId).getText();
93 public static List<WebElement> byClass(String className) {
94 return GeneralUIUtils.getWebElementsListByContainsClassName(className);
97 public static WebElement byCssSelector(String css) {
98 return GeneralUIUtils.getDriver().findElement(By.cssSelector(css));
101 public static List<String> tableHeaderValuesByTestId(String tableId) {
102 return tableValuesById(tableId, "thead", "th").get(0);
105 public static List<List<String>> tableBodyValuesByTestId(String tableId) {
106 return tableValuesById(tableId, "tbody", "td");
109 private static List<WebElement> rowsByTableId(String tableId,String section, String column) {
111 return GeneralUIUtils.getElemenetsFromTable(By.xpath("//table[@data-tests-id=\"" + tableId + "\"]/" + section + "/tr"));
112 } catch (Exception var2) {
117 private static List<List<String>> tableValuesById(String tableId, String section, String column) {
118 List<WebElement> rows = rowsByTableId(tableId, section, column);
120 List<List<String>> tableContent = new ArrayList<List<String>>();
121 for(WebElement row:rows) {
122 List<WebElement> columns = row.findElements(By.xpath(column));
123 tableContent.add(GeneralUIUtils.getWebElementListText(columns));
131 public static String alertText() {
132 WebDriverWait wait = new WebDriverWait(GeneralUIUtils.getDriver(), 2);
133 wait.until(alertIsPresent());
134 Alert alert = GeneralUIUtils.getDriver().switchTo().alert();
135 Assert.assertTrue(alert != null);
136 return alert.getText();
139 public static Function<WebDriver, Alert> alertIsPresent() {
140 return new Function<WebDriver, Alert>() {
141 public String toString() {
142 return "alert to be present";
146 public Alert apply(WebDriver driver) {
148 return driver.switchTo().alert();
149 } catch (NoAlertPresentException arg2) {