cb2ee3d282699947653f1ff0a98ce7111c6631d8
[sdc.git] / integration-tests / src / test / java / org / onap / sdc / frontend / ci / tests / pages / component / workspace / InterfaceDefinitionOperationsModal.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 com.aventstack.extentreports.Status;
23 import lombok.AllArgsConstructor;
24 import lombok.Getter;
25 import org.onap.sdc.frontend.ci.tests.execute.setup.ExtentTestActions;
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 Modal.
33  */
34 public class InterfaceDefinitionOperationsModal extends AbstractPageObject {
35
36     public InterfaceDefinitionOperationsModal(final WebDriver webDriver) {
37         super(webDriver);
38     }
39
40     @Override
41     public void isLoaded() {
42         waitForElementVisibility(By.xpath(XpathSelector.TITLE_SPAN.getXPath()));
43         waitForElementVisibility(By.xpath(XpathSelector.INTERFACE_NAME_LABEL.getXPath()));
44         waitForElementVisibility(By.xpath(XpathSelector.OPERATION_NAME_LABEL.getXPath()));
45         waitForElementVisibility(By.xpath(XpathSelector.INPUT_NAME_SPAN.getXPath()));
46         waitForElementVisibility(By.xpath(XpathSelector.INPUT_VALUE_SPAN.getXPath()));
47         waitForElementVisibility(By.xpath(XpathSelector.ADD_INPUT_BTN.getXPath()));
48         waitForElementVisibility(By.xpath(XpathSelector.SAVE_BTN.getXPath()));
49         waitToBeClickable(By.xpath(XpathSelector.CANCEL_BTN.getXPath()));
50     }
51
52     public void clickOnSave() {
53         waitToBeClickable(By.xpath(XpathSelector.SAVE_BTN.getXPath())).click();
54     }
55
56     public void clickOnCancel() {
57         waitToBeClickable(By.xpath(XpathSelector.CANCEL_BTN.getXPath())).click();
58     }
59
60     public void clickOnDelete() {
61         waitToBeClickable(By.xpath(XpathSelector.DELETE_BTN.getXPath())).click();
62     }
63
64     public void updateInterfaceOperation(final InterfaceOperationsData interfaceOperationsData) {
65         fillDescription(interfaceOperationsData.getDescription());
66         fillImplementationName(interfaceOperationsData.getImplementationName());
67         fillInputName(interfaceOperationsData.getInputName());
68         fillInputValue(interfaceOperationsData.getInputValue());
69         clickOnSave();
70     }
71
72     private void fillDescription(final String description) {
73         setInputField(By.xpath(XpathSelector.INTERFACE_OPERATION_DESCRIPTION_INPUT.getXPath()), description);
74     }
75
76     private void fillImplementationName(final String implementationName) {
77         setInputField(By.xpath(XpathSelector.INTERFACE_OPERATION_IMPLEMENTATION_NAME_INPUT.getXPath()), implementationName);
78     }
79
80     private void fillInputName(final String inputName) {
81         setInputField(By.xpath(XpathSelector.FIELD_INPUT_NAME_INPUT.getXPath()), inputName);
82     }
83
84     private void fillInputValue(final String inputValue) {
85         setInputField(By.xpath(XpathSelector.FIELD_INPUT_VALUE_INPUT.getXPath()), inputValue);
86     }
87
88     private void setInputField(final By locator, final String value) {
89         if (value == null) {
90             return;
91         }
92         final WebElement webElement = findElement(locator);
93         webElement.clear();
94         webElement.sendKeys(value);
95         ExtentTestActions.takeScreenshot(Status.INFO, value, value);
96     }
97
98     public void addInput() {
99         waitToBeClickable(By.xpath(XpathSelector.ADD_INPUT_BTN.getXPath())).click();
100     }
101
102     public String getDescription() {
103         return findElement(By.xpath(XpathSelector.INTERFACE_OPERATION_DESCRIPTION_INPUT.getXPath())).getAttribute("value");
104     }
105
106     public String getImplementationName() {
107         return findElement(By.xpath(XpathSelector.INTERFACE_OPERATION_IMPLEMENTATION_NAME_INPUT.getXPath())).getAttribute("value");
108     }
109
110     public String getInputName() {
111         return findElement(By.xpath(XpathSelector.FIELD_INPUT_NAME_INPUT.getXPath())).getAttribute("value");
112     }
113
114     public String getInputValue() {
115         return findElement(By.xpath(XpathSelector.FIELD_INPUT_VALUE_INPUT.getXPath())).getAttribute("value");
116     }
117
118     @Getter
119     @AllArgsConstructor
120     public static class InterfaceOperationsData {
121
122         private final String description;
123         private final String implementationName;
124         private final String inputName;
125         private final String inputValue;
126     }
127
128     @AllArgsConstructor
129     private enum XpathSelector {
130         TITLE_SPAN("//span[@class='title' and contains(text(), 'Edit Operation')]"),
131         ADD_INPUT_BTN("//a[contains(@class,'add-param-link add-btn') and contains(text(), 'Add Input')]"),
132         DELETE_BTN("//svg-icon[@name='trash-o']"),
133         SAVE_BTN("//button[@data-tests-id='Save']"),
134         CANCEL_BTN("//button[@data-tests-id='Cancel']"),
135         INTERFACE_NAME_LABEL("//label[contains(@class,'sdc-input') and contains(text(), 'Interface Name')]"),
136         OPERATION_NAME_LABEL("//label[contains(@class,'sdc-input') and contains(text(), 'Operation Name')]"),
137         INTERFACE_OPERATION_DESCRIPTION_INPUT("//input[@data-tests-id='interface-operation-description']"),
138         INTERFACE_OPERATION_IMPLEMENTATION_NAME_INPUT("//input[@data-tests-id='interface-operation-implementation-name']"),
139         INPUT_NAME_SPAN("//span[contains(@class,'field-input-name') and contains(text(), 'Name')]"),
140         INPUT_VALUE_SPAN("//span[contains(@class,'field-input-value') and contains(text(), 'Value')]"),
141         FIELD_INPUT_NAME_INPUT("//input[@data-tests-id='interface-operation-input-name']"),
142         FIELD_INPUT_VALUE_INPUT("//input[@data-tests-id='interface-operation-input-value']");
143
144         @Getter
145         private final String xPath;
146
147     }
148 }