Catalog alignment
[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.apache.commons.collections.CollectionUtils;
21 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
22 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
23 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
24 import org.openqa.selenium.By;
25 import org.openqa.selenium.WebElement;
26 import org.testng.Assert;
27
28 import java.io.File;
29 import java.util.List;
30
31 public class VspValidationPage extends GeneralPageElements {
32
33     private VspValidationPage() {
34         super();
35     }
36
37     public static void navigateToVspValidationPageUsingNavbar() throws Exception {
38         clickOnElementUsingTestId(DataTestIdEnum.VspValidationPage.VSP_VALIDATION_PAGE_NAVBAR);
39     }
40
41     public static void navigateToVspValidationPageUsingBreadcrumbs() throws Exception {
42         clickOnElementUsingTestId(DataTestIdEnum.VspValidationPage.VSP_VALIDATION_PAGE_BREADCRUMBS);
43     }
44
45     public static void clickOnNextButton() throws Exception {
46         clickOnElementUsingTestId(DataTestIdEnum.VspValidationPage.VSP_VALIDATION_PAGE_PROCEED_TO_INPUTS_BUTTON);
47     }
48
49     public static void clickOnBackButton() throws Exception {
50         clickOnElementUsingTestId(DataTestIdEnum.VspValidationPage.VSP_VALIDATION_PAGE_PROCEED_TO_SETUP_BUTTON);
51     }
52
53     public static void clickOnSubmitButton() throws Exception {
54         clickOnElementUsingTestId(DataTestIdEnum.VspValidationPage.VSP_VALIDATION_PAGE_PROCEED_TO_RESULTS_BUTTON);
55     }
56
57     public static void loadVSPFile(String path, String filename) {
58         List<WebElement> checkboxes =
59                 GeneralUIUtils.findElementsByXpath("//div[@class='validation-input-wrapper']//input");
60         boolean hasValue = CollectionUtils.isNotEmpty(checkboxes);
61         if (hasValue) {
62             WebElement browseWebElement = checkboxes.get(0);
63             browseWebElement.sendKeys(path + File.separator + filename);
64             GeneralUIUtils.ultimateWait();
65         } else {
66             Assert.fail("Did not find File input field in the page for loading VSP test file");
67         }
68
69     }
70     public static boolean checkNextButtonDisabled() throws Exception {
71         return GeneralUIUtils.isElementDisabled(DataTestIdEnum.VspValidationPage.VSP_VALIDATION_PAGE_PROCEED_TO_INPUTS_BUTTON.getValue());
72     }
73
74     public static void clickCertificationQueryAll() throws Exception {
75         List<WebElement> checkboxes = GeneralUIUtils.findElementsByXpath("//div[@data-test-id='vsp-validation-certifications-query-checkbox-tree']//label//span[@class='rct-checkbox']");
76         if (!checkboxes.isEmpty()) {
77             checkboxes.get(0).click();
78         } else {
79             Assert.fail("Did not find certification test checkbox in the page");
80         }
81     }
82
83     public static void clickComplianceChecksAll() throws Exception {
84         List<WebElement> vnfComplianceCheckboxes = GeneralUIUtils.findElementsByXpath("//div[@data-test-id='vsp-validation-compliance-checks-checkbox-tree']//span[@class='rct-text' and .//label//text()='vnf-compliance']//button");
85         if (!vnfComplianceCheckboxes.isEmpty()) {
86             vnfComplianceCheckboxes.get(vnfComplianceCheckboxes.size() - 1).click();
87         } else {
88             Assert.fail("Did not find vnf-compliance test checkbox in the page");
89         }
90         List<WebElement> checkboxes = GeneralUIUtils.findElementsByXpath("//div[@data-test-id='vsp-validation-compliance-checks-checkbox-tree']//label//span[@class='rct-title' and text()='csar-validate']");
91         if (!checkboxes.isEmpty()) {
92             checkboxes.get(checkboxes.size() - 1).click();
93         } else {
94             Assert.fail("Did not find csar-validate test Checkbox in the page");
95         }
96     }
97
98     public static boolean checkCertificationQueryExists() throws Exception {
99         WebElement parentDiv = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.VspValidationPage.VSP_VALIDATION_PAGE_CERTIFICATION_CHECKBOX_TREE.getValue());
100         List<WebElement> checkboxTreeDivs = getChildElements(parentDiv);
101         List<WebElement> orderedList = getChildElements(checkboxTreeDivs.get(0));
102         return (!orderedList.isEmpty());
103     }
104
105     public static boolean checkComplianceCheckExists() throws Exception {
106         WebElement parentDiv = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.VspValidationPage.VSP_VALIDATION_PAGE_COMPLIANCE_CHECKBOX_TREE.getValue());
107         List<WebElement> checkboxTreeDivs = getChildElements(parentDiv);
108         List<WebElement> orderedList = getChildElements(checkboxTreeDivs.get(0));
109         return (!orderedList.isEmpty());
110     }
111
112     public static boolean checkSelectedComplianceCheckExists() throws Exception {
113         WebElement selectedTests = GeneralUIUtils.findElementsByXpath("//div[contains(text(),'Selected Compliance Tests')]/..//select[@class='validation-setup-selected-tests']").get(0);
114         List<WebElement> options = getChildElements(selectedTests);
115         return (!options.isEmpty());
116     }
117
118     public static boolean checkSelectedCertificationQueryExists() throws Exception {
119         WebElement selectedTests = GeneralUIUtils.findElementsByXpath("//div[contains(text(),'Selected Certifications Query')]/..//select[@class='validation-setup-selected-tests']").get(0);
120         List<WebElement> options = getChildElements(selectedTests);
121         return (!options.isEmpty());
122     }
123
124     public static void clickOnElementUsingTestId(DataTestIdEnum.VspValidationPage elementTestId) throws Exception {
125         SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on %s", elementTestId.name()));
126         GeneralUIUtils.getWebElementByTestID(elementTestId.getValue()).click();
127         GeneralUIUtils.ultimateWait();
128     }
129
130     private static List<WebElement> getChildElements(WebElement webElement) throws Exception {
131         return webElement.findElements(By.xpath(".//*"));
132     }
133
134
135 }