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.execute.sanity;
23 import com.aventstack.extentreports.Status;
24 import org.onap.sdc.backend.ci.tests.utils.Utils;
25 import org.onap.sdc.backend.ci.tests.utils.general.ElementFactory;
26 import org.onap.sdc.frontend.ci.tests.verificator.CatalogVerificator;
27 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
28 import org.onap.sdc.frontend.ci.tests.datatypes.CheckBoxStatusEnum;
29 import org.onap.sdc.frontend.ci.tests.datatypes.DataTestIdEnum;
30 import org.onap.sdc.frontend.ci.tests.datatypes.LifeCycleStateEnum;
31 import org.onap.sdc.backend.ci.tests.datatypes.ResourceReqDetails;
32 import org.onap.sdc.backend.ci.tests.datatypes.ServiceReqDetails;
33 import org.onap.sdc.frontend.ci.tests.datatypes.TopMenuButtonsEnum;
34 import org.onap.sdc.frontend.ci.tests.datatypes.TypesEnum;
35 import org.onap.sdc.backend.ci.tests.datatypes.enums.UserRoleEnum;
36 import org.onap.sdc.frontend.ci.tests.execute.setup.SetupCDTest;
37 import org.onap.sdc.frontend.ci.tests.pages.ResourceGeneralPage;
38 import org.onap.sdc.frontend.ci.tests.utilities.CatalogUIUtilitis;
39 import org.onap.sdc.frontend.ci.tests.utilities.FileHandling;
40 import org.onap.sdc.frontend.ci.tests.utilities.GeneralUIUtils;
41 import org.onap.sdc.frontend.ci.tests.utilities.ResourceUIUtils;
42 import org.onap.sdc.frontend.ci.tests.utilities.ServiceUIUtils;
43 import org.openqa.selenium.WebElement;
44 import org.testng.annotations.BeforeMethod;
45 import org.testng.annotations.DataProvider;
46 import org.testng.annotations.Test;
48 import java.util.Arrays;
49 import java.util.List;
51 import static org.testng.AssertJUnit.assertTrue;
53 @Test(singleThreaded = true)
54 public class CatalogLeftPanelTestWithTime extends SetupCDTest {
56 private static final int REGULAR_TEST_RUN_TIME = 400;
57 private String filePath;
60 public void beforeTest() {
61 filePath = FileHandling.getFilePath("");
64 private static String[] resourceTypes = Arrays.stream(ResourceTypeEnum.class.getEnumConstants()).
65 map(ResourceTypeEnum::name).toArray(String[]::new);
67 private static String[] catalogTypes = {"RESOURCE", "SERVICE"};
69 private static Object[][] provideData(String[] arObj) {
70 Object[][] arObject = new Object[arObj.length][];
73 for (Object obj : arObj) {
74 arObject[index++] = new Object[]{obj};
79 @DataProvider(name = "Resource_Type_List")
80 private static Object[][] resourceTypeList() {
81 // Extract names of constants from enum as array of Strings
82 ResourceTypeEnum[] resourceEnums = {ResourceTypeEnum.CP, ResourceTypeEnum.VF, ResourceTypeEnum.VFC, ResourceTypeEnum.VL};
83 String[] resourcesForTest = Arrays.stream(resourceEnums).map(ResourceTypeEnum::name).toArray(String[]::new);
84 return provideData(resourcesForTest);
87 @DataProvider(name = "Type_List")
88 private static Object[][] typeList() {
89 // Extract names of constants from enum as array of Strings
90 Object[][] arObject = new Object[catalogTypes.length][];
92 for (String catalogType : catalogTypes) {
93 if (catalogType.equals("RESOURCE")) {
94 arObject[index++] = new Object[]{catalogType, resourceTypes};
96 arObject[index++] = new Object[]{catalogType, new String[]{catalogType}};
102 @DataProvider(name = "Status_List")
103 private static Object[][] statusList() {
104 CheckBoxStatusEnum[] checkboxes = {CheckBoxStatusEnum.CERTIFIED,
105 CheckBoxStatusEnum.IN_DESIGN,
106 CheckBoxStatusEnum.DISTRIBUTED,
107 CheckBoxStatusEnum.IN_TESTING,
108 CheckBoxStatusEnum.READY_FOR_TESTING};
109 Object[][] arObject = new Object[checkboxes.length][];
111 for (CheckBoxStatusEnum checkbox : checkboxes) {
112 if (checkbox.equals(CheckBoxStatusEnum.CERTIFIED)) {
113 arObject[index++] = new Object[]{checkbox, Arrays.asList(LifeCycleStateEnum.CERTIFIED, LifeCycleStateEnum.DISTRIBUTED, LifeCycleStateEnum.WAITING_FOR_DISTRIBUTION)};
114 } else if (checkbox.equals(CheckBoxStatusEnum.IN_DESIGN)) {
115 arObject[index++] = new Object[]{checkbox, Arrays.asList(LifeCycleStateEnum.CHECKIN, LifeCycleStateEnum.CHECKOUT)};
116 } else if (checkbox.equals(CheckBoxStatusEnum.DISTRIBUTED)) {
117 arObject[index++] = new Object[]{checkbox, Arrays.asList(LifeCycleStateEnum.DISTRIBUTED)};
118 } else if (checkbox.equals(CheckBoxStatusEnum.IN_TESTING)) {
119 arObject[index++] = new Object[]{checkbox, Arrays.asList(LifeCycleStateEnum.IN_TESTING)};
120 } else if (checkbox.equals(CheckBoxStatusEnum.READY_FOR_TESTING)) {
121 arObject[index++] = new Object[]{checkbox, Arrays.asList(LifeCycleStateEnum.READY_FOR_TESTING)};
127 // filter by Type Resource in catalog
128 @Test(dataProvider = "Type_List")
129 public void filterByTypeWithTime(String catalogType, String[] classValues) throws Exception {
132 Long actualTestRunTime = GeneralUIUtils.getAndValidateActionDuration(() ->
133 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG), REGULAR_TEST_RUN_TIME);
134 SetupCDTest.getExtendTest().log(Status.INFO, "Actual catalog loading time is "
135 + actualTestRunTime + " seconds");
137 actualTestRunTime = Utils.getAndValidateActionDuration(() -> {
139 CatalogUIUtilitis.catalogFilterTypeChecBox(TypesEnum.valueOf(catalogType));
140 } catch (Exception e) {
143 }, REGULAR_TEST_RUN_TIME);
144 SetupCDTest.getExtendTest().log(Status.INFO, "Actual catalog filtering time is "
145 + actualTestRunTime + " seconds");
146 //Validate number of elements after filtering
147 CatalogVerificator.validateType(TypesEnum.valueOf(catalogType));
150 @Test(dataProvider = "Resource_Type_List")
151 public void filterByResourceTypeWithTime(String resourceType) throws Exception {
152 setLog(resourceType);
154 Long actualTestRunTime = Utils.getAndValidateActionDuration(() ->
155 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG), REGULAR_TEST_RUN_TIME);
156 SetupCDTest.getExtendTest().log(Status.INFO, "Actual catalog loading time is "
157 + actualTestRunTime + " seconds");
158 //Filter by resource type
159 actualTestRunTime = Utils.getAndValidateActionDuration(() -> {
161 CatalogUIUtilitis.catalogFilterTypeChecBox(TypesEnum.valueOf(resourceType));
162 } catch (Exception e) {
165 }, REGULAR_TEST_RUN_TIME);
166 SetupCDTest.getExtendTest().log(Status.INFO, "Actual catalog filtering time is "
167 + actualTestRunTime + " seconds");
168 //Validate number of elements after filtering
169 CatalogVerificator.validateType(TypesEnum.valueOf(resourceType));
172 @Test(dataProvider = "Status_List")
173 public void filterByStatus(CheckBoxStatusEnum statusCheckbox, List<LifeCycleStateEnum> lifecycleStates) throws Exception {
174 setLog(statusCheckbox.name());
176 Long actualTestRunTime = Utils.getAndValidateActionDuration(() ->
177 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG), REGULAR_TEST_RUN_TIME);
178 SetupCDTest.getExtendTest().log(Status.INFO, "Actual catalog loading time is "
179 + actualTestRunTime + " seconds");
180 CatalogUIUtilitis.clickOnLeftPanelElement(DataTestIdEnum.CatalogPageLeftPanelFilterTitle.CATEGORIES);
181 //Filter by resource type
182 actualTestRunTime = Utils.getAndValidateActionDuration(() -> CatalogUIUtilitis.catalogFilterStatusChecBox(statusCheckbox), REGULAR_TEST_RUN_TIME);
183 SetupCDTest.getExtendTest().log(Status.INFO, "Actual catalog filtering time is "
184 + actualTestRunTime + " seconds");
185 //TODO check the test after removing lifecycle steps for resource
186 //Validate number of elements after filtering
187 CatalogVerificator.validateStatus(lifecycleStates, statusCheckbox.name());
191 public void filterByUpperCategory() throws Exception {
193 Long actualTestRunTime = Utils.getAndValidateActionDuration(() ->
194 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG), REGULAR_TEST_RUN_TIME);
195 SetupCDTest.getExtendTest().log(Status.INFO, "Actual catalog loading time is "
196 + actualTestRunTime + " seconds");
197 //Filter by Upper Category
198 CatalogUIUtilitis.clickOnLeftPanelElement(DataTestIdEnum.CatalogPageLeftPanelFilterTitle.TYPE);
199 actualTestRunTime = Utils.getAndValidateActionDuration(() -> CatalogUIUtilitis.clickOnUpperCategoryCheckbox(), REGULAR_TEST_RUN_TIME);
200 SetupCDTest.getExtendTest().log(Status.INFO, "Actual catalog filtering time is "
201 + actualTestRunTime + " seconds");
202 WebElement categoryCheckbox = CatalogUIUtilitis.getCategoryCheckbox();
203 CatalogVerificator.validateCategory(categoryCheckbox.getAttribute("textContent").trim());
207 public void filterByGenericDatabaseSubCategory() throws Exception {
209 Long actualTestRunTime = Utils.getAndValidateActionDuration(() ->
210 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG), REGULAR_TEST_RUN_TIME);
211 SetupCDTest.getExtendTest().log(Status.INFO, "Actual catalog loading time is "
212 + actualTestRunTime + " seconds");
213 CatalogUIUtilitis.clickOnLeftPanelElement(DataTestIdEnum.CatalogPageLeftPanelFilterTitle.TYPE);
214 WebElement checkboxElement = GeneralUIUtils.getElementsByCSS(DataTestIdEnum.CatalogPageLeftPanelSubCategoryCheckbox.DATABASE.getValue()).get(0);
215 String checkboxElementName = checkboxElement.getAttribute("textContent").trim();
216 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on %s subcategory ...", checkboxElementName));
217 //Filter by sub category
218 actualTestRunTime = Utils.getAndValidateActionDuration(() -> {
220 GeneralUIUtils.clickOnAreaJS(checkboxElement);
221 } catch (Exception e) {
224 }, REGULAR_TEST_RUN_TIME);
225 SetupCDTest.getExtendTest().log(Status.INFO, "Actual catalog filtering time is "
226 + actualTestRunTime + " seconds");
227 //Validate filtering results
228 CatalogVerificator.validateSubCategory("Generic", checkboxElementName);
232 public void lastUpdatedService() throws Exception {
234 ServiceReqDetails serviceMetadata = ElementFactory.getDefaultService();
235 ServiceUIUtils.createService(serviceMetadata);
237 ResourceGeneralPage.clickCheckinButton(serviceMetadata.getName());
238 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
239 List<WebElement> cardElements = GeneralUIUtils.getElementsByCSS(DataTestIdEnum.DashboardCardEnum.INFO_NAME.getValue());
240 String firstElementName = cardElements.get(0).getAttribute("textContent").trim();
241 assertTrue(String.format("Wrong element name, Expected : %s , Actual: %s", serviceMetadata.getName(), firstElementName), serviceMetadata.getName().equals(firstElementName));
245 public void lastUpdatedResource() throws Exception {
247 ResourceReqDetails vfMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
248 ResourceUIUtils.createVF(vfMetaData, getUser());
250 ResourceGeneralPage.clickCheckinButton(vfMetaData.getName());
251 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
252 List<WebElement> cardElements = GeneralUIUtils.getElementsByCSS(DataTestIdEnum.DashboardCardEnum.INFO_NAME.getValue());
253 String firstElementName = cardElements.get(0).getAttribute("textContent").trim();
254 assertTrue(String.format("Wrong element name, Expected : %s , Actual: %s", vfMetaData.getName(), firstElementName), vfMetaData.getName().equals(firstElementName));
258 public void fromCatalogCheckout() throws Exception {
260 ResourceReqDetails vfMetaData = ElementFactory.getDefaultResourceByType(ResourceTypeEnum.VF, getUser());
261 ResourceUIUtils.createVF(vfMetaData, getUser());
262 ResourceGeneralPage.clickCheckinButton(vfMetaData.getName());
263 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
265 GeneralUIUtils.findComponentAndClick(vfMetaData.getName());
266 ResourceGeneralPage.clickCheckoutButton();
267 ResourceGeneralPage.clickCheckinButton(vfMetaData.getName());
271 public void keepSearchResultsInCatalogAfterBrowserBack() throws Exception {
272 ResourceReqDetails resourceMetadata = ElementFactory.getDefaultResource();
273 ResourceUIUtils.createVF(resourceMetadata, getUser());
274 ResourceGeneralPage.clickCheckinButton(resourceMetadata.getName());
275 CatalogUIUtilitis.clickTopMenuButton(TopMenuButtonsEnum.CATALOG);
276 CatalogUIUtilitis.catalogSearchBox(resourceMetadata.getName());
277 GeneralUIUtils.findComponentAndClick(resourceMetadata.getName());
279 GeneralUIUtils.clickOnBrowserBackButton();
281 int numOfElementsInFilteredCatalog = CatalogVerificator.getNumberOfElementsFromCatalogHeader();
282 assertTrue(String.format("Wrong number fo elements, Expected : %s , Actual: %s", 1, numOfElementsInFilteredCatalog), numOfElementsInFilteredCatalog == 1);
284 List<WebElement> cardElements = GeneralUIUtils.getElementsByCSS(DataTestIdEnum.DashboardCardEnum.INFO_NAME.getValue());
285 String firstElementName = cardElements.get(0).getAttribute("textContent").trim();
286 assertTrue(String.format("Wrong element name, Expected : %s , Actual: %s", resourceMetadata.getName(), firstElementName), resourceMetadata.getName().equals(firstElementName));
290 protected UserRoleEnum getRole() {
291 return UserRoleEnum.DESIGNER;