vid-automation selenium tests
[vid.git] / vid-automation / src / main / java / vid / automation / test / infra / Click.java
1 package vid.automation.test.infra;
2
3 import org.junit.Assert;
4 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
5 import org.openqa.selenium.Alert;
6 import org.openqa.selenium.By;
7 import org.openqa.selenium.Keys;
8 import org.openqa.selenium.WebElement;
9 import org.openqa.selenium.support.ui.ExpectedConditions;
10 import org.openqa.selenium.support.ui.Select;
11 import org.openqa.selenium.support.ui.WebDriverWait;
12
13 import java.util.List;
14
15 public class Click {
16     public static void byText(String text) {
17         WebElement element = GeneralUIUtils.findByText(text);
18         Assert.assertTrue(element != null);
19
20         element.click();
21     }
22
23     public static void byId(String id) {
24         WebElement element = Get.byId(id);
25         Assert.assertTrue(element != null);
26
27         element.click();
28     }
29
30     public static void byTestId(String testId) {
31         WebElement element = Get.byTestId(testId);
32         Assert.assertTrue(element != null);
33         element.click();
34     }
35
36     public static void byClass(String className) {
37         List<WebElement> elements = Get.byClass(className);
38         Assert.assertTrue(elements != null && elements.size() > 0);
39
40         elements.get(0).click();
41     }
42
43     public static void byXpath(String xpath) {
44         WebElement element = Get.byXpath(xpath);
45         Assert.assertNotNull(element);
46         element.click();
47     }
48
49
50     public static void onFirstSelectOptionById(String id) {
51         Select selectlist = new Select(Get.byId(id));
52         if(selectlist.getOptions().size() > 1) {
53             selectlist.selectByIndex(1);
54         }
55     }
56
57     public static void onFirstSelectOptionByTestId(String dataTestId) {
58         Select selectList = new Select(Get.byTestId(dataTestId));
59         if(selectList.getOptions().size() > 1) {
60             selectList.selectByIndex(1);
61         }
62     }
63
64     public static void onFirstSelectOptionByClass(String className) {
65         final List<WebElement> webElements = Get.byClass(className);
66         webElements.forEach(webElement -> {
67             Select selectlist = new Select(webElement);
68             if (selectlist.getOptions().size() > 1) {
69                 selectlist.selectByIndex(1);
70             }
71         });
72     }
73
74     public static void byClassAndVisibleText(String className, String text ) {
75         WebElement element = Get.byClassAndText(className, text);
76         element.click();
77     }
78
79
80
81     public static void acceptAlert() {
82         Alert alert = GeneralUIUtils.getDriver().switchTo().alert();
83         Assert.assertTrue(alert != null);
84         alert.accept();
85     }
86 }