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.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;
38 * Handles the VSP Repository Modal UI actions
40 public class VspRepositoryModalComponent extends AbstractPageObject {
42 private static final Logger LOGGER = LoggerFactory.getLogger(VspRepositoryModalComponent.class);
44 private WebElement wrappingElement;
46 public VspRepositoryModalComponent(final WebDriver webDriver) {
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())));
61 * Clicks on the Import Vsp button of the given repository item position in the list.
63 * @param listPosition the position of the element in the VSP list, starting from 1
64 * @return the next page object
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);
75 * Searches for a VSP in the repository list.
77 * @param vspName the VSP name to search
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();
86 * Gets the enclosing element of the modal.
88 * @return the enclosing element
90 public WebElement getWrappingElement() {
91 LOGGER.debug("Finding element with xpath '{}'", XpathSelector.MODAL_DIV.getXpath());
92 return waitForElementVisibility(XpathSelector.MODAL_DIV.getXpath());
96 * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
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']");
106 private final String id;
107 private final String xpathFormat;
109 public String getXpath() {
110 return String.format(xpathFormat, id);