Onboard PNF software version Ui test case
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / pages / TopNavComponent.java
1 /*
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
8  *
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.
15  *
16  *  SPDX-License-Identifier: Apache-2.0
17  *  ============LICENSE_END=========================================================
18  */
19
20 package org.openecomp.sdc.ci.tests.pages;
21
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;
27
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;
38
39 /**
40  * Handles the Top Navigation Component UI actions
41  */
42 public class TopNavComponent extends AbstractPageObject {
43
44     private static final Logger LOGGER = LoggerFactory.getLogger(TopNavComponent.class);
45
46     private WebElement wrappingElement;
47     private By navLocator = By.xpath(NAV.getXpath());
48
49     public TopNavComponent(final WebDriver webDriver) {
50         super(webDriver);
51         timeoutInSeconds = 5;
52     }
53
54     @Override
55     public void isLoaded() {
56         wrappingElement = getWrappingElement();
57     }
58
59     /**
60      * Gets the enclosing element of the component.
61      *
62      * @return the enclosing element
63      */
64     public WebElement getWrappingElement() {
65         LOGGER.debug("Finding element with xpath '{}'", NAV.getXpath());
66         return waitForElementVisibility(navLocator);
67     }
68
69     /**
70      * Clicks on home link inside the first breadcrumb arrow.
71      */
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();
77         getWait()
78             .until(ExpectedConditions.visibilityOfElementLocated(By.xpath(REPOSITORY_ICON.getXpath())));
79     }
80
81     /**
82      * Clicks on the VSP repository icon.
83      *
84      * @return the next page object
85      */
86     public VspRepositoryModalComponent clickOnRepositoryIcon() {
87         wrappingElement.findElement(By.xpath(REPOSITORY_ICON.getXpath())).click();
88         return new VspRepositoryModalComponent(webDriver);
89     }
90
91     /**
92      * Clicks on the Onboard button.
93      *
94      * @return the next page object
95      */
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()));
99     }
100
101     /**
102      * Hover to a breadcrumb arrow of the given position.
103      *
104      * @param arrowPosition the position of the arrow from left to right
105      * @return the hovered breadcrumb arrow element
106      */
107     public WebElement hoverToBreadcrumbArrow(final int arrowPosition) {
108         final Actions actions = new Actions(GeneralUIUtils.getDriver());
109         final List<WebElement> arrowElementList = getWait()
110             .until(
111                 ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath(ARROW_DROPDOWN.getXpath())));
112         final WebElement selectedArrowElement = arrowElementList.get(arrowPosition);
113         actions.moveToElement(selectedArrowElement).perform();
114         return selectedArrowElement;
115     }
116
117     /**
118      * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
119      */
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']");
126
127         private final String id;
128         private final String xpathFormat;
129
130         XpathSelector(final String id, final String xpathFormat) {
131             this.id = id;
132             this.xpathFormat = xpathFormat;
133         }
134
135         public String getId() {
136             return id;
137         }
138
139         public String getXpath() {
140             return String.format(xpathFormat, id);
141         }
142     }
143
144 }