2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.sdc.frontend.ci.tests.pages;
23 import com.aventstack.extentreports.Status;
24 import org.onap.sdc.frontend.ci.tests.datatypes.DataTestIdEnum;
25 import org.onap.sdc.frontend.ci.tests.exception.HomePageRuntimeException;
26 import org.onap.sdc.frontend.ci.tests.execute.setup.ExtentTestActions;
27 import org.onap.sdc.frontend.ci.tests.utilities.DownloadManager;
28 import org.onap.sdc.frontend.ci.tests.utilities.FileHandling;
29 import org.onap.sdc.frontend.ci.tests.utilities.GeneralUIUtils;
30 import org.openqa.selenium.By;
31 import org.openqa.selenium.WebElement;
32 import org.openqa.selenium.support.ui.ExpectedConditions;
33 import org.openqa.selenium.support.ui.WebDriverWait;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
38 import java.io.IOException;
39 import java.text.SimpleDateFormat;
40 import java.util.Calendar;
41 import java.util.List;
42 import java.util.UUID;
44 import static org.onap.sdc.frontend.ci.tests.execute.setup.SetupCDTest.getExtendTest;
45 import static org.onap.sdc.frontend.ci.tests.pages.HomePage.PageElement.REPOSITORY_ICON;
47 public class HomePage {
49 private static final Logger LOGGER = LoggerFactory.getLogger(HomePage.class);
51 private static final int WAIT_FOR_ELEMENT_TIME_OUT = 30;
52 private static final int WAIT_FOR_LOADER_TIME_OUT = 600;
58 public static void showVspRepository() {
59 GeneralUIUtils.waitForElementInVisibilityBy(By.className("ui-notification"), WAIT_FOR_ELEMENT_TIME_OUT);
60 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.MainMenuButtons.REPOSITORY_ICON.getValue());
63 public static boolean searchForVSP(String vspName) {
64 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ImportVfRepository.SEARCH.getValue()).clear();
65 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ImportVfRepository.SEARCH.getValue()).sendKeys(vspName);
66 GeneralUIUtils.ultimateWait();
70 public static void importVSP(String vspName) {
71 HomePage.showVspRepository();
72 boolean vspFound = HomePage.searchForVSP(vspName);
74 List<WebElement> elementsFromTable = GeneralPageElements.getElementsFromTable();
75 WebDriverWait wait = new WebDriverWait(GeneralUIUtils.getDriver(), WAIT_FOR_ELEMENT_TIME_OUT);
76 WebElement findElement = wait.until(ExpectedConditions.visibilityOf(elementsFromTable.get(1)));
78 GeneralUIUtils.waitForLoader();
79 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ImportVfRepository.IMPORT_VSP.getValue());
80 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.GeneralElementsEnum.CREATE_BUTTON.getValue());
81 GeneralUIUtils.waitForLoader(WAIT_FOR_LOADER_TIME_OUT);
82 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.CHECKIN_BUTTON.getValue());
86 public static boolean navigateToHomePage() {
88 LOGGER.debug("Searching for repository icon");
89 final WebElement repositoryIcon = GeneralUIUtils.getInputElement(REPOSITORY_ICON.getTestId());
90 if (repositoryIcon != null) {
93 GeneralUIUtils.ultimateWait();
94 final List<WebElement> homeButtons = GeneralUIUtils
95 .getElementsByLocator(By.xpath("//a[contains(.,'HOME')]"));
96 if (!homeButtons.isEmpty()) {
97 homeButtons.stream().filter(WebElement::isDisplayed).findFirst().ifPresent(webElement -> {
99 LOGGER.debug("Clicked on home button");
103 GeneralUIUtils.closeErrorMessage();
104 WebElement homeButton = GeneralUIUtils
105 .getInputElement(DataTestIdEnum.MainMenuButtons.HOME_BUTTON.getValue());
106 return homeButton != null && homeButton.isDisplayed();
108 } catch (final Exception e) {
109 final String msg = "Could not click on home button";
111 .log(Status.WARNING, msg);
117 public static File downloadVspCsarToDefaultDirectory(String vspName) throws Exception {
118 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtonsFromInsideFrame.HOME_BUTTON.getValue()).click();
119 DownloadManager.downloadCsarByNameFromVSPRepository(vspName, "");
120 return FileHandling.getLastModifiedFileNameFromDir();
123 public static void findComponentAndClick(final String resourceName) {
124 findComponent(resourceName);
125 clickComponent(resourceName);
128 public static void findComponent(final String resourceName) {
129 LOGGER.debug("Searching for component '{}'", resourceName);
130 getExtendTest().log(Status.INFO, "Searching for " + resourceName + " in home tab");
131 clearSearchResults(getSearchInput());
132 searchForComponent(resourceName);
135 private static WebElement getSearchInput() {
136 WebElement searchTextbox;
138 searchTextbox = TopSearchComponent.getComponentInput();
139 LOGGER.debug("Search textbox '{}' selected", TopSearchComponent.SEARCH_INPUT_TEST_ID);
140 } catch (final Exception e) {
141 final String errorMsg = "Top Search bar was not visible";
142 getExtendTest().log(Status.ERROR, errorMsg);
143 throw new HomePageRuntimeException(errorMsg, e);
145 return searchTextbox;
148 private static void clearSearchResults(final WebElement searchTextbox) {
150 LOGGER.debug("Clearing search results before searching");
151 TopSearchComponent.replaceSearchValue(searchTextbox, UUID.randomUUID().toString());
152 MainRightContainer.isEmptyResult();
153 } catch (final Exception e) {
154 final String errorMsg = "Could not clean up the search result";
155 getExtendTest().log(Status.ERROR, errorMsg);
156 throw new HomePageRuntimeException(errorMsg, e);
160 private static void searchForComponent(final String resourceName) {
162 LOGGER.debug("Searching for '{}'", resourceName);
163 TopSearchComponent.replaceSearchValue(resourceName);
164 MainRightContainer.isResultVisible(resourceName);
165 } catch (final Exception e) {
166 final String errorMsg = String.format("Could not find the component '%s' after search", resourceName);
167 getExtendTest().log(Status.ERROR, errorMsg);
168 throw new HomePageRuntimeException(errorMsg, e);
172 public static void clickComponent(final String resourceName) {
173 LOGGER.debug("Clicking on the component " + resourceName);
176 .log(Status.INFO, String.format("Clicking on the '%s' component from home tab", resourceName));
177 GeneralUIUtils.clickOnElementByTestId(resourceName);
178 } catch (final Exception e) {
179 final String errorMsg = String.format("Could not click on home tab component '%s' ", resourceName);
180 getExtendTest().log(Status.ERROR, e.getMessage());
181 throw new HomePageRuntimeException(errorMsg, e);
183 final String datetimeString =
184 new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss.SSS").format(Calendar.getInstance().getTime());
187 .addScreenshot(Status.INFO,
188 String.format("after-click-resource-%s-%s", resourceName, datetimeString),
189 String.format("Clicked on resource '%s'", resourceName)
191 } catch (final IOException e) {
192 LOGGER.warn("Could take screenshot after resource {} click", resourceName, e);
195 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.LIFECYCLE_STATE.getValue());
196 } catch (final Exception e) {
197 final String errorMsg = String.format("Expecting to be inside component '%s' screen", resourceName);
198 getExtendTest().log(Status.ERROR, e.getMessage());
199 throw new HomePageRuntimeException(errorMsg, e);
203 public static void waitForElement(PageElement homePageElement) {
204 final String cssClass = homePageElement.getCssClass();
205 LOGGER.debug("Waiting for{} visibility", cssClass);
206 GeneralUIUtils.getWebElementByClassName(cssClass);
207 LOGGER.debug("{} is visible", cssClass);
210 public enum PageElement {
211 COMPONENT_PANEL("w-sdc-main-right-container", null),
212 REPOSITORY_ICON(null, "repository-icon");
214 private final String cssClass;
215 private final String testId;
217 PageElement(String cssClass, String testId) {
218 this.cssClass = cssClass;
219 this.testId = testId;
222 public String getCssClass() {
226 public String getTestId() {