4db048be09c137ae7632ee984dead7068979a0c8
[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 addProperties(final Map<String, String> propertiesMap) {
94         resourcePropertiesAssignmentTab.addProperties(propertiesMap);
95     }
96
97     public Map<String, String> getPropertyNamesAndTypes() {
98         return resourcePropertiesAssignmentTab.getPropertyNamesAndTypes();
99     }
100
101     public void setInputPropertyMetadata(String name, String key, String value) {
102         resourcePropertiesAssignmentInputTab.setInputPropertyMetadata(name, key, value);
103     }
104
105     public List<String> getInputPropertyNames() {
106         return resourcePropertiesAssignmentInputTab.getInputPropertyNames();
107     }
108
109     /**
110      * select property
111      */
112     public void selectProperty(String propertyName){
113         resourcePropertiesAssignmentTab.selectProperty(propertyName);
114     }
115
116     public void loadComponentInstanceProperties(final String instanceName){
117         resourcePropertiesAssignmentTab.loadComponentInstanceProperties(instanceName);
118     }
119
120     public void clickOnDeclareInput(){
121         resourcePropertiesAssignmentTab.clickOnDeclareInput();
122     }
123
124     public void loadCompositionTab(){
125         resourcePropertiesAssignmentTab.loadCompositionTab();
126     }
127
128     public void clickInputTab(String propertyName){
129         waitForElementVisibility(By.xpath(XpathSelector.DECLARE_NOTIFIFICATION.getXpath()));
130         ExtentTestActions.takeScreenshot(Status.INFO, "Declare-Input", String.format("Added declared input for property %s", propertyName));
131         selectInputTab();
132     }
133
134     /**
135      * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
136      */
137     @AllArgsConstructor
138     private enum XpathSelector {
139         MAIN_DIV("w-sdc-main-right-container", "//div[@class='%s']"),
140         TITLE_DIV("tab-title", "//div[contains(@class,'%s') and contains(text(), 'Properties Assignment')]"),
141         PROPERTIES_TAB("//*[contains(@data-tests-id, 'Properties') and contains(@class, 'tab')]"),
142         INPUT_TAB("//*[contains(@data-tests-id, 'Inputs') and contains(@class, 'tab')]"),
143         DECLARE_NOTIFIFICATION("//div[@data-tests-id='Inputs']/div[contains(@class, 'tab-indication')]");
144
145         @Getter
146         private String id;
147         private final String xpathFormat;
148
149         XpathSelector(final String xpathFormat) {
150             this.xpathFormat = xpathFormat;
151         }
152
153         public String getXpath() {
154             return String.format(xpathFormat, id);
155         }
156     }
157
158 }