[SDC-29] rebase continue work to align source
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / pages / ServiceGeneralPage.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.pages;
22
23 import java.util.ArrayList;
24
25 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
26 import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
27 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
28 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
29 import org.openqa.selenium.By;
30 import org.openqa.selenium.WebElement;
31
32 import com.aventstack.extentreports.Status;
33
34 public class ServiceGeneralPage extends ResourceGeneralPage {
35
36         public ServiceGeneralPage() {
37                 super();
38         }
39         
40         public static ServiceLeftMenu getServiceLeftMenu() {
41         return new ServiceLeftMenu();
42     }
43
44         public static void defineName(String serviceName) {
45                 WebElement serviceNameTextbox = GeneralUIUtils
46                                 .getWebElementByTestID(DataTestIdEnum.ServiceMetadataEnum.SERVICE_NAME.getValue());
47                 serviceNameTextbox.clear();
48                 serviceNameTextbox.sendKeys(serviceName);
49         }
50
51         public static void defineProjectCode(String pmat) {
52                 WebElement projectCodeTextbox = GeneralUIUtils
53                                 .getWebElementByTestID(DataTestIdEnum.ServiceMetadataEnum.PROJECT_CODE.getValue());
54                 projectCodeTextbox.clear();
55                 projectCodeTextbox.sendKeys(pmat);
56         }
57         
58         public static String getProjectCodeText(){
59                 return getProjectCodeField().getAttribute("value");
60         }
61         
62         public static String[] getTags(){
63                 return ResourceGeneralPage.getElementsFromTagsTable().stream().map(WebElement::getText).toArray(String[]::new);
64         }
65         
66         private static WebElement getProjectCodeField() {
67                 return GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.ServiceMetadataEnum.PROJECT_CODE.getValue());
68         }
69         
70         public static void deleteOldTags(ServiceReqDetails service){
71                 // Delete tag elements
72                 int i = GeneralUIUtils.getWebElementsListByTestID("i-sdc-tag-delete").size();
73                 while (i > 0){                  
74                         GeneralUIUtils.getWebElementByTestID("i-sdc-tag-delete").click();
75                         i--;
76                 }
77                 
78                 service.setTags(new ArrayList<String>());
79         }
80         
81         public static String getCategoryText() {
82                 return GeneralUIUtils.getSelectedElementFromDropDown(getCategoryDataTestsIdAttribute()).getText();
83         }
84         
85         public static void clickAddWorkflow (){
86                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Adding workflow..."));
87                 GeneralUIUtils.clickOnElementByText("Add Workflow");
88         }
89         
90         public static void fillAndAddNewWorkflow(String name, String description ) throws InterruptedException{
91                 GeneralUIUtils.ultimateWait();
92                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Filling name field with %s", name));
93                 insertText(name, "label + input");
94                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Filling description filed with %s", name));
95                 insertText(description,"label + textarea");
96                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking save button "));
97                 clickSave();
98         }
99         
100         public static void insertText(String artifactDescriptoin, String element) throws InterruptedException {
101                 GeneralUIUtils.getElementsByCSS("div[class='modal-content']");
102                 WebElement artifactDescriptionTextbox = GeneralUIUtils.getWebElementBy(By.cssSelector(element));
103                 artifactDescriptionTextbox.clear();
104                 artifactDescriptionTextbox.sendKeys(artifactDescriptoin);
105                 GeneralUIUtils.ultimateWait();          
106         }
107         
108         public static void clickSave() {
109                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on Save button"));
110                 GeneralUIUtils.clickOnElementByText("Save");
111                 GeneralUIUtils.ultimateWait();
112         }
113
114 }