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