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.utilities;
23 import java.io.IOException;
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.List;
28 import org.codehaus.jettison.json.JSONArray;
29 import org.codehaus.jettison.json.JSONException;
30 import org.openecomp.sdc.ci.tests.datatypes.TopMenuButtonsEnum;
31 import org.openecomp.sdc.ci.tests.datatypes.CheckBoxStatusEnum;
32 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
33 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum.CatalogPageLeftPanelFilterTitle;
34 import org.openecomp.sdc.ci.tests.datatypes.TypesEnum;
35 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
36 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
37 import org.openecomp.sdc.ci.tests.utils.rest.CatalogRestUtils;
38 import org.openqa.selenium.WebElement;
39 import org.testng.annotations.Test;
41 import com.aventstack.extentreports.Status;
43 public class CatalogUIUtilitis {
49 // Get all Categories , Subcategories and Icons.
50 public void getAllCategoriesAndSubcategories() throws IOException, JSONException {
51 RestResponse allcategoriesJson = CatalogRestUtils.getAllCategoriesTowardsCatalogBe();
52 JSONArray categories = new JSONArray(allcategoriesJson.getResponse());
53 for (int i = 0; i < categories.length(); i++) {
54 String categoryname = (String) categories.getJSONObject(i).get("name");
55 JSONArray subcategories = (JSONArray) categories.getJSONObject(i).get("subcategories");
56 for (int j = 0; j < subcategories.length(); j++) {
57 String subcategoryname = (String) subcategories.getJSONObject(j).get("name");
58 System.out.println(subcategoryname);
60 for (int j = 0; j < subcategories.length(); j++) {
61 JSONArray icons = (JSONArray) subcategories.getJSONObject(j).get("icons");
62 for (int k = 0; k < icons.length(); k++) {
63 System.out.println(icons.get(k));
66 System.out.println("-------------------------------");
71 // FOr testing---delete.
72 public static List<String> abcd() throws IOException, JSONException {
73 RestResponse allcategoriesJson = CatalogRestUtils.getAllCategoriesTowardsCatalogBe();
74 JSONArray categories = new JSONArray(allcategoriesJson.getResponse());
75 List<String> allcat = new ArrayList<>();
76 String uniqueId = null;
77 for (int i = 0; i < categories.length(); i++) {
78 String categoryname = (String) categories.getJSONObject(i).get("name");
79 uniqueId = (String) categories.getJSONObject(i).get("uniqueId");
81 JSONArray subcategories = (JSONArray) categories.getJSONObject(i).get("subcategories");
82 for (int j = 0; j < subcategories.length(); j++) {
83 String subcategoryname = (String) subcategories.getJSONObject(j).get("name");
84 uniqueId = (String) subcategories.getJSONObject(j).get("uniqueId");
92 public static void clickTopMenuButton(TopMenuButtonsEnum button) {
93 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on %s button ...", button.name()));
96 GeneralUIUtils.getWebElementByTestID(button.getButton()).click();
99 GeneralUIUtils.getWebElementByTestID(button.getButton()).click();
102 GeneralUIUtils.getWebElementByTestID(button.getButton()).click();
107 GeneralUIUtils.ultimateWait();
110 public static String catalogFilterTypeChecBox(TypesEnum enumtype) throws Exception {
111 String Type = enumtype.toString().toLowerCase();
112 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on %s ...", Type));
113 GeneralUIUtils.getWebElementByTestID(enumtype.getValue()).click();
117 public static List<String> catalogFilterStatusChecBox(CheckBoxStatusEnum statusEnum) throws Exception {
118 List<String> status = null;
119 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on %s status", statusEnum.name()));
120 switch (statusEnum) {
122 status = Arrays.asList("NOT_CERTIFIED_CHECKIN", "NOT_CERTIFIED_CHECKOUT");
123 GeneralUIUtils.getWebElementByTestID(statusEnum.getCatalogValue()).click();
125 case READY_FOR_TESTING:
126 status = Arrays.asList("READY_FOR_CERTIFICATION");
127 GeneralUIUtils.getWebElementByTestID(statusEnum.getCatalogValue()).click();
130 status = Arrays.asList("CERTIFICATION_IN_PROGRESS");
131 GeneralUIUtils.getWebElementByTestID(statusEnum.getCatalogValue()).click();
134 status = Arrays.asList("CERTIFIED");
135 GeneralUIUtils.getWebElementByTestID(statusEnum.getCatalogValue()).click();
138 status = Arrays.asList("CERTIFIED");
139 GeneralUIUtils.getWebElementByTestID(statusEnum.getCatalogValue()).click();
145 // Get all Categories uniqueID .//The parent categories.
146 public static List<String> getCategories() throws IOException, JSONException {
147 List<String> allCategoriesList = new ArrayList<>();
148 RestResponse allcategoriesJson = CatalogRestUtils.getAllCategoriesTowardsCatalogBe();
149 JSONArray categories = new JSONArray(allcategoriesJson.getResponse());
150 for (int i = 0; i < categories.length(); i++) {
151 String categoryname = (String) categories.getJSONObject(i).get("name");
152 System.out.println(categoryname);
153 allCategoriesList.add(categoryname);
155 return allCategoriesList;
159 // Get Subcategories by Category name
160 public static List<String> getAllSubcategoriesByUniqueId(String uniqueId) throws IOException, JSONException {
162 RestResponse allcategoriesJson = CatalogRestUtils.getAllCategoriesTowardsCatalogBe();
163 JSONArray categories = new JSONArray(allcategoriesJson.getResponse());
164 List<String> subCategories = new ArrayList<>();// subCategories to
166 JSONArray subcategories = null;
168 for (int i = 0; i < categories.length(); i++) {
170 String categoryuniqueId = (String) categories.getJSONObject(i).get("uniqueId");
172 if (categoryuniqueId.contentEquals(uniqueId)) {
173 subcategories = (JSONArray) categories.getJSONObject(i).get("subcategories");
175 for (int j = 0; j < subcategories.length(); j++) {
177 subCategories.add((String) subcategories.getJSONObject(j).get("uniqueId"));
183 if (subcategories == null) {
184 subCategories.add(uniqueId);
186 return subCategories;
190 // Get icons by category name
191 public void getSubCategoryIcons() throws IOException, JSONException {
192 RestResponse allcategoriesJson = CatalogRestUtils.getAllCategoriesTowardsCatalogBe();
194 JSONArray categories = new JSONArray(allcategoriesJson.getResponse());
195 for (int i = 0; i < categories.length(); i++) {
196 String subcategoryname = (String) categories.getJSONObject(i).get("name");
197 if (subcategoryname.contentEquals("Generic")) {
198 JSONArray subcategories = (JSONArray) categories.getJSONObject(i).get("subcategories");
199 for (int j = 0; j < subcategories.length(); j++) {
200 JSONArray icons = (JSONArray) subcategories.getJSONObject(j).get("icons");
201 for (int k = 0; k < icons.length(); k++) {
202 System.out.println(icons.get(k));
211 public static WebElement clickOnUpperCategoryCheckbox() throws InterruptedException {
212 List<WebElement> categorieCheckboxes = GeneralUIUtils.getElementsByCSS("span[data-tests-id*='category']"); // get all categories and subcategories
213 WebElement categorieCheckbox = categorieCheckboxes.get(0);
214 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on %s category ...", categorieCheckbox.getText()));
215 categorieCheckbox.click();
216 GeneralUIUtils.ultimateWait();
217 return categorieCheckbox;
220 public static void clickOnLeftPanelElement(DataTestIdEnum.CatalogPageLeftPanelFilterTitle leftPanelElement) throws InterruptedException {
221 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on %s", leftPanelElement.name()));
222 GeneralUIUtils.getElementsByCSS(leftPanelElement.getValue()).forEach(WebElement::click);
225 public static WebElement catalogSearchBox(String searchText) {
226 WebElement searchBox = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtons.SEARCH_BOX.getValue());
228 searchBox.sendKeys(searchText);