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