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