Catalog alignment
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / utilities / ServiceUIUtils.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.openecomp.sdc.be.model.User;
25 import org.openecomp.sdc.be.model.category.CategoryDefinition;
26 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
27 import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
28 import org.openecomp.sdc.ci.tests.datatypes.enums.ServiceCategoriesEnum;
29 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
30 import org.openecomp.sdc.ci.tests.pages.GeneralPageElements;
31 import org.openecomp.sdc.ci.tests.pages.ServiceGeneralPage;
32 import org.openqa.selenium.Keys;
33 import org.openqa.selenium.WebElement;
34
35 import java.util.ArrayList;
36 import java.util.List;
37
38 public class ServiceUIUtils {
39
40     private ServiceUIUtils() {
41
42     }
43
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);
51         }
52     }
53
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.clickSomewhereOnPage();
64     }
65
66     public static void createService(ServiceReqDetails service) {
67         clickAddService();
68         fillServiceGeneralPage(service);
69         GeneralPageElements.clickCreateButton();
70         SetupCDTest.getExtendTest().log(Status.INFO, String.format("The service %s was created", service.getName()));
71     }
72
73     public static void setServiceCategory(ServiceReqDetails service, ServiceCategoriesEnum category) {
74         CategoryDefinition categoryDefinition = new CategoryDefinition();
75         categoryDefinition.setName(category.getValue());
76         List<CategoryDefinition> categories = new ArrayList<>();
77         categories.add(categoryDefinition);
78         service.setCategories(categories);
79     }
80
81     public static void createServiceWithDefaultTagAndUserId(ServiceReqDetails service, User user) {
82         clickAddService();
83         SetupCDTest.getExtendTest().log(Status.INFO, String.format("Defining General Page fields"));
84         ServiceGeneralPage.defineName(service.getName());
85         ServiceGeneralPage.defineDescription(service.getDescription());
86         ServiceGeneralPage.defineCategory(service.getCategories().get(0).getName());
87         ServiceGeneralPage.defineProjectCode(service.getProjectCode());
88         ServiceGeneralPage.defineInstantiationType(service.getInstantiationType());
89         GeneralUIUtils.ultimateWait();
90         GeneralPageElements.clickCreateButton();
91         SetupCDTest.getExtendTest().log(Status.INFO, "Done creating service over the UI, "
92                 + "about to move into Tosca Artifacts section.");
93     }
94
95     public static void clickAddService() {
96         SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking the Add Service button"));
97         try {
98             GeneralUIUtils.hoverOnAreaByTestId(DataTestIdEnum.Dashboard.ADD_AREA.getValue());
99             GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.Dashboard.BUTTON_ADD_SERVICE.getValue()).click();
100             GeneralUIUtils.ultimateWait();
101         } catch (Exception e) {
102             SetupCDTest.getExtendTest().log(Status.WARNING, String.format("Exception on catched on Add Service button, retrying ..."));
103             GeneralUIUtils.hoverOnAreaByClassName("w-sdc-dashboard-card-new");
104             GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.Dashboard.BUTTON_ADD_SERVICE.getValue()).click();
105             GeneralUIUtils.ultimateWait();
106         }
107     }
108
109 }