diff options
Diffstat (limited to 'ui-ci/src/main/java/org/openecomp/sdc/ci/tests/pages/HomePage.java')
-rw-r--r-- | ui-ci/src/main/java/org/openecomp/sdc/ci/tests/pages/HomePage.java | 167 |
1 files changed, 136 insertions, 31 deletions
diff --git a/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/pages/HomePage.java b/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/pages/HomePage.java index d6485fd5c2..c5cd347e88 100644 --- a/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/pages/HomePage.java +++ b/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/pages/HomePage.java @@ -20,7 +20,15 @@ package org.openecomp.sdc.ci.tests.pages; +import static org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest.getExtendTest; +import static org.openecomp.sdc.ci.tests.pages.HomePage.PageElement.REPOSITORY_ICON; + +import com.aventstack.extentreports.Status; +import java.io.File; +import java.util.List; +import java.util.UUID; import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum; +import org.openecomp.sdc.ci.tests.exception.HomePageRuntimeException; import org.openecomp.sdc.ci.tests.utilities.DownloadManager; import org.openecomp.sdc.ci.tests.utilities.FileHandling; import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils; @@ -28,17 +36,18 @@ import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -import java.io.File; -import java.util.List; +public class HomePage { -public class HomePage extends GeneralPageElements { + private static final Logger LOGGER = LoggerFactory.getLogger(HomePage.class); private static final int WAIT_FOR_ELEMENT_TIME_OUT = 30; private static final int WAIT_FOR_LOADER_TIME_OUT = 600; - public HomePage() { - super(); + private HomePage() { + } public static void showVspRepository() { @@ -56,9 +65,9 @@ public class HomePage extends GeneralPageElements { HomePage.showVspRepository(); boolean vspFound = HomePage.searchForVSP(vspName); if (vspFound) { - List<WebElement> elemenetsFromTable = getElemenetsFromTable(); + List<WebElement> elementsFromTable = GeneralPageElements.getElementsFromTable(); WebDriverWait wait = new WebDriverWait(GeneralUIUtils.getDriver(), WAIT_FOR_ELEMENT_TIME_OUT); - WebElement findElement = wait.until(ExpectedConditions.visibilityOf(elemenetsFromTable.get(1))); + WebElement findElement = wait.until(ExpectedConditions.visibilityOf(elementsFromTable.get(1))); findElement.click(); GeneralUIUtils.waitForLoader(); GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ImportVfRepository.IMPORT_VSP.getValue()); @@ -68,42 +77,138 @@ public class HomePage extends GeneralPageElements { } } - public static boolean navigateToHomePage() { try { - System.out.println("Searching for reporsitory icon."); - WebElement repositoryIcon = GeneralUIUtils.getInputElement("repository-icon"); + LOGGER.debug("Searching for repository icon"); + final WebElement repositoryIcon = GeneralUIUtils.getInputElement(REPOSITORY_ICON.getTestId()); if (repositoryIcon != null) { return true; - } else { - GeneralUIUtils.ultimateWait(); - List<WebElement> homeButtons = GeneralUIUtils.getElemenetsFromTable(By.xpath("//a[contains(.,'HOME')]")); - if (homeButtons.size() != 0) { - for (WebElement home : homeButtons) { - if (home.isDisplayed()) { - home.click(); - System.out.println("Clicked on home button"); - break; - } - } - GeneralUIUtils.closeErrorMessage(); - WebElement homeButton = GeneralUIUtils.getInputElement(DataTestIdEnum.MainMenuButtons.HOME_BUTTON.getValue()); - return homeButton.isDisplayed(); - } - } - } catch (Exception innerException) { - System.out.println("Can't click on home button."); + GeneralUIUtils.ultimateWait(); + final List<WebElement> homeButtons = GeneralUIUtils + .getElementsByLocator(By.xpath("//a[contains(.,'HOME')]")); + if (!homeButtons.isEmpty()) { + homeButtons.stream().filter(WebElement::isDisplayed).findFirst().ifPresent(webElement -> { + webElement.click(); + LOGGER.debug("Clicked on home button"); + }); + } + + GeneralUIUtils.closeErrorMessage(); + WebElement homeButton = GeneralUIUtils + .getInputElement(DataTestIdEnum.MainMenuButtons.HOME_BUTTON.getValue()); + return homeButton != null && homeButton.isDisplayed(); + + } catch (final Exception e) { + final String msg = "Could not click on home button"; + getExtendTest() + .log(Status.WARNING, msg); + LOGGER.warn(msg, e); return false; } - return false; } public static File downloadVspCsarToDefaultDirectory(String vspName) throws Exception { GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtonsFromInsideFrame.HOME_BUTTON.getValue()).click(); DownloadManager.downloadCsarByNameFromVSPRepository(vspName, ""); - File latestFilefromDir = FileHandling.getLastModifiedFileNameFromDir(); - return latestFilefromDir; + return FileHandling.getLastModifiedFileNameFromDir(); + } + + public static void findComponentAndClick(final String resourceName) { + findComponent(resourceName); + clickComponent(resourceName); + } + + public static void findComponent(final String resourceName) { + LOGGER.debug("Searching for component '{}'", resourceName); + getExtendTest().log(Status.INFO, "Searching for " + resourceName + " in home tab"); + clearSearchResults(getSearchInput()); + searchForComponent(resourceName); + } + + private static WebElement getSearchInput() { + WebElement searchTextbox; + try { + searchTextbox = TopSearchComponent.getComponentInput(); + LOGGER.debug("Search textbox '{}' selected", TopSearchComponent.SEARCH_INPUT_TEST_ID); + } catch (final Exception e) { + final String errorMsg = "Top Search bar was not visible"; + getExtendTest().log(Status.ERROR, errorMsg); + throw new HomePageRuntimeException(errorMsg, e); + } + return searchTextbox; + } + + private static void clearSearchResults(final WebElement searchTextbox) { + try { + LOGGER.debug("Clearing search results before searching"); + TopSearchComponent.replaceSearchValue(searchTextbox, UUID.randomUUID().toString()); + MainRightContainer.isEmptyResult(); + } catch (final Exception e) { + final String errorMsg = "Could not clean up the search result"; + getExtendTest().log(Status.ERROR, errorMsg); + throw new HomePageRuntimeException(errorMsg, e); + } + } + + private static void searchForComponent(final String resourceName) { + try { + LOGGER.debug("Searching for '{}'", resourceName); + TopSearchComponent.replaceSearchValue(resourceName); + MainRightContainer.isResultVisible(resourceName); + } catch (final Exception e) { + final String errorMsg = String.format("Could not find the component '%s' after search", resourceName); + getExtendTest().log(Status.ERROR, errorMsg); + throw new HomePageRuntimeException(errorMsg, e); + } + } + + public static void clickComponent(final String resourceName) { + LOGGER.debug("Clicking on the component " + resourceName); + try { + getExtendTest() + .log(Status.INFO, String.format("Clicking on the '%s' component from home tab", resourceName)); + GeneralUIUtils.clickOnElementByTestId(resourceName); + } catch (final Exception e) { + final String errorMsg = String.format("Could not click on home tab component '%s' ", resourceName); + getExtendTest().log(Status.ERROR, e.getMessage()); + throw new HomePageRuntimeException(errorMsg, e); + } + try { + GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.LIFECYCLE_STATE.getValue()); + } catch (final Exception e) { + final String errorMsg = String.format("Expecting to be inside component '%s' screen", resourceName); + getExtendTest().log(Status.ERROR, e.getMessage()); + throw new HomePageRuntimeException(errorMsg, e); + } + } + + public static void waitForElement(PageElement homePageElement) { + final String cssClass = homePageElement.getCssClass(); + LOGGER.debug("Waiting for{} visibility", cssClass); + GeneralUIUtils.getWebElementByClassName(cssClass); + LOGGER.debug("{} is visible", cssClass); + } + + public enum PageElement { + COMPONENT_PANEL("w-sdc-main-right-container", null), + REPOSITORY_ICON(null, "repository-icon"); + + private final String cssClass; + private final String testId; + + PageElement(String cssClass, String testId) { + this.cssClass = cssClass; + this.testId = testId; + } + + public String getCssClass() { + return cssClass; + } + + public String getTestId() { + return testId; + } } } |