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.openecomp.sdc.ci.tests.pages.TopNavComponent.XpathSelector.ARROW_DROPDOWN;
23 import static org.openecomp.sdc.ci.tests.pages.TopNavComponent.XpathSelector.MAIN_MENU_ONBOARD_BTN;
24 import static org.openecomp.sdc.ci.tests.pages.TopNavComponent.XpathSelector.NAV;
25 import static org.openecomp.sdc.ci.tests.pages.TopNavComponent.XpathSelector.REPOSITORY_ICON;
26 import static org.openecomp.sdc.ci.tests.pages.TopNavComponent.XpathSelector.SUB_MENU_BUTTON_HOME;
28 import java.util.List;
29 import org.openecomp.sdc.ci.tests.execute.setup.DriverFactory;
30 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
31 import org.openqa.selenium.By;
32 import org.openqa.selenium.WebDriver;
33 import org.openqa.selenium.WebElement;
34 import org.openqa.selenium.interactions.Actions;
35 import org.openqa.selenium.support.ui.ExpectedConditions;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
40 * Handles the Top Navigation Component UI actions
42 public class TopNavComponent extends AbstractPageObject {
44 private static final Logger LOGGER = LoggerFactory.getLogger(TopNavComponent.class);
46 private WebElement wrappingElement;
47 private By navLocator = By.xpath(NAV.getXpath());
49 public TopNavComponent(final WebDriver webDriver) {
55 public void isLoaded() {
56 wrappingElement = getWrappingElement();
60 * Gets the enclosing element of the component.
62 * @return the enclosing element
64 public WebElement getWrappingElement() {
65 LOGGER.debug("Finding element with xpath '{}'", NAV.getXpath());
66 return waitForElementVisibility(navLocator);
70 * Clicks on home link inside the first breadcrumb arrow.
72 public void clickOnHome() {
73 hoverToBreadcrumbArrow(0);
74 final By homeButtonLocator = By.xpath(SUB_MENU_BUTTON_HOME.getXpath());
75 getWait().until(ExpectedConditions.visibilityOfElementLocated(homeButtonLocator));
76 getWait().until(ExpectedConditions.elementToBeClickable(homeButtonLocator)).click();
78 .until(ExpectedConditions.visibilityOfElementLocated(By.xpath(REPOSITORY_ICON.getXpath())));
82 * Clicks on the VSP repository icon.
84 * @return the next page object
86 public VspRepositoryModalComponent clickOnRepositoryIcon() {
87 wrappingElement.findElement(By.xpath(REPOSITORY_ICON.getXpath())).click();
88 return new VspRepositoryModalComponent(webDriver);
92 * Clicks on the Onboard button.
94 * @return the next page object
96 public OnboardHomePage clickOnOnboard() {
97 wrappingElement.findElement(By.xpath(MAIN_MENU_ONBOARD_BTN.getXpath())).click();
98 return new OnboardHomePage(DriverFactory.getDriver(), new OnboardHeaderComponent(DriverFactory.getDriver()));
102 * Hover to a breadcrumb arrow of the given position.
104 * @param arrowPosition the position of the arrow from left to right
105 * @return the hovered breadcrumb arrow element
107 public WebElement hoverToBreadcrumbArrow(final int arrowPosition) {
108 final Actions actions = new Actions(GeneralUIUtils.getDriver());
109 final List<WebElement> arrowElementList = getWait()
111 ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath(ARROW_DROPDOWN.getXpath())));
112 final WebElement selectedArrowElement = arrowElementList.get(arrowPosition);
113 actions.moveToElement(selectedArrowElement).perform();
114 return selectedArrowElement;
118 * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
120 public enum XpathSelector {
121 NAV("top-nav", "//nav[@class='%s']"),
122 SUB_MENU_BUTTON_HOME("sub-menu-button-home", "//*[@data-tests-id='%s']"),
123 ARROW_DROPDOWN("triangle-dropdown", "//li[contains(@class, '%s')]"),
124 MAIN_MENU_ONBOARD_BTN("main-menu-button-onboard", "//a[@data-tests-id='%s']"),
125 REPOSITORY_ICON("repository-icon", "//div[@data-tests-id='%s']");
127 private final String id;
128 private final String xpathFormat;
130 XpathSelector(final String id, final String xpathFormat) {
132 this.xpathFormat = xpathFormat;
135 public String getId() {
139 public String getXpath() {
140 return String.format(xpathFormat, id);