Support for selection of capabilities
[sdc.git] / integration-tests / src / test / java / org / onap / sdc / frontend / ci / tests / pages / component / workspace / CompositionRequirementsCapabilitiesTab.java
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2021 Nordix Foundation
4  *  ================================================================================
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
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  *  SPDX-License-Identifier: Apache-2.0
17  *  ============LICENSE_END=========================================================
18  */
19
20 package org.onap.sdc.frontend.ci.tests.pages.component.workspace;
21
22 import static org.junit.jupiter.api.Assertions.fail;
23
24 import java.util.HashMap;
25 import java.util.List;
26 import java.util.Map;
27 import lombok.AllArgsConstructor;
28 import lombok.Getter;
29 import org.onap.sdc.frontend.ci.tests.flow.exception.UiTestFlowRuntimeException;
30 import org.onap.sdc.frontend.ci.tests.pages.AbstractPageObject;
31 import org.onap.sdc.frontend.ci.tests.utilities.LoaderHelper;
32 import org.openqa.selenium.By;
33 import org.openqa.selenium.WebDriver;
34 import org.openqa.selenium.WebElement;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37
38 /**
39  * Represents the composition page, details panel, Substitution Filters tab.
40  */
41 public class CompositionRequirementsCapabilitiesTab extends AbstractPageObject {
42
43     private static final Logger LOGGER = LoggerFactory.getLogger(CompositionRequirementsCapabilitiesTab.class);
44
45     private Map<String, WebElement> checkboxExternalRequirementMap;
46     private final LoaderHelper loaderHelper;
47
48     public CompositionRequirementsCapabilitiesTab(final WebDriver webDriver) {
49         super(webDriver);
50         loaderHelper = new LoaderHelper(webDriver);
51     }
52
53     @Override
54     public void isLoaded() {
55         waitForElementVisibility(By.xpath(XpathSelector.REQ_CAPABILITIES_TAB.getXPath()));
56         waitForElementVisibility(By.xpath(XpathSelector.CAPABILITIES_ACCORDION.getXPath()));
57         waitForElementVisibility(By.xpath(XpathSelector.REQUIREMENTS_ACCORDION.getXPath()));
58     }
59
60     public void clickOnRequirements() {
61         waitForElementVisibility(XpathSelector.REQUIREMENTS_ACCORDION.getXPath()).click();
62         loadRequirements();
63     }
64
65     public void clickOnCapabilities() {
66         waitForElementVisibility(XpathSelector.CAPABILITIES_ACCORDION.getXPath()).click();
67     }
68
69     private void loadRequirements() {
70         final List<WebElement> webElements = waitForAllElementsVisibility(By.xpath(XpathSelector.REQUIREMENT_EXTERNAL_CHECKBOX.getXPath()));
71         checkboxExternalRequirementMap = new HashMap<>();
72         webElements.forEach(webElement -> {
73             final String dataTestsId = webElement.getAttribute("data-tests-id");
74             checkboxExternalRequirementMap.put(dataTestsId.substring("checkbox-external-req-".length()), webElement);
75         });
76     }
77
78     public void toggleRequirementAsExternal(final String requirementName) {
79         LOGGER.debug("Externalizing the requirement '{}'", requirementName);
80         if (checkboxExternalRequirementMap == null) {
81             throw new UiTestFlowRuntimeException("The requirements checkbox map is not loaded. Did you call clickOnRequirements?");
82         }
83         final WebElement element = checkboxExternalRequirementMap.get(requirementName);
84         if (element == null) {
85             fail(String.format("Could not find requirement '%s'", requirementName));
86         }
87         element.click();
88         loaderHelper.waitForLoader(LoaderHelper.XpathSelector.LOADER_WITH_LOADER_BACKGROUND, 10);
89     }
90
91
92     @AllArgsConstructor
93     @Getter
94     private enum XpathSelector {
95         REQ_CAPABILITIES_TAB("//req-capabilities-tab"),
96         CAPABILITIES_ACCORDION("//div[@data-tests-id='Capabilities-accordion']"),
97         REQUIREMENTS_ACCORDION("//div[@data-tests-id='Requirements-accordion']"),
98         REQUIREMENT_EXTERNAL_CHECKBOX("//checkbox[starts-with(@data-tests-id, 'checkbox-external-req-')]");
99
100         private final String xPath;
101
102     }
103 }