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.openecomp.sdc.ci.tests.pages;
22 import static org.hamcrest.Matchers.empty;
23 import static org.hamcrest.core.Is.is;
24 import static org.hamcrest.core.IsNot.not;
25 import static org.junit.Assert.assertThat;
26 import static org.openecomp.sdc.ci.tests.pages.VspRepositoryModalComponent.XpathSelector.IMPORT_VSP_BTN;
27 import static org.openecomp.sdc.ci.tests.pages.VspRepositoryModalComponent.XpathSelector.MODAL_DIV;
28 import static org.openecomp.sdc.ci.tests.pages.VspRepositoryModalComponent.XpathSelector.RESULTS_CONTAINER_DIV;
29 import static org.openecomp.sdc.ci.tests.pages.VspRepositoryModalComponent.XpathSelector.SEARCH_TXT;
31 import java.util.List;
32 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
33 import org.openecomp.sdc.ci.tests.utilities.LoaderHelper;
34 import org.openecomp.sdc.ci.tests.utilities.NotificationHelper;
35 import org.openqa.selenium.By;
36 import org.openqa.selenium.WebDriver;
37 import org.openqa.selenium.WebElement;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
42 * Handles the VSP Repository Modal UI actions
44 public class VspRepositoryModalComponent extends AbstractPageObject {
46 private static final Logger LOGGER = LoggerFactory.getLogger(VspRepositoryModalComponent.class);
48 private WebElement wrappingElement;
50 public VspRepositoryModalComponent(final WebDriver webDriver) {
56 public void isLoaded() {
57 wrappingElement = getWrappingElement();
58 GeneralUIUtils.ultimateWait();
59 final List<WebElement> vspResultList = wrappingElement
60 .findElements(By.className(RESULTS_CONTAINER_DIV.getId()));
61 assertThat("VSP Repository should contain at least one result", vspResultList, is(not(empty())));
65 * Clicks on the Import Vsp button of the given repository item position in the list.
67 * @param listPosition the position of the element in the VSP list, starting from 1
68 * @return the next page object
70 public ResourceCreatePage clickOnImportVsp(final int listPosition) {
71 final List<WebElement> vspResultList =
72 findSubElements(wrappingElement, By.className(RESULTS_CONTAINER_DIV.getId()));
73 vspResultList.get(listPosition).click();
74 findSubElement(wrappingElement, By.xpath(IMPORT_VSP_BTN.getXpath())).click();
75 return new ResourceCreatePage(webDriver, new LoaderHelper(), new NotificationHelper());
79 * Searches for a VSP in the repository list.
81 * @param vspName the VSP name to search
83 public void searchForVSP(final String vspName) {
84 final WebElement searchTxtElement = findSubElement(wrappingElement, By.xpath(SEARCH_TXT.getXpath()));
85 searchTxtElement.sendKeys(vspName);
86 GeneralUIUtils.ultimateWait();
90 * Gets the enclosing element of the modal.
92 * @return the enclosing element
94 public WebElement getWrappingElement() {
95 LOGGER.debug("Finding element with xpath '{}'", MODAL_DIV.getXpath());
96 return waitForElementVisibility(MODAL_DIV.getXpath());
100 * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
102 public enum XpathSelector {
103 MODAL_DIV("modalOnboarding", "//div[@modal='%s']"),
104 SEARCH_TXT("onboarding-search", "//input[@data-tests-id='%s']"),
105 IMPORT_VSP_BTN("import-csar", "//span[@data-tests-id='%s']"),
106 RESULTS_CONTAINER_DIV("flex-container", "//div[contains(@class,'%s']");
108 private final String id;
109 private final String xpathFormat;
111 XpathSelector(final String id, final String xpathFormat) {
113 this.xpathFormat = xpathFormat;
116 public String getId() {
120 public String getXpath() {
121 return String.format(xpathFormat, id);