48fb0b8efb298fd457d361c5d8fc73c483eacd79
[sdc.git] / integration-tests / src / test / java / org / onap / sdc / frontend / 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.onap.sdc.frontend.ci.tests.utilities;
22
23 import com.aventstack.extentreports.Status;
24 import org.onap.sdc.backend.ci.tests.datatypes.ServiceReqDetails;
25 import org.onap.sdc.backend.ci.tests.datatypes.enums.ServiceCategoriesEnum;
26 import org.onap.sdc.frontend.ci.tests.pages.GeneralPageElements;
27 import org.onap.sdc.frontend.ci.tests.pages.ServiceGeneralPage;
28 import org.openecomp.sdc.be.model.User;
29 import org.openecomp.sdc.be.model.category.CategoryDefinition;
30 import org.onap.sdc.frontend.ci.tests.datatypes.DataTestIdEnum;
31 import org.onap.sdc.frontend.ci.tests.execute.setup.SetupCDTest;
32 import org.openqa.selenium.Keys;
33 import org.openqa.selenium.WebElement;
34 import org.openqa.selenium.interactions.Actions;
35
36 import java.util.ArrayList;
37 import java.util.List;
38
39 public class ServiceUIUtils {
40
41     private ServiceUIUtils() {
42
43     }
44
45     private static void defineTagsList2(List<String> serviceTags) {
46         WebElement serviceTagsTextbox = GeneralUIUtils.getWebElementByTestID("i-sdc-tag-input");
47         for (String tag : serviceTags) {
48             serviceTagsTextbox.clear();
49             serviceTagsTextbox.sendKeys(tag);
50             GeneralUIUtils.waitForAngular();
51             serviceTagsTextbox.sendKeys(Keys.ENTER);
52         }
53     }
54
55     public static void fillServiceGeneralPage(final ServiceReqDetails service) {
56         SetupCDTest.getExtendTest().log(Status.INFO, "Fill in metadata values in general page");
57         ServiceGeneralPage.defineName(service.getName());
58         ServiceGeneralPage.defineDescription(service.getDescription());
59         ServiceGeneralPage.defineCategory(service.getCategories().get(0).getName());
60         ServiceGeneralPage.defineServiceFunction(service.getServiceFunction());
61         ServiceGeneralPage.defineNamingPolicy(service.getNamingPolicy());
62         defineTagsList2(service.getTags());
63         ServiceGeneralPage.defineContactId(service.getContactId());
64         GeneralUIUtils.clickSomewhereOnPage();
65     }
66
67     public static void createService(ServiceReqDetails service) {
68         clickAddService();
69         fillServiceGeneralPage(service);
70         GeneralPageElements.clickCreateButton();
71         SetupCDTest.getExtendTest().log(Status.INFO, String.format("The service %s was created", service.getName()));
72     }
73
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);
80     }
81
82     public static void createServiceWithDefaultTagAndUserId(ServiceReqDetails service, User user) {
83         clickAddService();
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.");
94     }
95
96     public static void clickAddService() {
97         SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking the Add Service button"));
98         try {
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();
108         }
109     }
110 }