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 org.openecomp.sdc.ci.tests.execute.setup.DriverFactory;
23 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
24 import org.openqa.selenium.By;
25 import org.openqa.selenium.WebDriver;
26 import org.openqa.selenium.WebElement;
27 import org.openqa.selenium.interactions.Actions;
28 import org.openqa.selenium.support.ui.ExpectedConditions;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 import java.util.List;
34 import static org.openecomp.sdc.ci.tests.pages.TopNavComponent.XpathSelector.ARROW_DROPDOWN;
35 import static org.openecomp.sdc.ci.tests.pages.TopNavComponent.XpathSelector.MAIN_MENU_ONBOARD_BTN;
36 import static org.openecomp.sdc.ci.tests.pages.TopNavComponent.XpathSelector.NAV;
37 import static org.openecomp.sdc.ci.tests.pages.TopNavComponent.XpathSelector.REPOSITORY_ICON;
38 import static org.openecomp.sdc.ci.tests.pages.TopNavComponent.XpathSelector.SUB_MENU_BUTTON_HOME;
41 * Handles the Top Navigation Component UI actions
43 public class TopNavComponent extends AbstractPageObject {
45 private static final Logger LOGGER = LoggerFactory.getLogger(TopNavComponent.class);
47 private WebElement wrappingElement;
48 private By navLocator = By.xpath(NAV.getXpath());
50 public TopNavComponent(final WebDriver webDriver) {
56 public void isLoaded() {
57 wrappingElement = getWrappingElement();
61 * Gets the enclosing element of the component.
63 * @return the enclosing element
65 public WebElement getWrappingElement() {
66 LOGGER.debug("Finding element with xpath '{}'", NAV.getXpath());
67 return waitForElementVisibility(navLocator);
71 * Clicks on home link inside the first breadcrumb arrow.
73 public void clickOnHome() {
74 hoverToBreadcrumbArrow(0);
75 final By homeButtonLocator = By.xpath(SUB_MENU_BUTTON_HOME.getXpath());
76 getWait().until(ExpectedConditions.visibilityOfElementLocated(homeButtonLocator));
77 getWait().until(ExpectedConditions.elementToBeClickable(homeButtonLocator)).click();
79 .until(ExpectedConditions.visibilityOfElementLocated(By.xpath(REPOSITORY_ICON.getXpath())));
83 * Clicks on the VSP repository icon.
85 * @return the next page object
87 public VspRepositoryModalComponent clickOnRepositoryIcon() {
88 wrappingElement.findElement(By.xpath(REPOSITORY_ICON.getXpath())).click();
90 return new VspRepositoryModalComponent(webDriver);
94 * Clicks on the Onboard button.
96 * @return the next page object
98 public OnboardHomePage clickOnOnboard() {
99 wrappingElement.findElement(By.xpath(MAIN_MENU_ONBOARD_BTN.getXpath())).click();
100 return new OnboardHomePage(DriverFactory.getDriver(), new OnboardHeaderComponent(DriverFactory.getDriver()));
104 * Hover to a breadcrumb arrow of the given position.
106 * @param arrowPosition the position of the arrow from left to right
107 * @return the hovered breadcrumb arrow element
109 public WebElement hoverToBreadcrumbArrow(final int arrowPosition) {
110 final Actions actions = new Actions(GeneralUIUtils.getDriver());
111 final List<WebElement> arrowElementList = getWait()
113 ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath(ARROW_DROPDOWN.getXpath())));
114 final WebElement selectedArrowElement = arrowElementList.get(arrowPosition);
115 actions.moveToElement(selectedArrowElement).perform();
116 return selectedArrowElement;
120 * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
122 public enum XpathSelector {
123 NAV("top-nav", "//nav[@class='%s']"),
124 SUB_MENU_BUTTON_HOME("sub-menu-button-home", "//*[@data-tests-id='%s']"),
125 ARROW_DROPDOWN("triangle-dropdown", "//li[contains(@class, '%s')]"),
126 MAIN_MENU_ONBOARD_BTN("main-menu-button-onboard", "//a[@data-tests-id='%s']"),
127 REPOSITORY_ICON("repository-icon", "//*[@data-tests-id='%s']");
129 private final String id;
130 private final String xpathFormat;
132 XpathSelector(final String id, final String xpathFormat) {
134 this.xpathFormat = xpathFormat;
137 public String getId() {
141 public String getXpath() {
142 return String.format(xpathFormat, id);