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 java.time.Duration;
23 import java.util.List;
24 import lombok.AllArgsConstructor;
26 import org.onap.sdc.frontend.ci.tests.execute.setup.DriverFactory;
27 import org.onap.sdc.frontend.ci.tests.pages.home.HomePage;
28 import org.openqa.selenium.By;
29 import org.openqa.selenium.WebDriver;
30 import org.openqa.selenium.WebElement;
31 import org.openqa.selenium.interactions.Actions;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
36 * Handles the Top Navigation Component UI actions
38 public class TopNavComponent extends AbstractPageObject {
40 private static final Logger LOGGER = LoggerFactory.getLogger(TopNavComponent.class);
42 private WebElement wrappingElement;
43 private By navLocator = By.xpath(XpathSelector.NAV.getXpath());
45 public TopNavComponent(final WebDriver webDriver) {
51 public void isLoaded() {
52 wrappingElement = getWrappingElement();
56 * Gets the enclosing element of the component.
58 * @return the enclosing element
60 public WebElement getWrappingElement() {
61 LOGGER.debug("Finding element with xpath '{}'", XpathSelector.NAV.getXpath());
62 return waitForElementVisibility(navLocator);
66 * Clicks on home link inside the first breadcrumb arrow.
68 public HomePage clickOnHome() {
69 hoverToBreadcrumbArrow(0);
70 final By homeButtonLocator = By.xpath(XpathSelector.SUB_MENU_BUTTON_HOME.getXpath());
71 waitForElementVisibility(homeButtonLocator);
72 waitToBeClickable(homeButtonLocator).click();
73 return new HomePage(webDriver, this);
76 public boolean isHomeSelected() {
77 final By homeLinkLocator = By.xpath(XpathSelector.MAIN_MENU_LINK_HOME.getXpath());
78 final WebElement homeLinkElement = waitToBeClickable(homeLinkLocator);
79 final WebElement homeLinkParentElement = homeLinkElement.findElement(By.xpath("./.."));
80 final String homeLinkClass = homeLinkParentElement.getAttribute("class");
81 LOGGER.debug(String.format("Home link class '%s'", homeLinkClass));
82 return homeLinkClass != null && homeLinkClass.contains("selected");
86 * Click on one of the items of the top nav breadcrumb based on the given position.
87 * The first item in the breadcrumb is position 0.
89 * @param position the position of the breadcrumb item
91 public void clickOnBreadCrumb(final int position) {
93 throw new IllegalStateException("The position cannot be less that zero");
95 waitForElementVisibility(By.xpath(String.format("//*[@data-tests-id='breadcrumbs-button-%s']", position))).click();
98 public void waitRepositoryToBeClickable() {
99 waitToBeClickable(XpathSelector.REPOSITORY_ICON.getXpath());
103 * Clicks on the VSP repository icon.
105 * @return the next page object
107 public VspRepositoryModalComponent clickOnRepositoryIcon() {
108 wrappingElement.findElement(By.xpath(XpathSelector.REPOSITORY_ICON.getXpath())).click();
110 return new VspRepositoryModalComponent(webDriver);
114 * Clicks on the Onboard button.
116 * @return the next page object
118 public OnboardHomePage clickOnOnboard() {
119 wrappingElement.findElement(By.xpath(XpathSelector.MAIN_MENU_ONBOARD_BTN.getXpath())).click();
120 return new OnboardHomePage(DriverFactory.getDriver(), new OnboardHeaderComponent(DriverFactory.getDriver()));
124 * Hover to a breadcrumb arrow of the given position.
126 * @param arrowPosition the position of the arrow from left to right
127 * @return the hovered breadcrumb arrow element
129 public WebElement hoverToBreadcrumbArrow(final int arrowPosition) {
130 final Actions actions = new Actions(webDriver);
131 final List<WebElement> arrowElementList = waitForAllElementsVisibility(By.xpath(XpathSelector.ARROW_DROPDOWN.getXpath()));
132 final WebElement selectedArrowElement = arrowElementList.get(arrowPosition);
133 actions.moveByOffset(20, 20).moveToElement(selectedArrowElement).pause(Duration.ofMillis(500)).perform();
134 return selectedArrowElement;
138 * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
141 private enum XpathSelector {
142 NAV("top-nav", "//nav[@class='%s']"),
143 SUB_MENU_BUTTON_HOME("sub-menu-button-home", "//*[@data-tests-id='%s']"),
144 MAIN_MENU_LINK_HOME("main-menu-button-home", "//*[@data-tests-id='%s']"),
145 ARROW_DROPDOWN("triangle-dropdown", "//li[contains(@class, '%s')]"),
146 MAIN_MENU_ONBOARD_BTN("main-menu-button-onboard", "//a[@data-tests-id='%s']"),
147 REPOSITORY_ICON("repository-icon", "//*[@data-tests-id='%s']");
150 private final String id;
151 private final String xpathFormat;
153 public String getXpath() {
154 return String.format(xpathFormat, id);