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.utilities;
23 import com.aventstack.extentreports.Status;
24 import java.util.ArrayList;
25 import java.util.List;
26 import org.onap.sdc.backend.ci.tests.datatypes.ServiceReqDetails;
27 import org.onap.sdc.backend.ci.tests.datatypes.enums.ServiceCategoriesEnum;
28 import org.onap.sdc.frontend.ci.tests.datatypes.DataTestIdEnum;
29 import org.onap.sdc.frontend.ci.tests.execute.setup.SetupCDTest;
30 import org.onap.sdc.frontend.ci.tests.pages.GeneralPageElements;
31 import org.onap.sdc.frontend.ci.tests.pages.ServiceGeneralPage;
32 import org.openecomp.sdc.be.model.User;
33 import org.openecomp.sdc.be.model.category.CategoryDefinition;
34 import org.openqa.selenium.By;
35 import org.openqa.selenium.Keys;
36 import org.openqa.selenium.WebElement;
38 public class ServiceUIUtils {
40 private ServiceUIUtils() {
44 private static void defineTagsList2(List<String> serviceTags) {
45 WebElement serviceTagsTextbox = GeneralUIUtils.getWebElementByTestID("i-sdc-tag-input");
46 for (String tag : serviceTags) {
47 serviceTagsTextbox.clear();
48 serviceTagsTextbox.sendKeys(tag);
49 GeneralUIUtils.waitForAngular();
50 serviceTagsTextbox.sendKeys(Keys.ENTER);
54 public static void fillServiceGeneralPage(final ServiceReqDetails service) {
55 SetupCDTest.getExtendTest().log(Status.INFO, "Fill in metadata values in general page");
56 ServiceGeneralPage.defineName(service.getName());
57 ServiceGeneralPage.defineDescription(service.getDescription());
58 ServiceGeneralPage.defineCategory(service.getCategories().get(0).getName());
59 ServiceGeneralPage.defineServiceFunction(service.getServiceFunction());
60 ServiceGeneralPage.defineNamingPolicy(service.getNamingPolicy());
61 defineTagsList2(service.getTags());
62 ServiceGeneralPage.defineContactId(service.getContactId());
63 GeneralUIUtils.waitForElementInVisibilityBy(By.className("notification-container"), 10000);
64 GeneralUIUtils.clickSomewhereOnPage();
67 public static void createService(ServiceReqDetails service) {
69 fillServiceGeneralPage(service);
70 GeneralPageElements.clickCreateButton();
71 SetupCDTest.getExtendTest().log(Status.INFO, String.format("The service %s was created", service.getName()));
74 public static void setServiceCategory(ServiceReqDetails service, ServiceCategoriesEnum category) {
75 CategoryDefinition categoryDefinition = new CategoryDefinition();
76 categoryDefinition.setName(category.getValue());
77 List<CategoryDefinition> categories = new ArrayList<>();
78 categories.add(categoryDefinition);
79 service.setCategories(categories);
82 public static void createServiceWithDefaultTagAndUserId(ServiceReqDetails service, User user) {
84 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Defining General Page fields"));
85 ServiceGeneralPage.defineName(service.getName());
86 ServiceGeneralPage.defineDescription(service.getDescription());
87 ServiceGeneralPage.defineCategory(service.getCategories().get(0).getName());
88 ServiceGeneralPage.defineProjectCode(service.getProjectCode());
89 ServiceGeneralPage.defineInstantiationType(service.getInstantiationType());
90 GeneralUIUtils.ultimateWait();
91 GeneralPageElements.clickCreateButton();
92 SetupCDTest.getExtendTest().log(Status.INFO, "Done creating service over the UI, "
93 + "about to move into Tosca Artifacts section.");
96 public static void clickAddService() {
97 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking the Add Service button"));
99 GeneralUIUtils.hoverOnAreaByTestId(DataTestIdEnum.Dashboard.ADD_AREA.getValue());
100 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.Dashboard.BUTTON_ADD_SERVICE.getValue()).click();
101 //GeneralUIUtils.hoverAndClickOnButtonByTestId(DataTestIdEnum.Dashboard.ADD_AREA.getValue(),DataTestIdEnum.Dashboard.BUTTON_ADD_SERVICE.getValue());
102 GeneralUIUtils.ultimateWait();
103 } catch (Exception e) {
104 SetupCDTest.getExtendTest().log(Status.WARNING, String.format("Exception on catched on Add Service button, retrying ..."));
105 GeneralUIUtils.hoverOnAreaByClassName("w-sdc-dashboard-card-new");
106 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.Dashboard.BUTTON_ADD_SERVICE.getValue()).click();
107 GeneralUIUtils.ultimateWait();