fix ui-ci tests
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / pages / ResourceLeftSideMenu.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.openqa.selenium.By;
23 import org.openqa.selenium.WebDriver;
24 import org.openqa.selenium.WebElement;
25 import org.openqa.selenium.support.ui.ExpectedConditions;
26
27 import static org.openecomp.sdc.ci.tests.pages.ResourceLeftSideMenu.XpathSelector.MAIN_DIV;
28 import static org.openecomp.sdc.ci.tests.pages.ResourceLeftSideMenu.XpathSelector.PROPERTIES_ASSIGNMENT_MENU;
29
30 /**
31  * Handles the Resource Page Left Side Menu UI actions
32  */
33 public class ResourceLeftSideMenu extends AbstractPageObject {
34
35     private WebElement wrappingElement;
36
37     public ResourceLeftSideMenu(final WebDriver webDriver) {
38         super(webDriver);
39         timeoutInSeconds = 5;
40     }
41
42     @Override
43     public void isLoaded() {
44         wrappingElement = getWrappingElement();
45     }
46
47     /**
48      * Gets the enclosing element of the menu.
49      *
50      * @return the enclosing element
51      */
52     public WebElement getWrappingElement() {
53         return getWait()
54             .until(ExpectedConditions.visibilityOfElementLocated(By.className(MAIN_DIV.getId())));
55     }
56
57     /**
58      * Clicks on the properties assignment menu item.
59      *
60      * @return the next page object
61      */
62     public ResourcePropertiesAssignmentPage clickOnPropertiesAssignmentMenuItem() {
63         wrappingElement.findElement(By.xpath(PROPERTIES_ASSIGNMENT_MENU.getXpath())).click();
64         return new ResourcePropertiesAssignmentPage(webDriver);
65     }
66
67     /**
68      * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
69      */
70     public enum XpathSelector {
71         MAIN_DIV("w-sdc-left-sidebar", "//div[@class='%s']"),
72         PROPERTIES_ASSIGNMENT_MENU("Properties AssignmentLeftSideMenu", "//*[@data-tests-id='%s']");
73
74         private final String id;
75         private final String xpathFormat;
76
77         XpathSelector(final String id, final String xpathFormat) {
78             this.id = id;
79             this.xpathFormat = xpathFormat;
80         }
81
82         public String getId() {
83             return id;
84         }
85
86         public String getXpath() {
87             return String.format(xpathFormat, id);
88         }
89     }
90
91 }