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.openecomp.sdc.ci.tests.utilities;
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertTrue;
26 import java.awt.AWTException;
27 import java.util.ArrayList;
28 import java.util.Arrays;
29 import java.util.List;
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;
51 import com.aventstack.extentreports.Status;
53 public class ServiceUIUtils {
55 protected static WebDriver driver;
57 public ServiceUIUtils(TestName name, String className) {
61 public static String defineServiceName(String Name) {
62 WebElement serviceName = GeneralUIUtils.getWebElementByTestID("name");
64 serviceName.sendKeys(Name);
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);
79 WebElement moveResourceToCanvasResourceTwo = moveResource.get(1);
80 action.moveToElement(moveResourceToCanvasResourceTwo);
81 action.clickAndHold(moveResourceToCanvasResourceTwo);
82 action.moveByOffset(535, 375);
85 WebElement moveResourceToCanvasResourceTree = moveResource.get(2);
86 action.moveToElement(moveResourceToCanvasResourceTree);
87 action.clickAndHold(moveResourceToCanvasResourceTree);
88 action.moveByOffset(435, 375);
94 public static String catalogFilterServiceCategoriesChecBox(ServiceCategoriesNameEnum enumName) throws Exception {
96 GeneralUIUtils.getWebElementByTestID(enumName.getValue()).click();
100 public static List<String> catalogServiceTypeChecBox(ServiceCategoriesNameEnum enumtype) throws Exception {
101 List<String> categories = null;
104 GeneralUIUtils.getWebElementByTestID(enumtype.getValue()).click();
105 categories = Arrays.asList("network_l_1-3");
108 GeneralUIUtils.getWebElementByTestID(enumtype.getValue()).click();
109 categories = Arrays.asList("network_l_4 ");
112 GeneralUIUtils.getWebElementByTestID(enumtype.getValue()).click();
113 categories = Arrays.asList("mobility");
115 case VOIPCALL_CONTROL:
116 GeneralUIUtils.getWebElementByTestID(enumtype.getValue()).click();
117 categories = Arrays.asList("call_controll ");
123 public static WebElement waitToNextButtonEnabled() {
124 return GeneralUIUtils.getWebElementByTestID("Next");
127 public static WebElement waitToFinishButtonEnabled() {
128 return GeneralUIUtils.getWebElementByTestID("Finish");
131 public static WebElement deleteServiceInUI() {
133 return GeneralUIUtils.getWebElementByTestID("deleteVersion");
136 // get the service view data for validate.
138 public static void getServiceGeneralInfo(ServiceReqDetails service, User user) throws InterruptedException {
140 String version = GeneralUIUtils.getSelectList(null, "versionHeader").getFirstSelectedOption().getText()
142 String name = GeneralUIUtils.getWebElementByTestID("name").getAttribute("value");
143 String description = GeneralUIUtils.getWebElementByTestID("description").getAttribute("value");
144 String category = GeneralUIUtils.getSelectList(null, "selectGeneralCategory").getFirstSelectedOption()
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());
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);
176 // taglist.add(0, service.getName());
177 // service.setTags(taglist);
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);
190 public static Select defineServiceCategory(String category) {
192 return GeneralUIUtils.getSelectList(category, "selectGeneralCategory");
195 public static void defineServicePmatt(String pmatt) {
196 WebElement attPmattTextbox = GeneralUIUtils.getWebElementByTestID("pmatt");
197 attPmattTextbox.clear();
198 attPmattTextbox.sendKeys(pmatt);
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();
209 public static String defineDescription(String description) {
210 WebElement descriptionTextbox = GeneralUIUtils.getWebElementByTestID("description");
211 descriptionTextbox.clear();
212 descriptionTextbox.sendKeys(description);
216 public static void defineContactId(String userId) {
217 WebElement attContact = GeneralUIUtils.getWebElementByTestID("attContact");
219 attContact.sendKeys(userId);
222 public static WebElement clickAddArtifact() {
223 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking Add Artifact button"));
224 return GeneralUIUtils.getWebElementByTestID("addArtifactButton");
227 public static WebElement getArtifactName() {
228 return GeneralUIUtils.getWebElementByTestID("artifactName");
231 public static WebElement getArtifactDetails() {
232 return GeneralUIUtils.getWebElementByTestID("artifactDisplayName");
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();
246 public static void createService(ServiceReqDetails service, User user) throws Exception, AWTException {
248 fillServiceGeneralPage(service, user);
249 GeneralPageElements.clickCreateButton();
250 SetupCDTest.getExtendTest().log(Status.INFO, String.format("The service %s was created", service.getName()));
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);
261 public static void createServiceWithDefaultTagAndUserId(ServiceReqDetails service, User user) {
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();
272 public static void clickAddService(){
273 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking the Add Service button"));
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();