c67293939ebf09ce63d9d51aedb11c1ac7f25109
[sdc.git] / integration-tests / src / test / java / org / onap / sdc / frontend / ci / tests / pages / component / workspace / CompositionInterfaceOperationsTab.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.assertNotNull;
23
24 import lombok.AllArgsConstructor;
25 import lombok.Getter;
26 import org.onap.sdc.frontend.ci.tests.pages.AbstractPageObject;
27 import org.openqa.selenium.By;
28 import org.openqa.selenium.WebDriver;
29 import org.openqa.selenium.WebElement;
30
31 /**
32  * Represents the Composition Interface Operations tab.
33  */
34 public class CompositionInterfaceOperationsTab extends AbstractPageObject {
35
36     private WebElement webElement;
37
38     public CompositionInterfaceOperationsTab(final WebDriver webDriver) {
39         super(webDriver);
40     }
41
42     @Override
43     public void isLoaded() {
44         waitForElementVisibility(By.xpath(XpathSelector.INTERFACE_OPERATIONS.getXPath()));
45         waitForElementVisibility(By.xpath(XpathSelector.INTERFACE_NAME_SPAN.getXPath()));
46         webElement = findElement(By.xpath(XpathSelector.OPERATION_LIST.getXPath()));
47     }
48
49     public boolean isOperationPresent(final String operationName) {
50         try {
51             final WebElement webElementInterfaceRow = webElement.findElement(By.xpath(XpathSelector.INTERFACE_ROW.getXPath()));
52             webElementInterfaceRow.findElement(By.xpath(XpathSelector.FIELD_NAME_SPAN.getXPath(operationName)));
53         } catch (final Exception e) {
54             return false;
55         }
56         return true;
57     }
58
59     public boolean isDescriptionPresent() {
60         try {
61             final WebElement webElementInterfaceRow = webElement.findElement(By.xpath(XpathSelector.INTERFACE_ROW.getXPath()));
62             final WebElement rowElement = webElementInterfaceRow.findElement(By.xpath(XpathSelector.FIELD_DESCRIPTION_SPAN.getXPath()));
63             return rowElement != null && !rowElement.getText().isEmpty();
64         } catch (final Exception e) {
65             return false;
66         }
67     }
68
69     public CompositionInterfaceOperationsModal clickOnOperation(final String operationName) {
70         final WebElement webElementInterfaceRow = webElement.findElement(By.xpath(XpathSelector.INTERFACE_ROW.getXPath()));
71         webElementInterfaceRow.findElement(By.xpath(XpathSelector.FIELD_NAME_SPAN.getXPath(operationName))).click();
72         return new CompositionInterfaceOperationsModal(webDriver);
73     }
74
75     @AllArgsConstructor
76     private enum XpathSelector {
77         INTERFACE_OPERATIONS("//div[@class='interface-operations']"),
78         OPERATION_LIST("//div[@class='operation-list']"),
79         EXPAND_COLLAPSE("//div[@class='expand-collapse']"),
80         INTERFACE_ACCORDION("//div[@class='interface-accordion']"),
81         INTERFACE_ROW("//div[contains(@class,'interface-row')]"),
82         INTERFACE_NAME_SPAN("//span[@class='interface-name']"),
83         FIELD_NAME_SPAN("//span[contains(@class,'field-name') and contains(text(), '%s')]"),
84         FIELD_DESCRIPTION_SPAN("//span[contains(@class,'field-description')]");
85
86         @Getter
87         private final String xPath;
88
89         public String getXPath(final String... xpathParams) {
90             return String.format(xPath, xpathParams);
91         }
92
93     }
94 }