summaryrefslogtreecommitdiffstats
path: root/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/utilities/ServiceUIUtils.java
blob: 8b07e621d9edf87cfcffbeaa1ee72c9d35322346 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
/*-
 * ============LICENSE_START=======================================================
 * SDC
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.openecomp.sdc.ci.tests.utilities;

import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertTrue;

import java.awt.AWTException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.junit.rules.TestName;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum.StepsEnum;
import org.openecomp.sdc.ci.tests.datatypes.ServiceCategoriesNameEnum;
import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails;
import org.openecomp.sdc.ci.tests.datatypes.enums.ServiceCategoriesEnum;
import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
import org.openecomp.sdc.ci.tests.pages.GeneralPageElements;
import org.openecomp.sdc.ci.tests.pages.ServiceGeneralPage;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;

import com.aventstack.extentreports.Status;

public class ServiceUIUtils {

	protected static WebDriver driver;

	public ServiceUIUtils(TestName name, String className) {
		super();
	}

	public static String defineServiceName(String Name) {
		WebElement serviceName = GeneralUIUtils.getWebElementByTestID("name");
		serviceName.clear();
		serviceName.sendKeys(Name);
		return Name;
	}

	public void moveResourceInstanceToCanvasUI() throws Exception {
		List<WebElement> moveResource = driver.findElements(By.className("sprite-resource-icons"));
		WebElement moveResourceToCanvasResourceOne = moveResource.get(0);
		// WebElement moveResource =
		// driver.findElement(By.className("sprite-resource-icons"));
		Actions action = new Actions(driver);
		action.moveToElement(moveResourceToCanvasResourceOne);
		action.clickAndHold(moveResourceToCanvasResourceOne);
		action.moveByOffset(635, 375);
		action.release();
		action.perform();
		WebElement moveResourceToCanvasResourceTwo = moveResource.get(1);
		action.moveToElement(moveResourceToCanvasResourceTwo);
		action.clickAndHold(moveResourceToCanvasResourceTwo);
		action.moveByOffset(535, 375);
		action.release();
		action.perform();
		WebElement moveResourceToCanvasResourceTree = moveResource.get(2);
		action.moveToElement(moveResourceToCanvasResourceTree);
		action.clickAndHold(moveResourceToCanvasResourceTree);
		action.moveByOffset(435, 375);
		action.release();
		action.perform();
		Thread.sleep(2000);
	}

	public static String catalogFilterServiceCategoriesChecBox(ServiceCategoriesNameEnum enumName) throws Exception {
		String Type = null;
		GeneralUIUtils.getWebElementByTestID(enumName.getValue()).click();
		return Type;
	}

	public static List<String> catalogServiceTypeChecBox(ServiceCategoriesNameEnum enumtype) throws Exception {
		List<String> categories = null;
		switch (enumtype) {
		case NETWORK_L13:
			GeneralUIUtils.getWebElementByTestID(enumtype.getValue()).click();
			categories = Arrays.asList("network_l_1-3");
			break;
		case NETWORKL4:
			GeneralUIUtils.getWebElementByTestID(enumtype.getValue()).click();
			categories = Arrays.asList("network_l_4 ");
			break;
		case MOBILITY:
			GeneralUIUtils.getWebElementByTestID(enumtype.getValue()).click();
			categories = Arrays.asList("mobility");
			break;
		case VOIPCALL_CONTROL:
			GeneralUIUtils.getWebElementByTestID(enumtype.getValue()).click();
			categories = Arrays.asList("call_controll ");
			break;
		}
		return categories;
	}

	public static WebElement waitToNextButtonEnabled() {
		return GeneralUIUtils.getWebElementByTestID("Next");
	}

	public static WebElement waitToFinishButtonEnabled() {
		return GeneralUIUtils.getWebElementByTestID("Finish");
	}

	public static WebElement deleteServiceInUI() {

		return GeneralUIUtils.getWebElementByTestID("deleteVersion");
	}

	// get the service view data for validate.
	// created by tedy.
	public static void getServiceGeneralInfo(ServiceReqDetails service, User user) throws InterruptedException {
		Thread.sleep(2000);
		String version = GeneralUIUtils.getSelectList(null, "versionHeader").getFirstSelectedOption().getText()
				.substring(1);
		String name = GeneralUIUtils.getWebElementByTestID("name").getAttribute("value");
		String description = GeneralUIUtils.getWebElementByTestID("description").getAttribute("value");
		String category = GeneralUIUtils.getSelectList(null, "selectGeneralCategory").getFirstSelectedOption()
				.getText();
		List<WebElement> tags = GeneralUIUtils.getWebElementsListByTestID("i-sdc-tag-text");
		String type = GeneralUIUtils.getWebElementsListByTestID("type").get(1).getText();
		int index = type.lastIndexOf(":");
		System.out.println(type.substring(0, index));
		String attContact = GeneralUIUtils.getWebElementByTestID("attContact").getAttribute("value");
		String pmatt = GeneralUIUtils.getWebElementByTestID("pmatt").getAttribute("value");
		System.out.println(service.getVersion());
		assertTrue(service.getVersion().equals(version));
		assertTrue(service.getName().equals(name));
		assertTrue(service.getDescription().equals(description));
		assertTrue(service.getCategories().get(0).getName().equals(category));
		System.out.println(service.getContactId());
		assertTrue(service.getContactId().equals(attContact));
		assertTrue(service.getProjectCode().equals(pmatt));
		for (int i = 0; i < tags.size(); i++) {
			assertEquals(service.getTags().get(i), tags.get(i).getText());
		}

	}

//	public static void defineTagsList(ServiceReqDetails service, String[] serviceTags) {
//		List<String> taglist = new ArrayList<String>();		
//		WebElement serviceTagsTextbox = GeneralUIUtils.getWebElementByTestID("i-sdc-tag-input");
//		for (String tag : serviceTags) {
//			serviceTagsTextbox.clear();
//			serviceTagsTextbox.sendKeys(tag);
//			GeneralUIUtils.sleep(1000);
//			serviceTagsTextbox.sendKeys(Keys.ENTER);
//			taglist.add(tag);
//		}
//		taglist.add(0, service.getName());
//		service.setTags(taglist);
//	}
	
	public static void defineTagsList2(List<String> serviceTags){
		WebElement serviceTagsTextbox = GeneralUIUtils.getWebElementByTestID("i-sdc-tag-input");
		for (String tag : serviceTags) {
			serviceTagsTextbox.clear();
			serviceTagsTextbox.sendKeys(tag);
			GeneralUIUtils.waitForAngular();
			serviceTagsTextbox.sendKeys(Keys.ENTER);
		}
	}

	public static Select defineServiceCategory(String category) {

		return GeneralUIUtils.getSelectList(category, "selectGeneralCategory");
	}

	public static void defineServicePmatt(String pmatt) {
		WebElement attPmattTextbox = GeneralUIUtils.getWebElementByTestID("pmatt");
		attPmattTextbox.clear();
		attPmattTextbox.sendKeys(pmatt);
	}

	public static void selectRandomResourceIcon() throws Exception {
		GeneralUIUtils.moveToStep(StepsEnum.ICON);
		WebDriverWait wait = new WebDriverWait(driver, 6);
		wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[contains(@data-tests-id, 'iconBox')]")));
		List<WebElement> iconElement = driver.findElements(By.xpath("//*[contains(@data-tests-id, 'iconBox')]"));
		iconElement.get(0).click();
	}

	public static String defineDescription(String description) {
		WebElement descriptionTextbox = GeneralUIUtils.getWebElementByTestID("description");
		descriptionTextbox.clear();
		descriptionTextbox.sendKeys(description);
		return description;
	}

	public static void defineContactId(String userId) {
		WebElement attContact = GeneralUIUtils.getWebElementByTestID("attContact");
		attContact.clear();
		attContact.sendKeys(userId);
	}

	public static WebElement clickAddArtifact() {
		SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking Add Artifact button"));
		return GeneralUIUtils.getWebElementByTestID("addArtifactButton");
	}

	public static WebElement getArtifactName() {
		return GeneralUIUtils.getWebElementByTestID("artifactName");
	}

	public static WebElement getArtifactDetails() {
		return GeneralUIUtils.getWebElementByTestID("artifactDisplayName");
	}

	public static void fillServiceGeneralPage(ServiceReqDetails service, User user) throws Exception {
		SetupCDTest.getExtendTest().log(Status.INFO, String.format("Fill in metadata values in general page"));
		ServiceGeneralPage.defineName(service.getName());
		ServiceGeneralPage.defineDescription(service.getDescription());
		ServiceGeneralPage.defineCategory(service.getCategories().get(0).getName());
		ServiceGeneralPage.defineProjectCode(service.getProjectCode());
		defineTagsList2(service.getTags());
		ServiceGeneralPage.defineContactId(service.getContactId());
		GeneralUIUtils.clickSomewhereOnPage();		
	}
    
	public static void createService(ServiceReqDetails service, User user) throws Exception, AWTException {
		clickAddService();
		fillServiceGeneralPage(service, user);
		GeneralPageElements.clickCreateButton();
		SetupCDTest.getExtendTest().log(Status.INFO, String.format("The service %s was created", service.getName()));
	}
	
	public static void setServiceCategory(ServiceReqDetails service, ServiceCategoriesEnum category){
		CategoryDefinition categoryDefinition = new CategoryDefinition();
		categoryDefinition.setName(category.getValue());
		List<CategoryDefinition> categories = new ArrayList<>();
		categories.add(categoryDefinition);
		service.setCategories(categories);
	}
	
	public static void createServiceWithDefaultTagAndUserId(ServiceReqDetails service, User user) {
		clickAddService();
		SetupCDTest.getExtendTest().log(Status.INFO, String.format("Defining General Page fields"));
		ServiceGeneralPage.defineName(service.getName());
		ServiceGeneralPage.defineDescription(service.getDescription());
		ServiceGeneralPage.defineCategory(service.getCategories().get(0).getName());
		ServiceGeneralPage.defineProjectCode(service.getProjectCode());
		GeneralUIUtils.ultimateWait();
		GeneralPageElements.clickCreateButton();
	}
	
	public static void clickAddService(){
		SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking the Add Service button"));
		try {
	    GeneralUIUtils.hoverOnAreaByTestId(DataTestIdEnum.Dashboard.ADD_AREA.getValue());
			GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.Dashboard.BUTTON_ADD_SERVICE.getValue()).click();
		GeneralUIUtils.ultimateWait();
		} catch (Exception e){
			SetupCDTest.getExtendTest().log(Status.WARNING, String.format("Exception on catched on Add Service button, retrying ..."));
			GeneralUIUtils.hoverOnAreaByClassName("w-sdc-dashboard-card-new");			
			GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.Dashboard.BUTTON_ADD_SERVICE.getValue()).click();
			GeneralUIUtils.ultimateWait();
		}
	}

}