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.interactions.Actions;
33 import org.openqa.selenium.support.ui.ExpectedConditions;
34 import org.openqa.selenium.support.ui.WebDriverWait;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
39 import java.io.IOException;
40 import java.text.SimpleDateFormat;
41 import java.util.Calendar;
42 import java.util.List;
43 import java.util.UUID;
45 import static org.onap.sdc.frontend.ci.tests.execute.setup.DriverFactory.getDriver;
46 import static org.onap.sdc.frontend.ci.tests.execute.setup.SetupCDTest.getExtendTest;
47 import static org.onap.sdc.frontend.ci.tests.pages.HomePage.PageElement.REPOSITORY_ICON;
49 public class HomePage {
51 private static final Logger LOGGER = LoggerFactory.getLogger(HomePage.class);
53 private static final int WAIT_FOR_ELEMENT_TIME_OUT = 30;
54 private static final int WAIT_FOR_LOADER_TIME_OUT = 600;
60 public static void showVspRepository() {
61 GeneralUIUtils.waitForElementInVisibilityBy(By.className("ui-notification"), WAIT_FOR_ELEMENT_TIME_OUT);
62 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.MainMenuButtons.REPOSITORY_ICON.getValue());
65 public static boolean searchForVSP(String vspName) {
66 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ImportVfRepository.SEARCH.getValue()).clear();
67 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ImportVfRepository.SEARCH.getValue()).sendKeys(vspName);
68 GeneralUIUtils.ultimateWait();
72 public static void importVSP(String vspName) {
73 HomePage.showVspRepository();
74 boolean vspFound = HomePage.searchForVSP(vspName);
76 List<WebElement> elementsFromTable = GeneralPageElements.getElementsFromTable();
77 WebDriverWait wait = new WebDriverWait(GeneralUIUtils.getDriver(), WAIT_FOR_ELEMENT_TIME_OUT);
78 WebElement findElement = wait.until(ExpectedConditions.visibilityOf(elementsFromTable.get(1)));
80 GeneralUIUtils.waitForLoader();
81 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ImportVfRepository.IMPORT_VSP.getValue());
82 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.GeneralElementsEnum.CREATE_BUTTON.getValue());
83 GeneralUIUtils.waitForLoader(WAIT_FOR_LOADER_TIME_OUT);
84 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.CHECKIN_BUTTON.getValue());
88 public static boolean navigateToHomePage() {
90 LOGGER.debug("Searching for repository icon");
91 final WebElement repositoryIcon = GeneralUIUtils.getInputElement(REPOSITORY_ICON.getTestId());
92 if (repositoryIcon != null) {
95 GeneralUIUtils.ultimateWait();
96 final List<WebElement> homeButtons = GeneralUIUtils
97 .getElementsByLocator(By.xpath("//a[contains(.,'HOME')]"));
98 if (!homeButtons.isEmpty()) {
99 homeButtons.stream().filter(WebElement::isDisplayed).findFirst().ifPresent(webElement -> {
101 LOGGER.debug("Clicked on home button");
105 GeneralUIUtils.closeErrorMessage();
106 WebElement homeButton = GeneralUIUtils
107 .getInputElement(DataTestIdEnum.MainMenuButtons.HOME_BUTTON.getValue());
108 if (homeButton != null) {
109 //making sure that the mouse it is not on the add/import area
110 new Actions(getDriver()).moveToElement(homeButton).perform();
112 return homeButton != null && homeButton.isDisplayed();
114 } catch (final Exception e) {
115 final String msg = "Could not click on home button";
117 .log(Status.WARNING, msg);
123 public static File downloadVspCsarToDefaultDirectory(String vspName) throws Exception {
124 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtonsFromInsideFrame.HOME_BUTTON.getValue()).click();
125 DownloadManager.downloadCsarByNameFromVSPRepository(vspName, "");
126 return FileHandling.getLastModifiedFileNameFromDir();
129 public static void findComponentAndClick(final String resourceName) {
130 findComponent(resourceName);
131 clickComponent(resourceName);
134 public static void findComponent(final String resourceName) {
135 LOGGER.debug("Searching for component '{}'", resourceName);
136 getExtendTest().log(Status.INFO, "Searching for " + resourceName + " in home tab");
137 clearSearchResults(getSearchInput());
138 searchForComponent(resourceName);
141 private static WebElement getSearchInput() {
142 WebElement searchTextbox;
144 searchTextbox = TopSearchComponent.getComponentInput();
145 LOGGER.debug("Search textbox '{}' selected", TopSearchComponent.SEARCH_INPUT_TEST_ID);
146 } catch (final Exception e) {
147 final String errorMsg = "Top Search bar was not visible";
148 getExtendTest().log(Status.ERROR, errorMsg);
149 throw new HomePageRuntimeException(errorMsg, e);
151 return searchTextbox;
154 private static void clearSearchResults(final WebElement searchTextbox) {
156 LOGGER.debug("Clearing search results before searching");
157 TopSearchComponent.replaceSearchValue(searchTextbox, UUID.randomUUID().toString());
158 MainRightContainer.isEmptyResult();
159 } catch (final Exception e) {
160 final String errorMsg = "Could not clean up the search result";
161 getExtendTest().log(Status.ERROR, errorMsg);
162 throw new HomePageRuntimeException(errorMsg, e);
166 private static void searchForComponent(final String resourceName) {
168 LOGGER.debug("Searching for '{}'", resourceName);
169 TopSearchComponent.replaceSearchValue(resourceName);
170 MainRightContainer.isResultVisible(resourceName);
171 } catch (final Exception e) {
172 final String errorMsg = String.format("Could not find the component '%s' after search", resourceName);
173 getExtendTest().log(Status.ERROR, errorMsg);
174 throw new HomePageRuntimeException(errorMsg, e);
178 public static void clickComponent(final String resourceName) {
179 LOGGER.debug("Clicking on the component " + resourceName);
182 .log(Status.INFO, String.format("Clicking on the '%s' component from home tab", resourceName));
183 GeneralUIUtils.clickOnElementByTestId(resourceName);
184 } catch (final Exception e) {
185 final String errorMsg = String.format("Could not click on home tab component '%s' ", resourceName);
186 getExtendTest().log(Status.ERROR, e.getMessage());
187 throw new HomePageRuntimeException(errorMsg, e);
189 final String datetimeString =
190 new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss.SSS").format(Calendar.getInstance().getTime());
193 .addScreenshot(Status.INFO,
194 String.format("after-click-resource-%s-%s", resourceName, datetimeString),
195 String.format("Clicked on resource '%s'", resourceName)
197 } catch (final IOException e) {
198 LOGGER.warn("Could take screenshot after resource {} click", resourceName, e);
201 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.LIFECYCLE_STATE.getValue());
202 } catch (final Exception e) {
203 final String errorMsg = String.format("Expecting to be inside component '%s' screen", resourceName);
204 getExtendTest().log(Status.ERROR, e.getMessage());
205 throw new HomePageRuntimeException(errorMsg, e);
209 public static void waitForElement(PageElement homePageElement) {
210 final String cssClass = homePageElement.getCssClass();
211 LOGGER.debug("Waiting for{} visibility", cssClass);
212 GeneralUIUtils.getWebElementByClassName(cssClass);
213 LOGGER.debug("{} is visible", cssClass);
216 public enum PageElement {
217 COMPONENT_PANEL("w-sdc-main-right-container", null),
218 REPOSITORY_ICON(null, "repository-icon");
220 private final String cssClass;
221 private final String testId;
223 PageElement(String cssClass, String testId) {
224 this.cssClass = cssClass;
225 this.testId = testId;
228 public String getCssClass() {
232 public String getTestId() {