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