View Interface definition on VFC
[sdc.git] / integration-tests / src / test / java / org / onap / sdc / frontend / ci / tests / pages / component / workspace / InterfaceDefinitionPage.java
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2022 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.ComponentPage;
25 import org.openqa.selenium.By;
26 import org.openqa.selenium.WebDriver;
27 import org.openqa.selenium.WebElement;
28
29 public class InterfaceDefinitionPage extends ComponentPage {
30
31     private WebElement wrappingElement;
32
33     public InterfaceDefinitionPage(final WebDriver webDriver) {
34         super(webDriver);
35     }
36
37     @Override
38     public void isLoaded() {
39         wrappingElement = waitForElementVisibility(By.xpath(XpathSelector.MAIN_DIV.getXpath()), 5);
40         waitForElementVisibility(By.xpath(XpathSelector.TITLE_DIV.getXpath()), 5);
41         waitForElementVisibility(By.xpath(XpathSelector.INTERFACE_NAME_SPAN.getXpath()), 5);
42     }
43
44     public boolean isInterfaceDefinitionOperationPresent(final String operationName) {
45         try {
46             final WebElement webElementInterfaceRow = wrappingElement.findElement(
47                 By.xpath(InterfaceDefinitionPage.XpathSelector.INTERFACE_ROW.getXpath()));
48             webElementInterfaceRow.findElement(By.xpath(InterfaceDefinitionPage.XpathSelector.FIELD_NAME_SPAN.getXpath(operationName)));
49         } catch (final Exception e) {
50             return false;
51         }
52         return true;
53     }
54
55     public InterfaceDefinitionOperationsModal clickOnInterfaceDefinitionOperation(final String operationName) {
56         final WebElement webElementInterfaceRow = wrappingElement.findElement(
57             By.xpath(InterfaceDefinitionPage.XpathSelector.INTERFACE_ROW.getXpath()));
58         webElementInterfaceRow.findElement(By.xpath(InterfaceDefinitionPage.XpathSelector.FIELD_NAME_SPAN.getXpath(operationName))).click();
59         return new InterfaceDefinitionOperationsModal(webDriver);
60     }
61
62     /**
63      * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
64      */
65     @AllArgsConstructor
66     private enum XpathSelector {
67         MAIN_DIV("w-sdc-main-right-container", "//div[@class='%s']"),
68         TITLE_DIV("tab-title", "//div[contains(@class,'%s') and contains(text(), 'Interfaces')]"),
69         INTERFACE_NAME_SPAN("//span[@class='interface-name']"),
70
71         INTERFACE_OPERATIONS("//div[@class='interface-operations']"),
72         OPERATION_LIST("//div[@class='operation-list']"),
73         EXPAND_COLLAPSE("//div[@class='expand-collapse']"),
74         INTERFACE_ACCORDION("//div[@class='interface-accordion']"),
75         INTERFACE_ROW("//div[contains(@class,'interface-row')]"),
76         FIELD_NAME_SPAN("//span[contains(@class,'field-name') and contains(text(), '%s')]"),
77         FIELD_DESCRIPTION_SPAN("//span[contains(@class,'field-description')]");
78
79         @Getter
80         private String id;
81         private final String xpathFormat;
82
83         XpathSelector(final String xpathFormat) {
84             this.xpathFormat = xpathFormat;
85         }
86
87         public String getXpath() {
88             return String.format(xpathFormat, id);
89         }
90
91         public String getXpath(final String... params) {
92             return String.format(xpathFormat, params);
93         }
94
95     }
96 }