e69f1131e5ac522e4ce7426f480a8b4c71dbdbf6
[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 java.util.List;
23 import java.util.Map;
24
25 import org.openqa.selenium.By;
26 import org.openqa.selenium.WebDriver;
27
28 import lombok.AllArgsConstructor;
29 import lombok.Getter;
30
31 /**
32  * Handles the Resource Properties Assignment Page UI actions.
33  */
34 public class ResourcePropertiesAssignmentPage extends AbstractPageObject {
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         waitForElementVisibility((By.xpath(XpathSelector.MAIN_DIV.getXpath())));
48         waitForElementVisibility(By.xpath(XpathSelector.TITLE_DIV.getXpath()));
49         resourcePropertiesAssignmentTab.isLoaded();
50     }
51
52     /**
53      * Select the Properties Tab to be displayed
54      */
55     public void selectPropertiesTab() {
56         findElement(By.xpath(XpathSelector.PROPERTIES_TAB.getXpath())).click();
57         resourcePropertiesAssignmentTab.isLoaded();
58     }
59
60     /**
61      * Select the Input Tab to be displayed
62      */
63     public void selectInputTab() {
64         findElement(By.xpath(XpathSelector.INPUT_TAB.getXpath())).click();
65         resourcePropertiesAssignmentInputTab.isLoaded();
66     }
67
68     public List<String> getSoftwareVersionProperty() {
69         return resourcePropertiesAssignmentTab.getSoftwareVersionProperty();
70     }
71
72     public void setPropertyValue(final String propertyName, final Object value) {
73         resourcePropertiesAssignmentTab.setPropertyValue(propertyName, value);
74     }
75
76     public boolean isPropertyPresent(final String propertyName) {
77         return resourcePropertiesAssignmentTab.isPropertyPresent(propertyName);
78     }
79
80     public void saveProperties() {
81         resourcePropertiesAssignmentTab.saveProperties();
82     }
83
84     public void addProperties(final Map<String, String> propertiesMap) {
85         resourcePropertiesAssignmentTab.addProperties(propertiesMap);
86     }
87
88     public Map<String, String> getPropertyNamesAndTypes() {
89         return resourcePropertiesAssignmentTab.getPropertyNamesAndTypes();
90     }
91
92     public void setInputPropertyMetadata(String name, String key, String value) {
93         resourcePropertiesAssignmentInputTab.setInputPropertyMetadata(name, key, value);
94     }
95
96     public List<String> getInputPropertyNames() {
97         return resourcePropertiesAssignmentInputTab.getInputPropertyNames();
98     }
99
100     /**
101      * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
102      */
103     @AllArgsConstructor
104     private enum XpathSelector {
105         MAIN_DIV("w-sdc-main-right-container", "//div[@class='%s']"),
106         TITLE_DIV("tab-title", "//div[contains(@class,'%s') and contains(text(), 'Properties Assignment')]"),
107         PROPERTIES_TAB("//*[contains(@data-tests-id, 'Properties') and contains(@class, 'tab')]"),
108         INPUT_TAB("//*[contains(@data-tests-id, 'Inputs') and contains(@class, 'tab')]");
109
110         @Getter
111         private String id;
112         private final String xpathFormat;
113
114         XpathSelector(final String xpathFormat) {
115             this.xpathFormat = xpathFormat;
116         }
117
118         public String getXpath() {
119             return String.format(xpathFormat, id);
120         }
121     }
122
123 }