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