2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.sdc.frontend.ci.tests.pages;
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;
34 import java.util.List;
35 import java.util.function.Supplier;
37 public class GeneralPageElements {
39 private static final int WAIT_FOR_ELEMENT_TIME_OUT = 60;
40 private static final int WAIT_FOR_ELEMENT_TIME_OUT_DIVIDER = 10;
42 protected GeneralPageElements() {
46 public static ResourceLeftMenu getLeftMenu() {
47 return new ResourceLeftMenu();
50 public static void clickOKButton() {
51 SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on the OK button");
52 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ModalItems.OK.getValue());
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.");
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());
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();
76 public static void clickUpdateButton() {
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);
87 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtons.SEARCH_BOX.getValue());
88 GeneralUIUtils.ultimateWait();
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();
97 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtons.SEARCH_BOX.getValue(), WAIT_FOR_ELEMENT_TIME_OUT);
98 GeneralUIUtils.ultimateWait();
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();
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);
118 public static void restoreComponentFromElementPage(String componentName) throws Exception {
119 clickRestoreButton(componentName);
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());
127 public static void clickArchivedButtonFromCatalog(String componentName) throws Exception {
128 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
129 GeneralUIUtils.findComponentAndClick(componentName);
130 clickArchiveButton(componentName);
133 public static void archiveComponentFromElementPage(String componentName) throws Exception {
134 clickArchiveButton(componentName);
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));
144 public static void clickCertifyButton(String componentName) throws Exception {
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");
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");
161 public static void clickCertifyButtonNoUpgradePopupDismiss(String componentName) throws Exception {
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");
173 public static void clickCertifyButtonNoUpgradePopupDismissErrorCase(String componentName) throws Exception {
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();
181 } catch (Exception e) {
182 throw new Exception("Certification of " + componentName + " failed");
186 public static void clickUpgradeServicesCloseButton() {
187 WebElement closeButton = null;
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 ...");
193 } catch (WebDriverException e) {
195 UpgradeServicesPopup.setUpgradePopupShown(false);
196 SetupCDTest.getExtendTest().log(Status.INFO, "Update Services popup is not shown, continuing ...");
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();
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());
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());
219 public static String getLifeCycleState() {
220 return GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.LIFECYCLE_STATE.getValue()).getText();
223 public static String getWebElementTextByTestId(String dataTestIdEnumValue) {
224 return GeneralUIUtils.getWebElementByTestID(dataTestIdEnumValue).getText();
227 public static void selectVersion(String version) {
228 GeneralUIUtils.getSelectList(version, DataTestIdEnum.GeneralElementsEnum.VERSION_HEADER.getValue());
229 GeneralUIUtils.ultimateWait();
232 public static List<WebElement> getElementsFromTable() {
233 GeneralUIUtils.ultimateWait();
234 return GeneralUIUtils.getElementsByLocator(By.className("datatable-body"));
237 public static boolean checkElementsCountInTable(int expectedElementsCount) {
238 return checkElementsCountInTable(expectedElementsCount, () -> getElementsFromTable());
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());
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());
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();
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();
265 public static void clickOnHomeButton() {
266 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtonsFromInsideFrame.HOME_BUTTON.getValue()).click();