re base code
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / pages / GeneralPageElements.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.openecomp.sdc.ci.tests.pages;
22
23 import com.aventstack.extentreports.Status;
24 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
25 import org.openecomp.sdc.ci.tests.datatypes.TopMenuButtonsEnum;
26 import org.openecomp.sdc.ci.tests.execute.setup.ExtentTestActions;
27 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
28 import org.openecomp.sdc.ci.tests.utilities.CatalogUIUtilitis;
29 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
30 import org.openqa.selenium.By;
31 import org.openqa.selenium.WebDriverException;
32 import org.openqa.selenium.WebElement;
33
34 import java.util.List;
35 import java.util.function.Supplier;
36
37 public class GeneralPageElements {
38
39     public GeneralPageElements() {
40         super();
41     }
42
43     public static ResourceLeftMenu getLeftMenu() {
44         return new ResourceLeftMenu();
45     }
46
47     public static void clickOKButton() {
48         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on the OK button");
49         GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ModalItems.OK.getValue());
50     }
51
52     public static void clickCreateButton() {
53         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on the CREATE/UPDATE button.");
54         GeneralUIUtils.clickOnAreaJS(DataTestIdEnum.GeneralElementsEnum.CREATE_BUTTON.getValue());
55         GeneralUIUtils.ultimateWait();
56         GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.CHECKIN_BUTTON.getValue());
57         ExtentTestActions.log(Status.INFO, "Succeeded.");
58     }
59
60     public static void clickCreateButton(int timeout) {
61         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on the CREATE/UPDATE button");
62         GeneralUIUtils.clickOnAreaJS(DataTestIdEnum.GeneralElementsEnum.CREATE_BUTTON.getValue(), timeout);
63         GeneralUIUtils.ultimateWait();
64         GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.CHECKIN_BUTTON.getValue());
65     }
66
67     public static void clickCreateUpdateButton(int timeout) {
68         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on the CREATE/UPDATE button");
69         GeneralUIUtils.clickOnAreaJS(DataTestIdEnum.GeneralElementsEnum.CREATE_BUTTON.getValue(), timeout);
70         GeneralUIUtils.ultimateWait();
71     }
72
73     public static void clickUpdateButton() {
74         clickCreateButton();
75     }
76
77     public static void clickCheckinButton(String componentName) throws Exception {
78         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on the CHECKIN button");
79         GeneralUIUtils.ultimateWait();
80         GeneralUIUtils.clickOnAreaJS(DataTestIdEnum.GeneralElementsEnum.CHECKIN_BUTTON.getValue());
81         GeneralUIUtils.ultimateWait();
82         GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ModalItems.ACCEPT_TESTING_MESSAGE.getValue()).sendKeys("Checkin " + componentName);
83         clickOKButton();
84         GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtons.SEARCH_BOX.getValue());
85         GeneralUIUtils.ultimateWait();
86     }
87
88     public static void clickSubmitForTestingButton(String componentName) throws Exception {
89         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on the submitting for testing button");
90         GeneralUIUtils.clickOnAreaJS(DataTestIdEnum.GeneralElementsEnum.SUBMIT_FOR_TESTING_BUTTON.getValue());
91         GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ModalItems.SUMBIT_FOR_TESTING_MESSAGE.getValue()).sendKeys("Submit for testing " + componentName);
92         GeneralUIUtils.ultimateWait();
93         clickOKButton();
94         GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtons.SEARCH_BOX.getValue(), 60);
95         GeneralUIUtils.ultimateWait();
96     }
97
98     public static void clickSubmitForTestingButtonErrorCase(String componentName) throws Exception {
99         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on the submitting for testing button");
100         GeneralUIUtils.clickOnAreaJS(DataTestIdEnum.GeneralElementsEnum.SUBMIT_FOR_TESTING_BUTTON.getValue());
101         GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ModalItems.SUMBIT_FOR_TESTING_MESSAGE.getValue()).sendKeys("Submit for testing " + componentName);
102         GeneralUIUtils.ultimateWait();
103         clickOKButton();
104         clickOKButton();
105     }
106
107     public static void restoreComponentFromArchivedCatalog(String componentName) throws Exception {
108         GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.MainMenuButtonsFromInsideFrame.HOME_BUTTON.getValue());
109         GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.CatalogSwitchButtons.CATALOG_SWITCH_BUTTON.getValue());
110         GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.CatalogSwitchButtons.CATALOG_ARCHIVE.getValue());
111         GeneralUIUtils.findComponentAndClick(componentName);
112         clickRestoreButton(componentName);
113     }
114
115     public static void restoreComponentFromElementPage(String componentName) throws Exception {
116         clickRestoreButton(componentName);
117     }
118
119     private static void clickRestoreButton(String componentName){
120         SetupCDTest.getExtendTest().log(Status.INFO, String.format("Going to restore component: %s", componentName));
121         GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.GeneralElementsEnum.RESTORE_BUTTON.getValue());
122     }
123
124     public static void clickArchivedButtonFromCatalog(String componentName) throws Exception {
125         CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
126         GeneralUIUtils.findComponentAndClick(componentName);
127         clickArchiveButton(componentName);
128     }
129
130     public static void archiveComponentFromElementPage(String componentName) throws Exception {
131         clickArchiveButton(componentName);
132     }
133
134     private static void clickArchiveButton(String componentName){
135         SetupCDTest.getExtendTest().log(Status.INFO, String.format("Going to archive component: %s", componentName));
136         GeneralUIUtils.hoverOnAreaByTestId(DataTestIdEnum.GeneralElementsEnum.ARCHIVE_BUTTON.getValue());
137         GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.GeneralElementsEnum.ARCHIVE_BUTTON.getValue());
138         SetupCDTest.getExtendTest().log(Status.INFO, String.format("Component %s archived successfully", componentName));
139     }
140
141     //TODO should implement real code
142     public static void clickCertifyButton(String componentName) throws Exception {
143         try {
144             SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on certify button");
145             GeneralUIUtils.clickOnAreaJS(DataTestIdEnum.LifeCyleChangeButtons.CERTIFY.getValue());
146             GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.DistributionChangeButtons.APPROVE_MESSAGE.getValue())
147                     .sendKeys("resource " + componentName + " certified successfully");
148             clickOKButton();
149             clickUpgradeServicesCloseButton();
150             GeneralUIUtils.ultimateWait();
151             HomePage.navigateToHomePage();
152             GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtons.SEARCH_BOX.getValue(), GeneralUIUtils.getTimeOut()/10);
153         } catch (Exception e) {
154             throw new Exception("Certification of " + componentName + " failed");
155         }
156     }
157
158     public static void clickCertifyButtonNoUpgradePopupDismiss(String componentName) throws Exception {
159         try {
160             SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on certify button");
161             GeneralUIUtils.clickOnAreaJS(DataTestIdEnum.LifeCyleChangeButtons.CERTIFY.getValue());
162             GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.DistributionChangeButtons.APPROVE_MESSAGE.getValue())
163                     .sendKeys("resource " + componentName + " certified successfully");
164             GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ModalItems.OK.getValue()).click();
165         } catch (Exception e) {
166             throw new Exception("Certification of " + componentName + " failed");
167         }
168     }
169
170     public static void clickCertifyButtonNoUpgradePopupDismissErrorCase(String componentName) throws Exception {
171         try {
172             SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on certify button");
173             GeneralUIUtils.clickOnAreaJS(DataTestIdEnum.LifeCyleChangeButtons.CERTIFY.getValue());
174             GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.DistributionChangeButtons.APPROVE_MESSAGE.getValue())
175                     .sendKeys("resource " + componentName + " certified successfully");
176             GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ModalItems.OK.getValue()).click();
177             clickOKButton();
178         } catch (Exception e) {
179             throw new Exception("Certification of " + componentName + " failed");
180         }
181     }
182
183     public static void clickUpgradeServicesCloseButton(){
184         WebElement closeButton = null;
185         try {
186             closeButton = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ModalItems.UPGRADE_SERVICES_CANCEL.getValue(), GeneralUIUtils.getTimeOut()/10);
187             UpgradeServicesPopup.setUpgradePopupShown(true);
188             SetupCDTest.getExtendTest().log(Status.INFO, "Closing Update Services popup with X button ...");
189             closeButton.click();
190         }catch (WebDriverException e){
191             // regular flow
192             UpgradeServicesPopup.setUpgradePopupShown(false);
193             SetupCDTest.getExtendTest().log(Status.INFO, "Update Services popup is not shown, continuing ...");
194         }
195     }
196
197     public static void clickCheckoutButton() throws Exception {
198         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on CHECKOUT button ...");
199         GeneralUIUtils.clickOnAreaJS(DataTestIdEnum.GeneralElementsEnum.CHECKOUT_BUTTON.getValue());
200         GeneralUIUtils.ultimateWait();
201     }
202
203
204
205
206     public static void clickDeleteVersionButton() throws Exception {
207         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on DELETE VERSION button ...");
208         GeneralUIUtils.ultimateWait();
209         GeneralUIUtils.clickOnAreaJS(DataTestIdEnum.GeneralElementsEnum.DELETE_VERSION_BUTTON.getValue());
210         GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.GeneralElementsEnum.OK.getValue());
211     }
212
213     public static void clickRevertButton() throws Exception {
214         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on REVERT button ...");
215         GeneralUIUtils.clickOnAreaJS(DataTestIdEnum.GeneralElementsEnum.REVERT_BUTTON.getValue());
216     }
217
218     public static String getLifeCycleState() {
219         return GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.LIFECYCLE_STATE.getValue()).getText();
220     }
221
222     public static String getWebElementTextByTestId(String dataTestIdEnumValue) {
223         return GeneralUIUtils.getWebElementByTestID(dataTestIdEnumValue).getText();
224     }
225
226     public static void selectVersion(String version) {
227         GeneralUIUtils.getSelectList(version, DataTestIdEnum.GeneralElementsEnum.VERSION_HEADER.getValue());
228         GeneralUIUtils.ultimateWait();
229     }
230
231     public static List<WebElement> getElemenetsFromTable() {
232         GeneralUIUtils.ultimateWait();
233         return GeneralUIUtils.getElemenetsFromTable(By.className("flex-container"));
234     }
235
236     public static boolean checkElementsCountInTable(int expectedElementsCount) {
237         return checkElementsCountInTable(expectedElementsCount, () -> getElemenetsFromTable());
238     }
239
240
241     public static void clickTrashButtonAndConfirm() throws InterruptedException {
242         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on TRASH button ...");
243         GeneralUIUtils.clickOnAreaJS(DataTestIdEnum.GeneralElementsEnum.DELETE_VERSION_BUTTON.getValue());
244         clickOKButton();
245         }
246
247     public static void clickBrowseButton() throws InterruptedException{
248         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Browse button ...");
249         GeneralUIUtils.clickOnAreaJS(DataTestIdEnum.ModalItems.BROWSE_BUTTON.getValue());
250     }
251
252     public static boolean checkElementsCountInTable(int expectedElementsCount, Supplier<List<WebElement>> func) {
253         SetupCDTest.getExtendTest().log(Status.INFO, "Checking the number of elements in the table; should be " + (expectedElementsCount - 1));
254         GeneralUIUtils.ultimateWait();
255         return true;
256     }
257
258     public static void clickDeleteFile() throws Exception {
259         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on delete file X-button ...");
260         GeneralUIUtils.clickOnAreaJS(GeneralUIUtils.getWebElementBy
261                 (By.cssSelector("div[class='i-sdc-form-file-upload-x-btn']")));
262         GeneralUIUtils.ultimateWait();
263     }
264
265         public static void clickOnHomeButton() {
266                 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtonsFromInsideFrame.HOME_BUTTON.getValue()).click();
267         }
268
269 }