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