org.onap migration
[vid.git] / vid-automation / src / main / java / vid / automation / test / infra / Get.java
1 package vid.automation.test.infra;
2
3 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
4 import org.openqa.selenium.By;
5 import org.openqa.selenium.WebElement;
6
7 import java.util.ArrayList;
8 import java.util.List;
9
10 public class Get {
11     public static WebElement byId(String id) {
12         try {
13             return GeneralUIUtils.getDriver().findElement(By.id(id));
14         } catch (Exception var2) {
15             return null;
16         }
17     }
18
19     public static WebElement byTestId(String dataTestId) {
20         try {
21             return GeneralUIUtils.getDriver().findElement(By.xpath("//*[@data-tests-id='" + dataTestId + "']"));
22         } catch (Exception var2) {
23             return null;
24         }
25     }
26
27
28
29     public static WebElement byClassAndText(String className, String text) {
30         WebElement result = null;
31         List<WebElement> elements = GeneralUIUtils.getWebElementsListByContainsClassName(className);
32
33         for(WebElement element : elements) {
34             if (element.getText().contains(text)) {
35                 result = element;
36                 break;
37             }
38         }
39
40         return result;
41     }
42
43     public static WebElement byCssSelectorAndText(String css, String text) {
44         WebElement element = GeneralUIUtils.getDriver().findElement(By.cssSelector(css));
45
46         if (element != null && element.getText().contains(text)) {
47             return element;
48         }
49
50         return null;
51     }
52
53     public static String selectedOptionText(String dataTestId) {
54         return GeneralUIUtils.getSelectedElementFromDropDown(dataTestId).getText();
55     }
56
57     public static List<WebElement> byClass(String className) {
58         return GeneralUIUtils.getWebElementsListByContainsClassName(className);
59     }
60
61     public static WebElement byCssSelector(String css) {
62         return GeneralUIUtils.getDriver().findElement(By.cssSelector(css));
63     }
64
65     public static List<String> tableHeaderValuesByTestId(String tableId) {
66         return tableValuesById(tableId, "thead", "th").get(0);
67     }
68
69     public static List<List<String>> tableBodyValuesByTestId(String tableId) {
70         return tableValuesById(tableId, "tbody", "td");
71     }
72
73     private static List<WebElement> rowsByTableId(String tableId,String section, String column) {
74         try {
75             return GeneralUIUtils.getElemenetsFromTable(By.xpath("//table[@data-tests-id=\"" + tableId + "\"]/" + section + "/tr"));
76         } catch (Exception var2) {
77             return null;
78         }
79     }
80
81     private static List<List<String>> tableValuesById(String tableId, String section, String column) {
82         List<WebElement> rows = rowsByTableId(tableId, section, column);
83         if(rows != null) {
84             List<List<String>> tableContent = new ArrayList<List<String>>();
85             for(WebElement row:rows) {
86                 List<WebElement> columns = row.findElements(By.xpath(column));
87                 tableContent.add(GeneralUIUtils.getWebElementListText(columns));
88             }
89             return tableContent;
90         }
91         else {
92             return null;
93         }
94     }
95 }