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