81c46a7907fe836df55347227ec5f680a5cbb27f
[sdc.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 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;
21
22 import com.aventstack.extentreports.Status;
23 import java.util.List;
24 import java.util.Map;
25 import lombok.AllArgsConstructor;
26 import lombok.Getter;
27 import org.onap.sdc.frontend.ci.tests.execute.setup.ExtentTestActions;
28 import org.openqa.selenium.By;
29 import org.openqa.selenium.WebDriver;
30
31 /**
32  * Handles the Resource Properties Assignment Page UI actions.
33  */
34 public class ResourcePropertiesAssignmentPage extends ComponentPage {
35
36     private ResourcePropertiesAssignmentTab resourcePropertiesAssignmentTab;
37     private ResourcePropertiesAssignmentInputTab resourcePropertiesAssignmentInputTab;
38
39     public ResourcePropertiesAssignmentPage(final WebDriver webDriver) {
40         super(webDriver);
41         resourcePropertiesAssignmentTab = new ResourcePropertiesAssignmentTab(webDriver);
42         resourcePropertiesAssignmentInputTab = new ResourcePropertiesAssignmentInputTab(webDriver);
43     }
44
45     @Override
46     public void isLoaded() {
47         super.isLoaded();
48         waitForElementVisibility(XpathSelector.MAIN_DIV.getXpath());
49         waitForElementVisibility(XpathSelector.TITLE_DIV.getXpath());
50         resourcePropertiesAssignmentTab.isLoaded();
51     }
52
53     /**
54      * Select the Properties Tab to be displayed
55      */
56     public void selectPropertiesTab() {
57         findElement(XpathSelector.PROPERTIES_TAB.getXpath()).click();
58         resourcePropertiesAssignmentTab.isLoaded();
59     }
60
61     /**
62      * Select the Input Tab to be displayed
63      */
64     public void selectInputTab() {
65         findElement(XpathSelector.INPUT_TAB.getXpath()).click();
66         resourcePropertiesAssignmentInputTab.isLoaded();
67     }
68
69     public List<String> getSoftwareVersionProperty() {
70         return resourcePropertiesAssignmentTab.getSoftwareVersionProperty();
71     }
72
73     public void setPropertyValue(final String propertyName, final Object value) {
74         resourcePropertiesAssignmentTab.setPropertyValue(propertyName, value);
75     }
76
77     public void setInputValue(final String inputName, final Object value) {
78         resourcePropertiesAssignmentInputTab.setInputValue(inputName, value);
79     }
80
81     /**
82      * Retrieves a property value.
83      *
84      * @param propertyName the property name
85      * @return the property value
86      */
87     public Object getPropertyValue(final String propertyName) {
88         return resourcePropertiesAssignmentTab.getPropertyValue(propertyName);
89     }
90
91     public boolean isPropertyPresent(final String propertyName) {
92         return resourcePropertiesAssignmentTab.isPropertyPresent(propertyName);
93     }
94
95     public boolean isInputPresent(final String inputName) {
96         return resourcePropertiesAssignmentInputTab.isInputPresent(inputName);
97     }
98
99     /**
100      * Saves a property
101      */
102     public void saveProperties() {
103         resourcePropertiesAssignmentTab.saveProperties();
104     }
105
106     public void saveInputs() {
107         resourcePropertiesAssignmentInputTab.saveInputProperties();
108     }
109
110     public void addProperties(final Map<String, String> propertiesMap) {
111         resourcePropertiesAssignmentTab.addProperties(propertiesMap);
112     }
113
114     public void addInputs(final Map<String, String> inputsMap) {
115         resourcePropertiesAssignmentInputTab.addInputs(inputsMap);
116     }
117
118     public void verifyInputs(final Map<String, String> inputsMap) {
119         resourcePropertiesAssignmentInputTab.verifyInputs(inputsMap);
120     }
121
122     public Map<String, String> getPropertyNamesAndTypes() {
123         return resourcePropertiesAssignmentTab.getPropertyNamesAndTypes();
124     }
125
126     public void setInputPropertyMetadata(String name, String key, String value) {
127         resourcePropertiesAssignmentInputTab.setInputPropertyMetadata(name, key, value);
128     }
129
130     public List<String> getInputPropertyNames() {
131         return resourcePropertiesAssignmentInputTab.getInputPropertyNames();
132     }
133
134     /**
135      * select property
136      */
137     public void selectProperty(String propertyName) {
138         resourcePropertiesAssignmentTab.selectProperty(propertyName);
139     }
140
141     public void loadComponentInstanceProperties(final String instanceName) {
142         resourcePropertiesAssignmentTab.loadComponentInstanceProperties(instanceName);
143     }
144
145     public void clickOnDeclareInput() {
146         resourcePropertiesAssignmentTab.clickOnDeclareInput();
147     }
148
149     public void loadCompositionTab() {
150         resourcePropertiesAssignmentTab.loadCompositionTab();
151     }
152
153     public void clickInputTab(String propertyName) {
154         waitForElementVisibility(By.xpath(XpathSelector.DECLARE_NOTIFIFICATION.getXpath()));
155         ExtentTestActions.takeScreenshot(Status.INFO, "Declare-Input", String.format("Added declared input for property %s", propertyName));
156         selectInputTab();
157     }
158
159     /**
160      * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
161      */
162     @AllArgsConstructor
163     private enum XpathSelector {
164         MAIN_DIV("w-sdc-main-right-container", "//div[@class='%s']"),
165         TITLE_DIV("tab-title", "//div[contains(@class,'%s') and contains(text(), 'Properties Assignment')]"),
166         PROPERTIES_TAB("//*[contains(@data-tests-id, 'Properties') and contains(@class, 'tab')]"),
167         INPUT_TAB("//*[contains(@data-tests-id, 'Inputs') and contains(@class, 'tab')]"),
168         DECLARE_NOTIFIFICATION("//div[@data-tests-id='Inputs']/div[contains(@class, 'tab-indication')]");
169
170         @Getter
171         private String id;
172         private final String xpathFormat;
173
174         XpathSelector(final String xpathFormat) {
175             this.xpathFormat = xpathFormat;
176         }
177
178         public String getXpath() {
179             return String.format(xpathFormat, id);
180         }
181     }
182
183 }