ae01e9c207ba849340d6f430a8c1dd89e76ad996
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / pages / VspValidationPage.java
1 /**
2  * Copyright (c) 2019 Vodafone Group
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.openecomp.sdc.ci.tests.pages;
18
19 import com.aventstack.extentreports.Status;
20 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
21 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
22 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
23 import org.openqa.selenium.By;
24 import org.openqa.selenium.WebElement;
25
26 import java.util.List;
27
28 import static org.testng.AssertJUnit.assertTrue;
29
30 public class VspValidationPage extends GeneralPageElements {
31
32     private VspValidationPage() {
33         super();
34     }
35
36     public static void navigateToVspValidationPageUsingNavbar() throws Exception {
37         clickOnElementUsingTestId(DataTestIdEnum.VspValidationPage.VSP_VALIDATION_PAGE_NAVBAR);
38     }
39
40     public static void navigateToVspValidationPageUsingBreadcrumbs() throws Exception {
41         clickOnElementUsingTestId(DataTestIdEnum.VspValidationPage.VSP_VALIDATION_PAGE_BREADCRUMBS);
42     }
43
44     public static void clickOnNextButton() throws Exception {
45         clickOnElementUsingTestId(DataTestIdEnum.VspValidationPage.VSP_VALIDATION_PAGE_PROCEED_TO_INPUTS_BUTTON);
46     }
47
48     public static void clickOnBackButton() throws Exception {
49         clickOnElementUsingTestId(DataTestIdEnum.VspValidationPage.VSP_VALIDATION_PAGE_PROCEED_TO_SETUP_BUTTON);
50     }
51
52     public static void clickOnSubmitButton() throws Exception {
53         clickOnElementUsingTestId(DataTestIdEnum.VspValidationPage.VSP_VALIDATION_PAGE_PROCEED_TO_RESULTS_BUTTON);
54     }
55
56     public static boolean checkNextButtonDisabled() throws Exception {
57         return GeneralUIUtils.isElementDisabled(DataTestIdEnum.VspValidationPage.VSP_VALIDATION_PAGE_PROCEED_TO_INPUTS_BUTTON.getValue());
58     }
59
60     public static void clickCertificationQueryAll() throws Exception {
61         List<WebElement> checkboxes = GeneralUIUtils.findElementsByXpath("//div[@data-test-id='vsp-validation-certifications-query-checkbox-tree']//label//span[@class='rct-checkbox']");
62         if (checkboxes.size() > 0) {
63             checkboxes.get(0).click();
64         } else {
65             assertTrue("Checkbox Not Found", checkboxes.size() > 0);
66         }
67     }
68
69     public static void clickComplianceChecksAll() throws Exception {
70         List<WebElement> checkboxes = GeneralUIUtils.findElementsByXpath("//div[@data-test-id='vsp-validation-compliance-checks-checkbox-tree']//label//span[@class='rct-checkbox']");
71         if (checkboxes.size() > 0) {
72             checkboxes.get(checkboxes.size() - 1).click();
73         } else {
74             assertTrue("Checkbox Not Found", checkboxes.size() > 0);
75         }
76     }
77
78     public static boolean checkCertificationQueryExists() throws Exception {
79         WebElement parentDiv = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.VspValidationPage.VSP_VALIDATION_PAGE_CERTIFICATION_CHECKBOX_TREE.getValue());
80         List<WebElement> checkboxTreeDivs = getChildElements(parentDiv);
81         List<WebElement> orderedList = getChildElements(checkboxTreeDivs.get(0));
82         return (orderedList.size() > 0);
83     }
84
85     public static boolean checkComplianceCheckExists() throws Exception {
86         WebElement parentDiv = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.VspValidationPage.VSP_VALIDATION_PAGE_COMPLIANCE_CHECKBOX_TREE.getValue());
87         List<WebElement> checkboxTreeDivs = getChildElements(parentDiv);
88         List<WebElement> orderedList = getChildElements(checkboxTreeDivs.get(0));
89         return (orderedList.size() > 0);
90     }
91
92     public static boolean checkSelectedComplianceCheckExists() throws Exception {
93         WebElement selectedTests = GeneralUIUtils.findElementsByXpath("//div[contains(text(),'Selected Compliance Tests')]/..//select[@class='validation-setup-selected-tests']").get(0);
94         List<WebElement> options = getChildElements(selectedTests);
95         return (!options.isEmpty());
96     }
97
98     public static boolean checkSelectedCertificationQueryExists() throws Exception {
99         WebElement selectedTests = GeneralUIUtils.findElementsByXpath("//div[contains(text(),'Selected Certifications Query')]/..//select[@class='validation-setup-selected-tests']").get(0);
100         List<WebElement> options = getChildElements(selectedTests);
101         return (!options.isEmpty());
102     }
103
104     public static void clickOnElementUsingTestId(DataTestIdEnum.VspValidationPage elementTestId) throws Exception {
105         SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on %s", elementTestId.name()));
106         GeneralUIUtils.getWebElementByTestID(elementTestId.getValue()).click();
107         GeneralUIUtils.ultimateWait();
108     }
109
110     private static List<WebElement> getChildElements(WebElement webElement) throws Exception {
111         return webElement.findElements(By.xpath(".//*"));
112     }
113
114
115 }