re base code
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / utilities / CatalogUIUtilitis.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.openecomp.sdc.ci.tests.utilities;
22
23 import com.aventstack.extentreports.Status;
24 import org.codehaus.jettison.json.JSONArray;
25 import org.codehaus.jettison.json.JSONException;
26 import org.openecomp.sdc.ci.tests.datatypes.CheckBoxStatusEnum;
27 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
28 import org.openecomp.sdc.ci.tests.datatypes.TopMenuButtonsEnum;
29 import org.openecomp.sdc.ci.tests.datatypes.TypesEnum;
30 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
31 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
32 import org.openecomp.sdc.ci.tests.utils.rest.CatalogRestUtils;
33 import org.openqa.selenium.WebElement;
34
35 import java.io.IOException;
36 import java.util.ArrayList;
37 import java.util.Arrays;
38 import java.util.List;
39
40 public class CatalogUIUtilitis {
41         
42
43         public static void clickTopMenuButton(TopMenuButtonsEnum button) {
44                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on %s button ...", button.name()));
45                 switch (button) {
46                 case CATALOG:
47                         GeneralUIUtils.getWebElementByTestID(button.getButton()).click();
48                         break;
49                 case HOME:
50                         GeneralUIUtils.getWebElementByTestID(button.getButton()).click();
51                         break;
52                 case ON_BOARDING:
53                         GeneralUIUtils.getWebElementByTestID(button.getButton()).click();
54                         break;
55                 default:
56                         break;
57                 }
58                 GeneralUIUtils.ultimateWait();
59         }
60         
61         public static String catalogFilterTypeChecBox(TypesEnum enumtype) throws Exception {
62                 String Type = enumtype.toString().toLowerCase();
63                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on %s ...", Type));
64                 GeneralUIUtils.getWebElementByTestID(enumtype.getValue()).click();
65                 return Type;
66         }
67         
68         public static List<String> catalogFilterStatusChecBox(CheckBoxStatusEnum statusEnum){
69                 List<String> status = null;
70                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on %s status", statusEnum.name()));
71                 switch (statusEnum) {
72                 case IN_DESIGN:
73                         status = Arrays.asList("NOT_CERTIFIED_CHECKIN", "NOT_CERTIFIED_CHECKOUT");
74                         GeneralUIUtils.getWebElementByTestID(statusEnum.getValue()).click();
75                         break;
76                 case READY_FOR_TESTING:
77                         status = Arrays.asList("READY_FOR_CERTIFICATION");
78                         GeneralUIUtils.getWebElementByTestID(statusEnum.getValue()).click();
79                         break;
80                 case IN_TESTING:
81                         status = Arrays.asList("CERTIFICATION_IN_PROGRESS");
82                         GeneralUIUtils.getWebElementByTestID(statusEnum.getValue()).click();
83                         break;
84                 case CERTIFIED:
85                 case DISTRIBUTED:
86                         status = Arrays.asList("CERTIFIED");
87                         GeneralUIUtils.getWebElementByTestID(statusEnum.getValue()).click();
88                         break;
89                 }
90                 return status;
91         }
92
93         // Get all Categories uniqueID .//The parent categories.
94         public static List<String> getCategories() throws IOException, JSONException {
95                 List<String> allCategoriesList = new ArrayList<>();
96                 RestResponse allcategoriesJson = CatalogRestUtils.getAllCategoriesTowardsCatalogBe();
97                 JSONArray categories = new JSONArray(allcategoriesJson.getResponse());
98                 for (int i = 0; i < categories.length(); i++) {
99                         String categoryname = (String) categories.getJSONObject(i).get("name");
100                         allCategoriesList.add(categoryname);
101                 }
102                 return allCategoriesList;
103         }
104
105         public static WebElement clickOnUpperCategoryCheckbox() /*throws InterruptedException*/ {
106                 WebElement categoryCheckbox = getCategoryCheckbox();
107                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on %s category ...", categoryCheckbox.getText()));
108                 categoryCheckbox.click();
109                 GeneralUIUtils.ultimateWait();
110                 return categoryCheckbox;
111         }
112
113         public static WebElement getCategoryCheckbox() {
114                 List<WebElement> categoryCheckboxes = GeneralUIUtils.getElementsByCSS("span[data-tests-id*='category']"); // get all categories and subcategories
115                 return categoryCheckboxes.get(0);
116         }
117
118         public static void clickOnLeftPanelElement(DataTestIdEnum.CatalogPageLeftPanelFilterTitle leftPanelElement) throws InterruptedException {
119                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on %s", leftPanelElement.name()));
120                 GeneralUIUtils.getElementsByCSS(leftPanelElement.getValue()).forEach(WebElement::click);
121         }
122
123         public static WebElement catalogSearchBox(String searchText) {
124                 WebElement searchBox = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtons.SEARCH_BOX.getValue());
125                 searchBox.clear();
126                 searchBox.sendKeys(searchText);
127                 return searchBox;
128         }
129
130 }