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
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.
16 * SPDX-License-Identifier: Apache-2.0
17 * ============LICENSE_END=========================================================
20 package org.onap.sdc.frontend.ci.tests.pages.component.workspace;
22 import static org.junit.jupiter.api.Assertions.fail;
24 import java.util.HashMap;
25 import java.util.List;
27 import lombok.AllArgsConstructor;
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;
39 * Represents the composition page, details panel, Substitution Filters tab.
41 public class CompositionRequirementsCapabilitiesTab extends AbstractPageObject {
43 private static final Logger LOGGER = LoggerFactory.getLogger(CompositionRequirementsCapabilitiesTab.class);
45 private Map<String, WebElement> checkboxExternalRequirementMap;
46 private final LoaderHelper loaderHelper;
48 public CompositionRequirementsCapabilitiesTab(final WebDriver webDriver) {
50 loaderHelper = new LoaderHelper(webDriver);
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()));
60 public void clickOnRequirements() {
61 waitForElementVisibility(XpathSelector.REQUIREMENTS_ACCORDION.getXPath()).click();
65 public void clickOnCapabilities() {
66 waitForElementVisibility(XpathSelector.CAPABILITIES_ACCORDION.getXPath()).click();
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);
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?");
83 final WebElement element = checkboxExternalRequirementMap.get(requirementName);
84 if (element == null) {
85 fail(String.format("Could not find requirement '%s'", requirementName));
88 loaderHelper.waitForLoader(LoaderHelper.XpathSelector.LOADER_WITH_LOADER_BACKGROUND, 10);
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-')]");
100 private final String xPath;