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