Provide user to specify the ouput name while declaring the atrributes
[sdc.git] / integration-tests / src / test / java / org / onap / sdc / frontend / ci / tests / pages / ResourcePropertiesPage.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;
21
22 import java.util.HashMap;
23 import java.util.List;
24 import java.util.Map;
25
26 import org.openqa.selenium.By;
27 import org.openqa.selenium.WebDriver;
28 import org.openqa.selenium.WebElement;
29
30 import lombok.AllArgsConstructor;
31 import lombok.Getter;
32
33 /**
34  * Handles the Resource Properties Page UI actions
35  */
36 public class ResourcePropertiesPage extends AbstractPageObject {
37
38     public ResourcePropertiesPage(final WebDriver webDriver) {
39         super(webDriver);
40     }
41
42     @Override
43     public void isLoaded() {
44         waitForElementVisibility(By.xpath(XpathSelector.TITLE_DIV.getXpath()));
45         waitPropertiesToLoad();
46     }
47
48     /**
49      * Waits for the properties table to load.
50      */
51     private void waitPropertiesToLoad() {
52         waitForElementVisibility(By.xpath(XpathSelector.PROPERTIES_TABLE.getXpath()));
53         waitForElementInvisibility(By.xpath(XpathSelector.NO_DATA_MESSAGE.getXpath()));
54     }
55
56     /**
57      * Creates a map based on property names and data types
58      */
59     public Map<String, String> getPropertyNamesAndTypes() {
60         waitPropertiesToLoad();
61         final Map<String, String> namesAndTypes = new HashMap<>();
62         final List<WebElement> names = findElements(By.xpath(XpathSelector.PROPERTY_NAMES.getXpath()));
63         final List<WebElement> types = findElements(By.xpath(XpathSelector.PROPERTY_TYPES.getXpath()));
64
65         for (int i = 0;i < names.size();i++) {
66             namesAndTypes.put(names.get(i).getAttribute("innerText"), types.get(i).getAttribute("innerText"));
67         }
68
69         return namesAndTypes;
70     }
71
72     @AllArgsConstructor
73     @Getter
74     private enum XpathSelector {
75         TITLE_DIV("//div[contains(@class,'tab-title') and contains(text(), 'Properties')]"),
76         PROPERTIES_TABLE("//div[contains(@class,'table')]"),
77         NO_DATA_MESSAGE("//div[contains(@class,'no-data') and text()='No data to display']"),
78         PROPERTY_TYPES("//*[contains(@data-tests-id, 'propertyType')]"),
79         PROPERTY_NAMES("//*[contains(@data-tests-id, 'propertyName')]");
80
81         private final String xpath;
82     }
83
84 }