f0a973910f2daf2ea98c4267129bf7f346fea856
[sdc.git] / integration-tests / src / test / java / org / onap / sdc / frontend / 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.onap.sdc.frontend.ci.tests.pages;
21
22 import lombok.AllArgsConstructor;
23 import lombok.Getter;
24 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.CompositionPage;
25 import org.onap.sdc.frontend.ci.tests.pages.component.workspace.ToscaArtifactsPage;
26 import org.openqa.selenium.By;
27 import org.openqa.selenium.WebDriver;
28 import org.openqa.selenium.WebElement;
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         waitToBeClickable(By.xpath(XpathSelector.GENERAL_MENU.getXpath()));
46     }
47
48     /**
49      * Gets the enclosing element of the menu.
50      *
51      * @return the enclosing element
52      */
53     public WebElement getWrappingElement() {
54         return waitForElementVisibility(By.className(XpathSelector.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(XpathSelector.PROPERTIES_ASSIGNMENT_MENU.getXpath())).click();
64         return new ResourcePropertiesAssignmentPage(webDriver);
65     }
66
67     /**
68      * Clicks on the 'Attributes & Outputs' menu item.
69      *
70      * @return the next page object
71      */
72     public AttributesOutputsPage clickOnAttributesOutputsMenuItem() {
73         wrappingElement.findElement(By.xpath(XpathSelector.ATTRIBUTES_OUTPUTS_MENU.getXpath())).click();
74         return new AttributesOutputsPage(webDriver);
75     }
76
77     /**
78      * Clicks on the 'Attributes' menu item.
79      *
80      * @return the next page object
81      */
82     public AttributesPage clickOnAttributesMenuItem() {
83         wrappingElement.findElement(By.xpath(XpathSelector.ATTRIBUTES_MENU.getXpath())).click();
84         return new AttributesPage(webDriver);
85     }
86
87     /**
88      * Clicks on the TOSCA artifacts menu item.
89      *
90      * @return the next page object
91      */
92     public ToscaArtifactsPage clickOnToscaArtifactsMenuItem() {
93         wrappingElement.findElement(By.xpath(XpathSelector.TOSCA_ARTIFACTS_MENU.getXpath())).click();
94         return new ToscaArtifactsPage(webDriver);
95     }
96
97     /**
98      * Clicks on the 'General' menu item.
99      *
100      * @return the next page object
101      */
102     public <T extends ComponentPage> T clickOnGeneralMenuItem(Class<? extends T> clazz) {
103         wrappingElement.findElement(By.xpath(XpathSelector.GENERAL_MENU.getXpath())).click();
104         return (T) new ComponentPage(webDriver);
105     }
106
107     public CompositionPage clickOnCompositionMenuItem() {
108         wrappingElement.findElement(By.xpath(XpathSelector.COMPOSITION_MENU.getXpath())).click();
109         return new CompositionPage(webDriver);
110     }
111
112     public ResourcePropertiesPage clickOnPropertiesMenuItem() {
113         wrappingElement.findElement(By.xpath(XpathSelector.PROPERTIES_MENU.getXpath())).click();
114         return new ResourcePropertiesPage(webDriver);
115     }
116
117     /**
118      * Enum that contains identifiers and xpath expressions to elements related to the enclosing page object.
119      */
120     @AllArgsConstructor
121     private enum XpathSelector {
122         MAIN_DIV("w-sdc-left-sidebar", "//div[@class='%s']"),
123         PROPERTIES_ASSIGNMENT_MENU("Properties AssignmentLeftSideMenu", "//*[@data-tests-id='%s']"),
124         PROPERTIES_MENU("PropertiesLeftSideMenu", "//*[@data-tests-id='%s']"),
125         ATTRIBUTES_OUTPUTS_MENU("Attributes & OutputsLeftSideMenu", "//*[@data-tests-id='%s']"),
126         ATTRIBUTES_MENU("AttributesLeftSideMenu", "//*[@data-tests-id='%s']"),
127         GENERAL_MENU("GeneralLeftSideMenu", "//*[@data-tests-id='%s']"),
128         COMPOSITION_MENU("CompositionLeftSideMenu", "//*[@data-tests-id='%s']"),
129         REQUIREMENT_CAPABILITY_MENU("Req. & CapabilitiesLeftSideMenu", "//*[@data-tests-id='%s']"),
130         TOSCA_ARTIFACTS_MENU("TOSCA ArtifactsLeftSideMenu", "//*[@data-tests-id='%s']");
131
132         @Getter
133         private final String id;
134         private final String xpathFormat;
135
136         public String getXpath() {
137             return String.format(xpathFormat, id);
138         }
139     }
140
141 }