Catalog alignment
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / pages / ResourcePropertiesAssignmentPage.java
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.openecomp.sdc.ci.tests.pages;
21
22 import org.openqa.selenium.By;
23 import org.openqa.selenium.WebDriver;
24 import org.openqa.selenium.WebElement;
25 import org.openqa.selenium.support.ui.ExpectedConditions;
26
27 import java.util.ArrayList;
28 import java.util.List;
29
30 import static org.openecomp.sdc.ci.tests.pages.ResourcePropertiesAssignmentPage.XpathSelector.MAIN_DIV;
31 import static org.openecomp.sdc.ci.tests.pages.ResourcePropertiesAssignmentPage.XpathSelector.NO_DATA_MESSAGE;
32 import static org.openecomp.sdc.ci.tests.pages.ResourcePropertiesAssignmentPage.XpathSelector.PROPERTIES_TABLE;
33 import static org.openecomp.sdc.ci.tests.pages.ResourcePropertiesAssignmentPage.XpathSelector.SOFTWARE_VERSION_INPUT;
34 import static org.openecomp.sdc.ci.tests.pages.ResourcePropertiesAssignmentPage.XpathSelector.SOFTWARE_VERSION_PROPERTY_CHECKBOX;
35 import static org.openecomp.sdc.ci.tests.pages.ResourcePropertiesAssignmentPage.XpathSelector.TITLE_DIV;
36
37 /**
38  * Handles the Resource Properties Assignment Page UI actions
39  */
40 public class ResourcePropertiesAssignmentPage extends AbstractPageObject {
41
42     private WebElement wrappingElement;
43
44     public ResourcePropertiesAssignmentPage(final WebDriver webDriver) {
45         super(webDriver);
46     }
47
48     @Override
49     public void isLoaded() {
50         wrappingElement = getWait(5)
51             .until(ExpectedConditions.visibilityOfElementLocated(By.xpath(MAIN_DIV.getXpath())));
52         getWait(5)
53             .until(ExpectedConditions.visibilityOfElementLocated(By.xpath(TITLE_DIV.getXpath())));
54     }
55
56     /**
57      * Gets the software_version property values.
58      *
59      * @return the list of software versions found
60      */
61     public List<String> getSoftwareVersionProperty() {
62         waitPropertiesToLoad();
63         final By swVersionCheckboxLocator = By.xpath(SOFTWARE_VERSION_PROPERTY_CHECKBOX.getXpath());
64         getWait(5).until(ExpectedConditions.visibilityOfElementLocated(swVersionCheckboxLocator));
65
66         final List<String> softwareVersionList = new ArrayList<>();
67         final List<WebElement> elements = wrappingElement.findElements(By.xpath(SOFTWARE_VERSION_INPUT.getXpath()));
68         for (final WebElement element : elements) {
69             softwareVersionList.add(element.getAttribute("value"));
70         }
71
72         return softwareVersionList;
73     }
74
75     /**
76      * Waits for the properties loading.
77      */
78     private void waitPropertiesToLoad() {
79         getWait(5)
80             .until(ExpectedConditions.visibilityOfElementLocated(By.xpath(PROPERTIES_TABLE.getXpath())));
81         getWait(5)
82             .until(ExpectedConditions.invisibilityOfElementLocated(By.xpath(NO_DATA_MESSAGE.getXpath())));
83     }
84
85     /**
86      * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
87      */
88     public enum XpathSelector {
89         MAIN_DIV("w-sdc-main-right-container", "//div[@class='%s']"),
90         TITLE_DIV("tab-title", "//div[contains(@class,'%s') and contains(text(), 'Properties Assignment')]"),
91         PROPERTIES_TABLE("properties-table", "//div[contains(@class,'%s')]"),
92         NO_DATA_MESSAGE("no-data", "//div[contains(@class,'%s') and text()='No data to display']"),
93         SOFTWARE_VERSION_PROPERTY_CHECKBOX("software_versions", "//checkbox[@data-tests-id='%s']"),
94         SOFTWARE_VERSION_INPUT("value-prop-software_versions.", "//input[starts-with(@data-tests-id,'%s')]");
95
96         private final String id;
97         private final String xpathFormat;
98
99         XpathSelector(final String id, final String xpathFormat) {
100             this.id = id;
101             this.xpathFormat = xpathFormat;
102         }
103
104         public String getId() {
105             return id;
106         }
107
108         public String getXpath() {
109             return String.format(xpathFormat, id);
110         }
111     }
112
113 }