Onboard PNF software version Ui test case
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / pages / VspRepositoryModalComponent.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.hamcrest.Matchers.empty;
23 import static org.hamcrest.core.Is.is;
24 import static org.hamcrest.core.IsNot.not;
25 import static org.junit.Assert.assertThat;
26 import static org.openecomp.sdc.ci.tests.pages.VspRepositoryModalComponent.XpathSelector.IMPORT_VSP_BTN;
27 import static org.openecomp.sdc.ci.tests.pages.VspRepositoryModalComponent.XpathSelector.MODAL_DIV;
28 import static org.openecomp.sdc.ci.tests.pages.VspRepositoryModalComponent.XpathSelector.RESULTS_CONTAINER_DIV;
29 import static org.openecomp.sdc.ci.tests.pages.VspRepositoryModalComponent.XpathSelector.SEARCH_TXT;
30
31 import java.util.List;
32 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
33 import org.openecomp.sdc.ci.tests.utilities.LoaderHelper;
34 import org.openecomp.sdc.ci.tests.utilities.NotificationHelper;
35 import org.openqa.selenium.By;
36 import org.openqa.selenium.WebDriver;
37 import org.openqa.selenium.WebElement;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40
41 /**
42  * Handles the VSP Repository Modal UI actions
43  */
44 public class VspRepositoryModalComponent extends AbstractPageObject {
45
46     private static final Logger LOGGER = LoggerFactory.getLogger(VspRepositoryModalComponent.class);
47
48     private WebElement wrappingElement;
49
50     public VspRepositoryModalComponent(final WebDriver webDriver) {
51         super(webDriver);
52         timeoutInSeconds = 5;
53     }
54
55     @Override
56     public void isLoaded() {
57         wrappingElement = getWrappingElement();
58         GeneralUIUtils.ultimateWait();
59         final List<WebElement> vspResultList = wrappingElement
60             .findElements(By.className(RESULTS_CONTAINER_DIV.getId()));
61         assertThat("VSP Repository should contain at least one result", vspResultList, is(not(empty())));
62     }
63
64     /**
65      * Clicks on the Import Vsp button of the given repository item position in the list.
66      *
67      * @param listPosition the position of the element in the VSP list, starting from 1
68      * @return the next page object
69      */
70     public ResourceCreatePage clickOnImportVsp(final int listPosition) {
71         final List<WebElement> vspResultList =
72             findSubElements(wrappingElement, By.className(RESULTS_CONTAINER_DIV.getId()));
73         vspResultList.get(listPosition).click();
74         findSubElement(wrappingElement, By.xpath(IMPORT_VSP_BTN.getXpath())).click();
75         return new ResourceCreatePage(webDriver, new LoaderHelper(), new NotificationHelper());
76     }
77
78     /**
79      * Searches for a VSP in the repository list.
80      *
81      * @param vspName the VSP name to search
82      */
83     public void searchForVSP(final String vspName) {
84         final WebElement searchTxtElement = findSubElement(wrappingElement, By.xpath(SEARCH_TXT.getXpath()));
85         searchTxtElement.sendKeys(vspName);
86         GeneralUIUtils.ultimateWait();
87     }
88
89     /**
90      * Gets the enclosing element of the modal.
91      *
92      * @return the enclosing element
93      */
94     public WebElement getWrappingElement() {
95         LOGGER.debug("Finding element with xpath '{}'", MODAL_DIV.getXpath());
96         return waitForElementVisibility(MODAL_DIV.getXpath());
97     }
98
99     /**
100      * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
101      */
102     public enum XpathSelector {
103         MODAL_DIV("modalOnboarding", "//div[@modal='%s']"),
104         SEARCH_TXT("onboarding-search", "//input[@data-tests-id='%s']"),
105         IMPORT_VSP_BTN("import-csar", "//span[@data-tests-id='%s']"),
106         RESULTS_CONTAINER_DIV("flex-container", "//div[contains(@class,'%s']");
107
108         private final String id;
109         private final String xpathFormat;
110
111         XpathSelector(final String id, final String xpathFormat) {
112             this.id = id;
113             this.xpathFormat = xpathFormat;
114         }
115
116         public String getId() {
117             return id;
118         }
119
120         public String getXpath() {
121             return String.format(xpathFormat, id);
122         }
123     }
124
125 }