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