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
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.
16 * SPDX-License-Identifier: Apache-2.0
17 * ============LICENSE_END=========================================================
20 package org.onap.sdc.frontend.ci.tests.pages;
22 import org.onap.sdc.frontend.ci.tests.utilities.GeneralUIUtils;
23 import org.onap.sdc.frontend.ci.tests.utilities.LoaderHelper;
24 import org.onap.sdc.frontend.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;
31 import java.util.List;
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.onap.sdc.frontend.ci.tests.pages.VspRepositoryModalComponent.XpathSelector.IMPORT_VSP_BTN;
38 import static org.onap.sdc.frontend.ci.tests.pages.VspRepositoryModalComponent.XpathSelector.MODAL_DIV;
39 import static org.onap.sdc.frontend.ci.tests.pages.VspRepositoryModalComponent.XpathSelector.RESULTS_CONTAINER_DIV;
40 import static org.onap.sdc.frontend.ci.tests.pages.VspRepositoryModalComponent.XpathSelector.SEARCH_TXT;
43 * Handles the VSP Repository Modal UI actions
45 public class VspRepositoryModalComponent extends AbstractPageObject {
47 private static final Logger LOGGER = LoggerFactory.getLogger(VspRepositoryModalComponent.class);
49 private WebElement wrappingElement;
51 public VspRepositoryModalComponent(final WebDriver webDriver) {
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())));
66 * Clicks on the Import Vsp button of the given repository item position in the list.
68 * @param listPosition the position of the element in the VSP list, starting from 1
69 * @return the next page object
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());
80 * Searches for a VSP in the repository list.
82 * @param vspName the VSP name to search
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();
91 * Gets the enclosing element of the modal.
93 * @return the enclosing element
95 public WebElement getWrappingElement() {
96 LOGGER.debug("Finding element with xpath '{}'", MODAL_DIV.getXpath());
97 return waitForElementVisibility(MODAL_DIV.getXpath());
101 * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
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']");
109 private final String id;
110 private final String xpathFormat;
112 XpathSelector(final String id, final String xpathFormat) {
114 this.xpathFormat = xpathFormat;
117 public String getId() {
121 public String getXpath() {
122 return String.format(xpathFormat, id);