aboutsummaryrefslogtreecommitdiffstats
path: root/vid-automation/src/main/java/vid/automation/test/infra/Get.java
blob: f9ce529f89403c3ebbb1cd8c0f0d35a01c46ba03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package vid.automation.test.infra;

import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import java.util.ArrayList;
import java.util.List;

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(By.xpath("//*[@data-tests-id='" + dataTestId + "']"));
        } catch (Exception var2) {
            return null;
        }
    }



    public static WebElement byClassAndText(String className, String text) {
        WebElement result = null;
        List<WebElement> 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<WebElement> byClass(String className) {
        return GeneralUIUtils.getWebElementsListByContainsClassName(className);
    }

    public static WebElement byCssSelector(String css) {
        return GeneralUIUtils.getDriver().findElement(By.cssSelector(css));
    }

    public static List<String> tableHeaderValuesByTestId(String tableId) {
        return tableValuesById(tableId, "thead", "th").get(0);
    }

    public static List<List<String>> tableBodyValuesByTestId(String tableId) {
        return tableValuesById(tableId, "tbody", "td");
    }

    private static List<WebElement> 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<List<String>> tableValuesById(String tableId, String section, String column) {
        List<WebElement> rows = rowsByTableId(tableId, section, column);
        if(rows != null) {
            List<List<String>> tableContent = new ArrayList<List<String>>();
            for(WebElement row:rows) {
                List<WebElement> columns = row.findElements(By.xpath(column));
                tableContent.add(GeneralUIUtils.getWebElementListText(columns));
            }
            return tableContent;
        }
        else {
            return null;
        }
    }
}