aboutsummaryrefslogtreecommitdiffstats
path: root/vid-automation/src/main/java/vid/automation/test/infra/SelectOption.java
blob: dc792cfc3ffc8938ca0e0bde35721f62d10d8334 (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
package vid.automation.test.infra;

import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;
import vid.automation.test.Constants;

import java.util.List;

/**
 * Created by itzikliderman on 18/07/2017.
 */
public class SelectOption {
    public static Select byValue(String value, String dataTestsId) {
        Select select = new Select(GeneralUIUtils.getWebElementByTestID(dataTestsId));
        if(value != null) {
            select.selectByValue(value);
        }

        return select;
    }

    public static Select byIdAndVisibleText(String id, String text) {
        Select selectlist = new Select(Get.byId(id));
        if(text != null) {
            selectlist.selectByVisibleText(text);
        }

        return selectlist;
    }

    public static void byClassAndVisibleText(String className, String text) {
        final List<WebElement> webElements = Get.byClass(className);
        webElements.forEach(webElement -> {
            final String id = webElement.getAttribute("id");
            byIdAndVisibleText(id, text);
        });
    }
    public static List<WebElement> getList(String selectDataTestId) {
        Select selectList = GeneralUIUtils.getSelectList(null, selectDataTestId);
        return selectList.getOptions();
    }
    public static String getSelectedOption(String selectDataTestId) {
        Select selectList = GeneralUIUtils.getSelectList(null, selectDataTestId);
        return selectList.getFirstSelectedOption().getText();
    }
    public static void byTestIdAndVisibleText(String displayName, String selectDataTestId) {
        GeneralUIUtils.getSelectList(displayName, selectDataTestId);
    }

    public static void selectFirstTwoOptionsFromMultiselectById(String multiSelectId) throws InterruptedException {
        Click.byId(multiSelectId);
        Thread.sleep(1000);
        Click.byClass(Constants.MULTI_SELECT_UNSELECTED_CLASS);
        Click.byClass(Constants.MULTI_SELECT_UNSELECTED_CLASS);

    }

    public static void selectOptionsFromMultiselectById(String multiSelectId, List<String> options) {
        Click.byId(multiSelectId);
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        for(String option:options) {
            Click.byClassAndVisibleText(Constants.MULTI_SELECT_UNSELECTED_CLASS, option);
        }
    }
}