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 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;
35 import java.io.IOException;
36 import java.util.ArrayList;
37 import java.util.Arrays;
38 import java.util.List;
40 public class CatalogUIUtilitis {
43 public static void clickTopMenuButton(TopMenuButtonsEnum button) {
44 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on %s button ...", button.name()));
47 GeneralUIUtils.getWebElementByTestID(button.getButton()).click();
50 GeneralUIUtils.getWebElementByTestID(button.getButton()).click();
53 GeneralUIUtils.getWebElementByTestID(button.getButton()).click();
58 GeneralUIUtils.ultimateWait();
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();
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()));
73 status = Arrays.asList("NOT_CERTIFIED_CHECKIN", "NOT_CERTIFIED_CHECKOUT");
74 GeneralUIUtils.getWebElementByTestID(statusEnum.getValue()).click();
76 case READY_FOR_TESTING:
77 status = Arrays.asList("READY_FOR_CERTIFICATION");
78 GeneralUIUtils.getWebElementByTestID(statusEnum.getValue()).click();
81 status = Arrays.asList("CERTIFICATION_IN_PROGRESS");
82 GeneralUIUtils.getWebElementByTestID(statusEnum.getValue()).click();
86 status = Arrays.asList("CERTIFIED");
87 GeneralUIUtils.getWebElementByTestID(statusEnum.getValue()).click();
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);
102 return allCategoriesList;
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;
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);
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);
123 public static WebElement catalogSearchBox(String searchText) {
124 WebElement searchBox = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.MainMenuButtons.SEARCH_BOX.getValue());
126 searchBox.sendKeys(searchText);