Update integration UI tests selenium image
[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     public static void clickCertifyButton(String componentName) throws Exception {
145         try {
146             SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on certify button");
147             GeneralUIUtils.clickOnAreaJS(DataTestIdEnum.LifeCyleChangeButtons.CERTIFY.getValue());
148             GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.DistributionChangeButtons.APPROVE_MESSAGE.getValue())
149                     .sendKeys("resource " + componentName + " certified successfully");
150             clickOKButton();
151             GeneralUIUtils.ultimateWait();
152             GeneralUIUtils.waitForElementInVisibilityBy(By.className("notification-container"), 10000);
153             HomePage.navigateToHomePage();
154             GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtons.SEARCH_BOX.getValue(), GeneralUIUtils.getTimeOut() / WAIT_FOR_ELEMENT_TIME_OUT_DIVIDER);
155             GeneralUIUtils.ultimateWait();
156         } catch (Exception e) {
157             throw new Exception("Certification of " + componentName + " failed");
158         }
159     }
160
161     public static void clickCertifyButtonNoUpgradePopupDismiss(String componentName) throws Exception {
162         try {
163             SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on certify button");
164             GeneralUIUtils.clickOnAreaJS(DataTestIdEnum.LifeCyleChangeButtons.CERTIFY.getValue());
165             GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.DistributionChangeButtons.APPROVE_MESSAGE.getValue())
166                     .sendKeys("resource " + componentName + " certified successfully");
167             GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ModalItems.OK.getValue()).click();
168         } catch (Exception e) {
169             throw new Exception("Certification of " + componentName + " failed");
170         }
171     }
172
173     public static void clickCertifyButtonNoUpgradePopupDismissErrorCase(String componentName) throws Exception {
174         try {
175             SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on certify button");
176             GeneralUIUtils.clickOnAreaJS(DataTestIdEnum.LifeCyleChangeButtons.CERTIFY.getValue());
177             GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.DistributionChangeButtons.APPROVE_MESSAGE.getValue())
178                     .sendKeys("resource " + componentName + " certified successfully");
179             GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ModalItems.OK.getValue()).click();
180             clickOKButton();
181         } catch (Exception e) {
182             throw new Exception("Certification of " + componentName + " failed");
183         }
184     }
185
186     public static void clickUpgradeServicesCloseButton() {
187         WebElement closeButton = null;
188         try {
189             closeButton = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ModalItems.UPGRADE_SERVICES_CANCEL.getValue(), GeneralUIUtils.getTimeOut() / WAIT_FOR_ELEMENT_TIME_OUT_DIVIDER);
190             UpgradeServicesPopup.setUpgradePopupShown(true);
191             SetupCDTest.getExtendTest().log(Status.INFO, "Closing Update Services popup with X button ...");
192             closeButton.click();
193         } catch (WebDriverException e) {
194             // regular flow
195             UpgradeServicesPopup.setUpgradePopupShown(false);
196             SetupCDTest.getExtendTest().log(Status.INFO, "Update Services popup is not shown, continuing ...");
197         }
198     }
199
200     public static void clickCheckoutButton() throws Exception {
201         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on CHECKOUT button ...");
202         GeneralUIUtils.clickOnAreaJS(DataTestIdEnum.GeneralElementsEnum.CHECKOUT_BUTTON.getValue());
203         GeneralUIUtils.ultimateWait();
204     }
205
206
207     public static void clickDeleteVersionButton() throws Exception {
208         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on DELETE VERSION button ...");
209         GeneralUIUtils.ultimateWait();
210         GeneralUIUtils.clickOnAreaJS(DataTestIdEnum.GeneralElementsEnum.DELETE_VERSION_BUTTON.getValue());
211         GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.GeneralElementsEnum.OK.getValue());
212     }
213
214     public static void clickRevertButton() throws Exception {
215         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on REVERT button ...");
216         GeneralUIUtils.clickOnAreaJS(DataTestIdEnum.GeneralElementsEnum.REVERT_BUTTON.getValue());
217     }
218
219     public static String getLifeCycleState() {
220         return GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.LIFECYCLE_STATE.getValue()).getText();
221     }
222
223     public static String getWebElementTextByTestId(String dataTestIdEnumValue) {
224         return GeneralUIUtils.getWebElementByTestID(dataTestIdEnumValue).getText();
225     }
226
227     public static void selectVersion(String version) {
228         GeneralUIUtils.getSelectList(version, DataTestIdEnum.GeneralElementsEnum.VERSION_HEADER.getValue());
229         GeneralUIUtils.ultimateWait();
230     }
231
232     public static List<WebElement> getElementsFromTable() {
233         GeneralUIUtils.ultimateWait();
234         return GeneralUIUtils.getElementsByLocator(By.className("datatable-body"));
235     }
236
237     public static boolean checkElementsCountInTable(int expectedElementsCount) {
238         return checkElementsCountInTable(expectedElementsCount, () -> getElementsFromTable());
239     }
240
241
242     public static void clickTrashButtonAndConfirm() throws InterruptedException {
243         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on TRASH button ...");
244         GeneralUIUtils.clickOnAreaJS(DataTestIdEnum.GeneralElementsEnum.DELETE_VERSION_BUTTON.getValue());
245         clickOKButton();
246     }
247
248     public static void clickBrowseButton() throws InterruptedException {
249         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on Browse button ...");
250         GeneralUIUtils.clickOnAreaJS(DataTestIdEnum.ModalItems.BROWSE_BUTTON.getValue());
251     }
252
253     public static boolean checkElementsCountInTable(int expectedElementsCount, Supplier<List<WebElement>> func) {
254         SetupCDTest.getExtendTest().log(Status.INFO, "Checking the number of elements in the table; should be " + (expectedElementsCount - 1));
255         GeneralUIUtils.ultimateWait();
256         return true;
257     }
258
259     public static void clickDeleteFile() throws Exception {
260         SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on delete file X-button ...");
261         GeneralUIUtils.clickOnAreaJS(GeneralUIUtils.getWebElementBy(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 }