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.openecomp.sdc.ci.tests.pages;
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;
34 import java.util.List;
35 import java.util.function.Supplier;
37 public class GeneralPageElements {
39 public GeneralPageElements() {
43 public static ResourceLeftMenu getLeftMenu() {
44 return new ResourceLeftMenu();
47 public static void clickOKButton() {
48 SetupCDTest.getExtendTest().log(Status.INFO, "Clicking on the OK button");
49 GeneralUIUtils.clickOnElementByTestId(DataTestIdEnum.ModalItems.OK.getValue());
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.");
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());
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();
73 public static void clickUpdateButton() {
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);
84 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtons.SEARCH_BOX.getValue());
85 GeneralUIUtils.ultimateWait();
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();
94 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtons.SEARCH_BOX.getValue(), 60);
95 GeneralUIUtils.ultimateWait();
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();
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);
115 public static void restoreComponentFromElementPage(String componentName) throws Exception {
116 clickRestoreButton(componentName);
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());
124 public static void clickArchivedButtonFromCatalog(String componentName) throws Exception {
125 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
126 GeneralUIUtils.findComponentAndClick(componentName);
127 clickArchiveButton(componentName);
130 public static void archiveComponentFromElementPage(String componentName) throws Exception {
131 clickArchiveButton(componentName);
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));
141 //TODO should implement real code
142 public static void clickCertifyButton(String componentName) throws Exception {
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");
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");
158 public static void clickCertifyButtonNoUpgradePopupDismiss(String componentName) throws Exception {
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");
170 public static void clickCertifyButtonNoUpgradePopupDismissErrorCase(String componentName) throws Exception {
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();
178 } catch (Exception e) {
179 throw new Exception("Certification of " + componentName + " failed");
183 public static void clickUpgradeServicesCloseButton(){
184 WebElement closeButton = null;
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 ...");
190 }catch (WebDriverException e){
192 UpgradeServicesPopup.setUpgradePopupShown(false);
193 SetupCDTest.getExtendTest().log(Status.INFO, "Update Services popup is not shown, continuing ...");
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();
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());
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());
218 public static String getLifeCycleState() {
219 return GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.LIFECYCLE_STATE.getValue()).getText();
222 public static String getWebElementTextByTestId(String dataTestIdEnumValue) {
223 return GeneralUIUtils.getWebElementByTestID(dataTestIdEnumValue).getText();
226 public static void selectVersion(String version) {
227 GeneralUIUtils.getSelectList(version, DataTestIdEnum.GeneralElementsEnum.VERSION_HEADER.getValue());
228 GeneralUIUtils.ultimateWait();
231 public static List<WebElement> getElemenetsFromTable() {
232 GeneralUIUtils.ultimateWait();
233 return GeneralUIUtils.getElemenetsFromTable(By.className("flex-container"));
236 public static boolean checkElementsCountInTable(int expectedElementsCount) {
237 return checkElementsCountInTable(expectedElementsCount, () -> getElemenetsFromTable());
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());
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());
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();
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();
265 public static void clickOnHomeButton() {
266 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtonsFromInsideFrame.HOME_BUTTON.getValue()).click();