1 package vid.automation.test.infra;
3 import com.google.common.collect.ImmutableList;
4 import org.apache.commons.lang3.ObjectUtils;
5 import org.onap.sdc.ci.tests.utilities.GeneralUIUtils;
6 import org.openqa.selenium.WebElement;
7 import org.openqa.selenium.support.ui.Select;
8 import vid.automation.test.Constants;
10 import java.util.List;
11 import java.util.concurrent.TimeUnit;
14 * Created by itzikliderman on 18/07/2017.
16 public class SelectOption {
17 public static Select byValue(String value, String dataTestsId) {
18 Select select = new Select(GeneralUIUtils.getWebElementByTestID(dataTestsId));
20 select.selectByValue(value);
26 public static Select byIdAndVisibleText(String id, String text) {
27 Select selectlist = new Select(Get.byId(id));
29 selectlist.selectByVisibleText(text);
35 public static void byClassAndVisibleText(String className, String text) {
36 final List<WebElement> webElements = Get.byClass(className);
37 webElements.forEach(webElement -> {
38 final String id = webElement.getAttribute("id");
39 byIdAndVisibleText(id, text);
42 public static List<WebElement> getList(String selectDataTestId) {
43 Select selectList = GeneralUIUtils.getSelectList(null, selectDataTestId);
44 return selectList.getOptions();
46 public static String getSelectedOption(String selectDataTestId) {
47 Select selectList = GeneralUIUtils.getSelectList(null, selectDataTestId);
48 return selectList.getFirstSelectedOption().getText();
50 public static void byTestIdAndVisibleText(String displayName, String selectDataTestId) {
51 GeneralUIUtils.getSelectList(displayName, selectDataTestId);
54 public static void selectFirstTwoOptionsFromMultiselectById(String multiSelectId) throws InterruptedException {
55 Click.byId(multiSelectId);
57 Click.byClass(Constants.MULTI_SELECT_UNSELECTED_CLASS);
58 Click.byClass(Constants.MULTI_SELECT_UNSELECTED_CLASS);
62 public static void waitForOptionInSelect(String option, String selectTestId) {
64 ObjectUtils.defaultIfNull(SelectOption.getList(selectTestId), ImmutableList.<WebElement>of())
65 .stream().map(o -> o.getText()).filter(o -> option.equals(o)).findAny().isPresent(),
66 "", 10, 200, TimeUnit.MILLISECONDS);
69 public static void selectOptionsFromMultiselectById(String multiSelectId, List<String> options) {
70 Click.byId(multiSelectId);
73 } catch (InterruptedException e) {
74 throw new RuntimeException(e);
76 for(String option:options) {
77 Click.byClassAndVisibleText(Constants.MULTI_SELECT_UNSELECTED_CLASS, option);