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