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 //TODO should implement real code
145 public static void clickCertifyButton(String componentName) throws Exception {
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");
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");
163 public static void clickCertifyButtonNoUpgradePopupDismiss(String componentName) throws Exception {
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");
175 public static void clickCertifyButtonNoUpgradePopupDismissErrorCase(String componentName) throws Exception {
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();
183 } catch (Exception e) {
184 throw new Exception("Certification of " + componentName + " failed");
188 public static void clickUpgradeServicesCloseButton() {
189 WebElement closeButton = null;
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 ...");
195 } catch (WebDriverException e) {
197 UpgradeServicesPopup.setUpgradePopupShown(false);
198 SetupCDTest.getExtendTest().log(Status.INFO, "Update Services popup is not shown, continuing ...");
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();
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());
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());
221 public static String getLifeCycleState() {
222 return GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.LIFECYCLE_STATE.getValue()).getText();
225 public static String getWebElementTextByTestId(String dataTestIdEnumValue) {
226 return GeneralUIUtils.getWebElementByTestID(dataTestIdEnumValue).getText();
229 public static void selectVersion(String version) {
230 GeneralUIUtils.getSelectList(version, DataTestIdEnum.GeneralElementsEnum.VERSION_HEADER.getValue());
231 GeneralUIUtils.ultimateWait();
234 public static List<WebElement> getElementsFromTable() {
235 GeneralUIUtils.ultimateWait();
236 return GeneralUIUtils.getElementsByLocator(By.className("datatable-body"));
239 public static boolean checkElementsCountInTable(int expectedElementsCount) {
240 return checkElementsCountInTable(expectedElementsCount, () -> getElementsFromTable());
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());
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());
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();
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();
267 public static void clickOnHomeButton() {
268 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtonsFromInsideFrame.HOME_BUTTON.getValue()).click();