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();
89 return new VspRepositoryModalComponent(webDriver);
93 * Clicks on the Onboard button.
95 * @return the next page object
97 public OnboardHomePage clickOnOnboard() {
98 wrappingElement.findElement(By.xpath(MAIN_MENU_ONBOARD_BTN.getXpath())).click();
99 return new OnboardHomePage(DriverFactory.getDriver(), new OnboardHeaderComponent(DriverFactory.getDriver()));
103 * Hover to a breadcrumb arrow of the given position.
105 * @param arrowPosition the position of the arrow from left to right
106 * @return the hovered breadcrumb arrow element
108 public WebElement hoverToBreadcrumbArrow(final int arrowPosition) {
109 final Actions actions = new Actions(GeneralUIUtils.getDriver());
110 final List<WebElement> arrowElementList = getWait()
112 ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath(ARROW_DROPDOWN.getXpath())));
113 final WebElement selectedArrowElement = arrowElementList.get(arrowPosition);
114 actions.moveToElement(selectedArrowElement).perform();
115 return selectedArrowElement;
119 * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
121 public enum XpathSelector {
122 NAV("top-nav", "//nav[@class='%s']"),
123 SUB_MENU_BUTTON_HOME("sub-menu-button-home", "//*[@data-tests-id='%s']"),
124 ARROW_DROPDOWN("triangle-dropdown", "//li[contains(@class, '%s')]"),
125 MAIN_MENU_ONBOARD_BTN("main-menu-button-onboard", "//a[@data-tests-id='%s']"),
126 REPOSITORY_ICON("repository-icon", "//div[@data-tests-id='%s']");
128 private final String id;
129 private final String xpathFormat;
131 XpathSelector(final String id, final String xpathFormat) {
133 this.xpathFormat = xpathFormat;
136 public String getId() {
140 public String getXpath() {
141 return String.format(xpathFormat, id);