Provide user to specify the ouput name while declaring the atrributes
[sdc.git] / integration-tests / src / test / java / org / onap / sdc / frontend / ci / tests / pages / CompositionPage.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.sdc.frontend.ci.tests.pages;
22
23 import com.aventstack.extentreports.Status;
24 import org.onap.sdc.frontend.ci.tests.datatypes.CanvasElement;
25 import org.onap.sdc.frontend.ci.tests.datatypes.CanvasManager;
26 import org.onap.sdc.frontend.ci.tests.datatypes.DataTestIdEnum;
27 import org.onap.sdc.frontend.ci.tests.datatypes.DataTestIdEnum.LeftPanelCanvasItems;
28 import org.onap.sdc.frontend.ci.tests.execute.setup.SetupCDTest;
29 import org.onap.sdc.frontend.ci.tests.utilities.GeneralUIUtils;
30 import org.openqa.selenium.By;
31 import org.openqa.selenium.WebElement;
32 import org.openqa.selenium.interactions.Actions;
33 import org.openqa.selenium.support.ui.Select;
34 import org.testng.AssertJUnit;
35
36 import java.util.List;
37
38 public class CompositionPage extends GeneralPageElements {
39
40     private CompositionPage() {
41         super();
42     }
43
44     public static UploadArtifactPopup artifactPopup() {
45         return new UploadArtifactPopup(true);
46     }
47
48     public static void searchForElement(String elementName) {
49         SetupCDTest.getExtendTest().log(Status.INFO, "Searching for " + elementName + " in the left panel");
50         WebElement searchField = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.CompositionScreenEnum.SEARCH_ASSET.getValue());
51         searchField.clear();
52         searchField.sendKeys(elementName);
53         GeneralUIUtils.ultimateWait();
54     }
55
56     public static void showDeploymentArtifactTab() throws Exception {
57         clickOnTabTestID(DataTestIdEnum.CompositionScreenEnum.DEPLOYMENT_ARTIFACT_TAB);
58     }
59
60     public static void showInformationsTab() throws Exception {
61         clickOnTabTestID(DataTestIdEnum.CompositionScreenEnum.INFORMATION_TAB);
62     }
63
64     public static void showPropertiesAndAttributesTab() throws Exception {
65         clickOnTabTestID(DataTestIdEnum.CompositionScreenEnum.PROPERTIES_AND_ATTRIBUTES_TAB);
66     }
67
68     public static List<WebElement> getProperties() {
69         return PropertiesPage.getElemenetsFromTable();
70     }
71
72     public static List<WebElement> getDeploymentArtifacts() {
73         return getAllAddedArtifacts();
74     }
75
76     public static List<WebElement> getAllAddedArtifacts() {
77         String dataTestsId = DataTestIdEnum.CompositionScreenEnum.ARTIFACTS_LIST.getValue();
78         return GeneralUIUtils.getWebElementsListBy(By.xpath("//*[contains(@data-tests-id,'" + dataTestsId + "')]"));
79     }
80
81     public static void moveToInputsScreen() throws Exception {
82         openPagesMenu(2);
83         GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.CompositionScreenEnum.MENU_INPUTS.getValue());
84         //GeneralUIUtils.ultimateWait();
85     }
86
87     public static void moveToPropertiesScreen() throws Exception {
88         openPagesMenu(2);
89         GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.CompositionScreenEnum.MENU_PROPERTIES_ASSIGNMENT.getValue());
90         //GeneralUIUtils.ultimateWait();
91     }
92
93     public static void moveToOnboardScreen() throws Exception {
94         openPagesMenu(0);
95         GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.CompositionScreenEnum.MENU_ONBOARD.getValue());
96         //GeneralUIUtils.ultimateWait();
97     }
98
99     public static void moveToHomeScreen() throws Exception {
100         openPagesMenu(0);
101         GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.CompositionScreenEnum.MENU_HOME.getValue());
102         //GeneralUIUtils.ultimateWait();
103     }
104
105     private static void openPagesMenu(int counter) {
106         Actions actions = new Actions(GeneralUIUtils.getDriver());
107         List<WebElement> triangleList = GeneralUIUtils.getWebElementsListByClassName(DataTestIdEnum.CompositionScreenEnum.MENU_TRIANGLE_DROPDOWN.getValue());
108         WebElement pagesMenu = triangleList.get(counter);
109         actions.moveToElement(pagesMenu).perform();
110     }
111
112     public static void changeComponentVersion(CanvasManager canvasManager, CanvasElement element, String version) {
113         changeComponentVersion(canvasManager, element, version, false);
114     }
115
116     public static void changeComponentVersion(CanvasManager canvasManager, CanvasElement element, String version, boolean isValidate) {
117         try {
118             SetupCDTest.getExtendTest().log(Status.INFO, String.format("Changing component version to  %s", version));
119             canvasManager.clickOnCanvaElement(element);
120             GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.CompositionScreenEnum.CHANGE_VERSION.getValue());
121             //GeneralUIUtils.ultimateWait();
122             Select selectlist = new Select(GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.CompositionScreenEnum.CHANGE_VERSION.getValue()));
123             while (selectlist.getOptions().size() == 0) {
124                 selectlist = new Select(GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.CompositionScreenEnum.CHANGE_VERSION.getValue()));
125             }
126             GeneralUIUtils.ultimateWait();
127             selectlist.selectByValue(version);
128             GeneralUIUtils.ultimateWait();
129             GeneralUIUtils.clickSomewhereOnPage();
130
131             // Validate Selection
132             if (isValidate) {
133                 GeneralUIUtils.ultimateWait();
134                 canvasManager.clickOnCanvaElement(element);
135                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Validating component version changed to %s", version));
136                 String actualSelectedValue = GeneralUIUtils.getWebElementBy(By.xpath(String.format("//select[@data-tests-id='%s']//option[@selected='selected']", DataTestIdEnum.CompositionScreenEnum.CHANGE_VERSION.getValue()))).getText();
137                 AssertJUnit.assertTrue(actualSelectedValue.equals(version));
138             }
139         } catch (Exception e) {
140             throw e;
141         }
142     }
143
144     public static void clickAddArtifactButton() throws Exception {
145         clickOnTabTestID(DataTestIdEnum.CompositionScreenEnum.ADD_ARTIFACT);
146         GeneralUIUtils.getWebElementByClassName("sdc-add-artifact");
147     }
148
149     public static String getSelectedInstanceName() {
150         return GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.CompositionRightPanel.COMPONENT_TITLE.getValue()).getText();
151     }
152
153     public static void showInformationArtifactTab() throws Exception {
154         clickOnTab(DataTestIdEnum.CompositionScreenEnum.INFORMATION_ARTIFACTS);
155     }
156
157     public static void showAPIArtifactTab() throws Exception {
158         clickOnTab(DataTestIdEnum.CompositionScreenEnum.API);
159     }
160
161     public static void showInformationTab() throws Exception {
162         clickOnTab(DataTestIdEnum.CompositionScreenEnum.INFORMATION);
163     }
164
165     public static void showCompositionTab() throws Exception {
166         clickOnTab(DataTestIdEnum.CompositionScreenEnum.COMPOSITION);
167     }
168
169     public static void showInputsTab() throws Exception {
170         clickOnTab(DataTestIdEnum.CompositionScreenEnum.INPUTS);
171     }
172
173     public static void showRequirementsAndCapabilitiesTab() throws Exception {
174         clickOnTab(DataTestIdEnum.CompositionScreenEnum.REQUIREMENTS_AND_CAPABILITIES);
175     }
176
177     public static List<WebElement> getOpenTabTitle() throws Exception {
178         return GeneralUIUtils.getElementsByCSS("expand-collapse ng-transclude");
179     }
180
181     public static void clickOnTab(DataTestIdEnum.CompositionScreenEnum tabSelector) throws Exception {
182         SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on %s", tabSelector.name()));
183         GeneralUIUtils.getElementsByCSS(tabSelector.getValue()).get(0).click();
184         GeneralUIUtils.ultimateWait();
185     }
186
187     public static void clickOnTabTestID(DataTestIdEnum.CompositionScreenEnum tabSelector) throws Exception {
188         SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on %s", tabSelector.name()));
189         GeneralUIUtils.getWebElementByTestID(tabSelector.getValue()).click();
190         GeneralUIUtils.ultimateWait();
191     }
192
193     public static CanvasElement addElementToCanvasScreen(LeftPanelCanvasItems elementName, CanvasManager vfCanvasManager) throws Exception {
194         CompositionPage.searchForElement(elementName.name());
195         return vfCanvasManager.createElementOnCanvas(elementName);
196     }
197
198     public static CanvasElement addElementToCanvasScreen(String elementName, CanvasManager vfCanvasManager) throws Exception {
199         CompositionPage.searchForElement(elementName);
200         return vfCanvasManager.createElementOnCanvas(elementName);
201     }
202
203     public static List<WebElement> getCompositionDeplymentArtifacts() {
204         return GeneralUIUtils.getWebElementsListByContainTestID(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.ARTIFACT_DISPLAY_NAME.getValue());
205     }
206
207     public static WebElement getCustomizationUUID() throws Exception {
208         return GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.CompositionScreenEnum.CUSTOMIZATION_UUID.getValue());
209     }
210
211
212     public static List<WebElement> getCompositionEnvArtifacts() {
213         return GeneralUIUtils.getWebElementsListByContainTestID(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.ARTIFACT_ENV.getValue());
214     }
215
216     public static WebElement clickDownloadEnvArtifactComposition(String fileName) {
217         GeneralUIUtils.hoverOnAreaByTestId(DataTestIdEnum.DeploymentArtifactCompositionRightMenu.ARTIFACT_ENV.getValue() + fileName);
218         return GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ArtifactPageEnum.DOWNLOAD_ARTIFACT_ENV.getValue() + fileName);
219     }
220
221     public static void setSingleProperty(String propertyDataTestID, String propertyValue) {
222         WebElement findElement = GeneralUIUtils.getWebElementByTestID(propertyDataTestID);
223         findElement.click();
224         PropertiesPage.getPropertyPopup().insertPropertyDefaultValue(propertyValue);
225         PropertiesPage.getPropertyPopup().clickSave();
226         GeneralUIUtils.ultimateWait();
227         findElement = GeneralUIUtils.getWebElementByTestID("value_" + propertyDataTestID);
228         SetupCDTest.getExtendTest().log(Status.INFO, String.format("Validating property %s is set", propertyValue));
229         AssertJUnit.assertTrue(findElement.getText().equals(propertyValue));
230         GeneralUIUtils.ultimateWait();
231     }
232
233
234 }