[SDC-29] rebase continue work to align source
[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 static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertTrue;
25
26 import java.awt.AWTException;
27 import java.util.ArrayList;
28 import java.util.Arrays;
29 import java.util.List;
30
31 import org.junit.rules.TestName;
32 import org.openecomp.sdc.be.model.User;
33 import org.openecomp.sdc.be.model.category.CategoryDefinition;
34 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
35 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum.StepsEnum;
36 import org.openecomp.sdc.ci.tests.datatypes.ServiceCategoriesNameEnum;
37 import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
38 import org.openecomp.sdc.ci.tests.datatypes.enums.ServiceCategoriesEnum;
39 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
40 import org.openecomp.sdc.ci.tests.pages.GeneralPageElements;
41 import org.openecomp.sdc.ci.tests.pages.ServiceGeneralPage;
42 import org.openqa.selenium.By;
43 import org.openqa.selenium.Keys;
44 import org.openqa.selenium.WebDriver;
45 import org.openqa.selenium.WebElement;
46 import org.openqa.selenium.interactions.Actions;
47 import org.openqa.selenium.support.ui.ExpectedConditions;
48 import org.openqa.selenium.support.ui.Select;
49 import org.openqa.selenium.support.ui.WebDriverWait;
50
51 import com.aventstack.extentreports.Status;
52
53 public class ServiceUIUtils {
54
55         protected static WebDriver driver;
56
57         public ServiceUIUtils(TestName name, String className) {
58                 super();
59         }
60
61         public static String defineServiceName(String Name) {
62                 WebElement serviceName = GeneralUIUtils.getWebElementByTestID("name");
63                 serviceName.clear();
64                 serviceName.sendKeys(Name);
65                 return Name;
66         }
67
68         public void moveResourceInstanceToCanvasUI() throws Exception {
69                 List<WebElement> moveResource = driver.findElements(By.className("sprite-resource-icons"));
70                 WebElement moveResourceToCanvasResourceOne = moveResource.get(0);
71                 // WebElement moveResource =
72                 // driver.findElement(By.className("sprite-resource-icons"));
73                 Actions action = new Actions(driver);
74                 action.moveToElement(moveResourceToCanvasResourceOne);
75                 action.clickAndHold(moveResourceToCanvasResourceOne);
76                 action.moveByOffset(635, 375);
77                 action.release();
78                 action.perform();
79                 WebElement moveResourceToCanvasResourceTwo = moveResource.get(1);
80                 action.moveToElement(moveResourceToCanvasResourceTwo);
81                 action.clickAndHold(moveResourceToCanvasResourceTwo);
82                 action.moveByOffset(535, 375);
83                 action.release();
84                 action.perform();
85                 WebElement moveResourceToCanvasResourceTree = moveResource.get(2);
86                 action.moveToElement(moveResourceToCanvasResourceTree);
87                 action.clickAndHold(moveResourceToCanvasResourceTree);
88                 action.moveByOffset(435, 375);
89                 action.release();
90                 action.perform();
91                 Thread.sleep(2000);
92         }
93
94         public static String catalogFilterServiceCategoriesChecBox(ServiceCategoriesNameEnum enumName) throws Exception {
95                 String Type = null;
96                 GeneralUIUtils.getWebElementByTestID(enumName.getValue()).click();
97                 return Type;
98         }
99
100         public static List<String> catalogServiceTypeChecBox(ServiceCategoriesNameEnum enumtype) throws Exception {
101                 List<String> categories = null;
102                 switch (enumtype) {
103                 case NETWORK_L13:
104                         GeneralUIUtils.getWebElementByTestID(enumtype.getValue()).click();
105                         categories = Arrays.asList("network_l_1-3");
106                         break;
107                 case NETWORKL4:
108                         GeneralUIUtils.getWebElementByTestID(enumtype.getValue()).click();
109                         categories = Arrays.asList("network_l_4 ");
110                         break;
111                 case MOBILITY:
112                         GeneralUIUtils.getWebElementByTestID(enumtype.getValue()).click();
113                         categories = Arrays.asList("mobility");
114                         break;
115                 case VOIPCALL_CONTROL:
116                         GeneralUIUtils.getWebElementByTestID(enumtype.getValue()).click();
117                         categories = Arrays.asList("call_controll ");
118                         break;
119                 }
120                 return categories;
121         }
122
123         public static WebElement waitToNextButtonEnabled() {
124                 return GeneralUIUtils.getWebElementByTestID("Next");
125         }
126
127         public static WebElement waitToFinishButtonEnabled() {
128                 return GeneralUIUtils.getWebElementByTestID("Finish");
129         }
130
131         public static WebElement deleteServiceInUI() {
132
133                 return GeneralUIUtils.getWebElementByTestID("deleteVersion");
134         }
135
136         // get the service view data for validate.
137         // created by tedy.
138         public static void getServiceGeneralInfo(ServiceReqDetails service, User user) throws InterruptedException {
139                 Thread.sleep(2000);
140                 String version = GeneralUIUtils.getSelectList(null, "versionHeader").getFirstSelectedOption().getText()
141                                 .substring(1);
142                 String name = GeneralUIUtils.getWebElementByTestID("name").getAttribute("value");
143                 String description = GeneralUIUtils.getWebElementByTestID("description").getAttribute("value");
144                 String category = GeneralUIUtils.getSelectList(null, "selectGeneralCategory").getFirstSelectedOption()
145                                 .getText();
146                 List<WebElement> tags = GeneralUIUtils.getWebElementsListByTestID("i-sdc-tag-text");
147                 String type = GeneralUIUtils.getWebElementsListByTestID("type").get(1).getText();
148                 int index = type.lastIndexOf(":");
149                 System.out.println(type.substring(0, index));
150                 String attContact = GeneralUIUtils.getWebElementByTestID("attContact").getAttribute("value");
151                 String pmatt = GeneralUIUtils.getWebElementByTestID("pmatt").getAttribute("value");
152                 System.out.println(service.getVersion());
153                 assertTrue(service.getVersion().equals(version));
154                 assertTrue(service.getName().equals(name));
155                 assertTrue(service.getDescription().equals(description));
156                 assertTrue(service.getCategories().get(0).getName().equals(category));
157                 System.out.println(service.getContactId());
158                 assertTrue(service.getContactId().equals(attContact));
159                 assertTrue(service.getProjectCode().equals(pmatt));
160                 for (int i = 0; i < tags.size(); i++) {
161                         assertEquals(service.getTags().get(i), tags.get(i).getText());
162                 }
163
164         }
165
166 //      public static void defineTagsList(ServiceReqDetails service, String[] serviceTags) {
167 //              List<String> taglist = new ArrayList<String>();         
168 //              WebElement serviceTagsTextbox = GeneralUIUtils.getWebElementByTestID("i-sdc-tag-input");
169 //              for (String tag : serviceTags) {
170 //                      serviceTagsTextbox.clear();
171 //                      serviceTagsTextbox.sendKeys(tag);
172 //                      GeneralUIUtils.sleep(1000);
173 //                      serviceTagsTextbox.sendKeys(Keys.ENTER);
174 //                      taglist.add(tag);
175 //              }
176 //              taglist.add(0, service.getName());
177 //              service.setTags(taglist);
178 //      }
179         
180         public static void defineTagsList2(List<String> serviceTags){
181                 WebElement serviceTagsTextbox = GeneralUIUtils.getWebElementByTestID("i-sdc-tag-input");
182                 for (String tag : serviceTags) {
183                         serviceTagsTextbox.clear();
184                         serviceTagsTextbox.sendKeys(tag);
185                         GeneralUIUtils.waitForAngular();
186                         serviceTagsTextbox.sendKeys(Keys.ENTER);
187                 }
188         }
189
190         public static Select defineServiceCategory(String category) {
191
192                 return GeneralUIUtils.getSelectList(category, "selectGeneralCategory");
193         }
194
195         public static void defineServicePmatt(String pmatt) {
196                 WebElement attPmattTextbox = GeneralUIUtils.getWebElementByTestID("pmatt");
197                 attPmattTextbox.clear();
198                 attPmattTextbox.sendKeys(pmatt);
199         }
200
201         public static void selectRandomResourceIcon() throws Exception {
202                 GeneralUIUtils.moveToStep(StepsEnum.ICON);
203                 WebDriverWait wait = new WebDriverWait(driver, 6);
204                 wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[contains(@data-tests-id, 'iconBox')]")));
205                 List<WebElement> iconElement = driver.findElements(By.xpath("//*[contains(@data-tests-id, 'iconBox')]"));
206                 iconElement.get(0).click();
207         }
208
209         public static String defineDescription(String description) {
210                 WebElement descriptionTextbox = GeneralUIUtils.getWebElementByTestID("description");
211                 descriptionTextbox.clear();
212                 descriptionTextbox.sendKeys(description);
213                 return description;
214         }
215
216         public static void defineContactId(String userId) {
217                 WebElement attContact = GeneralUIUtils.getWebElementByTestID("attContact");
218                 attContact.clear();
219                 attContact.sendKeys(userId);
220         }
221
222         public static WebElement clickAddArtifact() {
223                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking Add Artifact button"));
224                 return GeneralUIUtils.getWebElementByTestID("addArtifactButton");
225         }
226
227         public static WebElement getArtifactName() {
228                 return GeneralUIUtils.getWebElementByTestID("artifactName");
229         }
230
231         public static WebElement getArtifactDetails() {
232                 return GeneralUIUtils.getWebElementByTestID("artifactDisplayName");
233         }
234
235         public static void fillServiceGeneralPage(ServiceReqDetails service, User user) throws Exception {
236                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Fill in metadata values in general page"));
237                 ServiceGeneralPage.defineName(service.getName());
238                 ServiceGeneralPage.defineDescription(service.getDescription());
239                 ServiceGeneralPage.defineCategory(service.getCategories().get(0).getName());
240                 ServiceGeneralPage.defineProjectCode(service.getProjectCode());
241                 defineTagsList2(service.getTags());
242                 ServiceGeneralPage.defineContactId(service.getContactId());
243                 GeneralUIUtils.clickSomewhereOnPage();          
244         }
245     
246         public static void createService(ServiceReqDetails service, User user) throws Exception, AWTException {
247                 clickAddService();
248                 fillServiceGeneralPage(service, user);
249                 GeneralPageElements.clickCreateButton();
250                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("The service %s was created", service.getName()));
251         }
252         
253         public static void setServiceCategory(ServiceReqDetails service, ServiceCategoriesEnum category){
254                 CategoryDefinition categoryDefinition = new CategoryDefinition();
255                 categoryDefinition.setName(category.getValue());
256                 List<CategoryDefinition> categories = new ArrayList<>();
257                 categories.add(categoryDefinition);
258                 service.setCategories(categories);
259         }
260         
261         public static void createServiceWithDefaultTagAndUserId(ServiceReqDetails service, User user) {
262                 clickAddService();
263                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Defining General Page fields"));
264                 ServiceGeneralPage.defineName(service.getName());
265                 ServiceGeneralPage.defineDescription(service.getDescription());
266                 ServiceGeneralPage.defineCategory(service.getCategories().get(0).getName());
267                 ServiceGeneralPage.defineProjectCode(service.getProjectCode());
268                 GeneralUIUtils.ultimateWait();
269                 GeneralPageElements.clickCreateButton();
270         }
271         
272         public static void clickAddService(){
273                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking the Add Service button"));
274                 try {
275             GeneralUIUtils.hoverOnAreaByTestId(DataTestIdEnum.Dashboard.ADD_AREA.getValue());
276                         GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.Dashboard.BUTTON_ADD_SERVICE.getValue()).click();
277                 GeneralUIUtils.ultimateWait();
278                 } catch (Exception e){
279                         SetupCDTest.getExtendTest().log(Status.WARNING, String.format("Exception on catched on Add Service button, retrying ..."));
280                         GeneralUIUtils.hoverOnAreaByClassName("w-sdc-dashboard-card-new");                      
281                         GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.Dashboard.BUTTON_ADD_SERVICE.getValue()).click();
282                         GeneralUIUtils.ultimateWait();
283                 }
284         }
285
286 }