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.hamcrest.MatcherAssert.assertThat;
23 import static org.hamcrest.Matchers.is;
25 import lombok.AllArgsConstructor;
27 import org.onap.sdc.frontend.ci.tests.pages.AbstractPageObject;
28 import org.openqa.selenium.By;
29 import org.openqa.selenium.Dimension;
30 import org.openqa.selenium.WebDriver;
31 import org.openqa.selenium.WebElement;
33 public class CompositionDetailSideBarComponent extends AbstractPageObject {
35 private WebElement wrappingElement;
37 public CompositionDetailSideBarComponent(final WebDriver webDriver) {
42 public void isLoaded() {
43 wrappingElement = waitForElementVisibility(By.xpath(XpathSelector.MAIN_ELEMENT_DIV.getXpath()));
46 public String getSelectedComponentName() {
47 return wrappingElement.findElement(By.xpath(XpathSelector.DETAIL_COMPONENT_NAME_DIV.getXpath())).getText();
50 public void checkComponentIsSelected(final String componentName) {
51 assertThat("The selected component should be as expected", getSelectedComponentName(), is(componentName));
54 public Dimension getSize() {
55 final WebElement sideBarToggle = waitForElementVisibility(XpathSelector.DETAIL_SIDE_BAR_TOGGLE_DIV.getXpath());
56 if (!sideBarToggle.getAttribute("class").contains("active")) {
57 return new Dimension(0, 0);
60 return wrappingElement.getSize();
63 public AbstractPageObject selectTab(final CompositionDetailTabName tabName) {
64 final WebElement tabElement = wrappingElement.findElement(By.xpath(tabName.getXpathSelector().getXpath()));
68 return new CompositionInformationTab(webDriver);
70 return new CompositionInputsTab(webDriver);
71 case DEPLOYMENT_ARTIFACTS:
72 return new CompositionDeploymentArtifactsTab(webDriver);
73 case INFORMATIONAL_ARTIFACTS:
74 return new CompositionInformationalArtifactsTab(webDriver);
76 return new CompositionApiArtifactsTab(webDriver);
77 case SUBSTITUTION_FILTER:
78 return new CompositionSubstitutionFilterTab(webDriver);
80 throw new IllegalStateException("Not yet implemented: " + tabName);
85 * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
88 private enum XpathSelector {
89 MAIN_ELEMENT_DIV("w-sdc-designer-sidebar", "//div[@class='%s']"),
90 DETAIL_SIDE_BAR_TOGGLE_DIV("w-sdc-designer-sidebar-toggle", "//div[contains(concat(' ',normalize-space(@class),' '),' %s ')]"),
91 DETAIL_HEADER("w-sdc-designer-sidebar-head", "//div[@data-tests-id='%s']"),
92 DETAIL_COMPONENT_NAME_DIV("selectedCompTitle", "//div[@data-tests-id='%s']"),
93 TAB_LIST("sdc-tabs-list", "//ul[@class='%s']/li"),
94 INFORMATION_TAB("detail-tab-information", "//li[@data-tests-id='%s']"),
95 INPUTS_TAB("detail-tab-inputs", "//li[@data-tests-id='%s']"),
96 DEPLOYMENT_ARTIFACTS_TAB("detail-tab-deployment-artifacts", "//li[@data-tests-id='%s']"),
97 INFORMATION_ARTIFACTS_TAB("detail-tab-information-artifacts", "//li[@data-tests-id='%s']"),
98 API_ARTIFACTS_TAB("detail-tab-api-artifacts", "//li[@data-tests-id='%s']"),
99 SUBSTITUTION_FILTER_TAB("detail-tab-substitution-filter", "//li[@data-tests-id='%s']");
102 private final String id;
103 private final String xpathFormat;
105 public String getXpath() {
106 return String.format(xpathFormat, id);
112 public enum CompositionDetailTabName {
113 INFORMATION(XpathSelector.INFORMATION_TAB),
114 INPUTS(XpathSelector.INPUTS_TAB),
115 DEPLOYMENT_ARTIFACTS(XpathSelector.DEPLOYMENT_ARTIFACTS_TAB),
116 INFORMATIONAL_ARTIFACTS(XpathSelector.INFORMATION_ARTIFACTS_TAB),
117 API_ARTIFACTS(XpathSelector.API_ARTIFACTS_TAB),
118 SUBSTITUTION_FILTER(XpathSelector.SUBSTITUTION_FILTER_TAB);
120 private final XpathSelector xpathSelector;