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 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;
27 import java.util.List;
28 import lombok.AllArgsConstructor;
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;
40 * Handles the VSP Repository Modal UI actions
42 public class VspRepositoryModalComponent extends AbstractPageObject {
44 private static final Logger LOGGER = LoggerFactory.getLogger(VspRepositoryModalComponent.class);
46 private WebElement wrappingElement;
48 public VspRepositoryModalComponent(final WebDriver webDriver) {
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())));
63 * Clicks on the Import Vsp button of the given repository item position in the list.
65 * @param listPosition the position of the element in the VSP list, starting from 1
66 * @return the next page object
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));
77 * Searches for a VSP in the repository list.
79 * @param vspName the VSP name to search
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();
88 * Gets the enclosing element of the modal.
90 * @return the enclosing element
92 public WebElement getWrappingElement() {
93 LOGGER.debug("Finding element with xpath '{}'", XpathSelector.MODAL_DIV.getXpath());
94 return waitForElementVisibility(XpathSelector.MODAL_DIV.getXpath());
98 * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
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']");
108 private final String id;
109 private final String xpathFormat;
111 public String getXpath() {
112 return String.format(xpathFormat, id);