summaryrefslogtreecommitdiffstats
path: root/ui-ci/src/main/java/org/openecomp/sdc/ci/tests/utilities/ResourceUIUtils.java
blob: 9b374c10b84ffb3bbc27c12daa12f429621c565e (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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
/*-
 * ============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.assertNotNull;
import static org.testng.AssertJUnit.assertTrue;

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.util.Arrays;
import java.util.List;
import java.util.Random;

import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.http.HttpStatus;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.ci.tests.datatypes.CheckBoxStatusEnum;
import org.openecomp.sdc.ci.tests.datatypes.CreateAndImportButtonsEnum;
import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum.Dashboard;
import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum.StepsEnum;
import org.openecomp.sdc.ci.tests.datatypes.ResourceCategoriesNameEnum;
import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
import org.openecomp.sdc.ci.tests.pages.ResourceGeneralPage;
import org.openqa.selenium.By;
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 org.testng.AssertJUnit;

public final class ResourceUIUtils {
	public static final String RESOURCE_NAME_PREFIX = "ResourceCDTest-";
	protected static final boolean IS_BEFORE_TEST = true;
	public static final String INITIAL_VERSION = "0.1";
	public static final String ICON_RESOURCE_NAME = "call_controll";
	protected static final String UPDATED_RESOURCE_ICON_NAME = "objectStorage";

	private ResourceUIUtils() {
	}

	static WebDriver driver = GeneralUIUtils.getDriver();

	public static void defineResourceName(String resourceName) {

		WebElement resourceNameTextbox = GeneralUIUtils.getDriver().findElement(By.name("componentName"));
		resourceNameTextbox.clear();
		resourceNameTextbox.sendKeys(resourceName);
	}

	public static void defineResourceCategory(String category, String datatestsid) {

		GeneralUIUtils.getSelectList(category, datatestsid);
	}
	
	public static void importFileWithSendKey(String FilePath, String FileName, CreateAndImportButtonsEnum type)
			throws Exception {
		WebElement importButton = GeneralUIUtils.createAndImportButtons(type, driver).findElement(By.tagName("input"));
		importButton.sendKeys(FilePath + FileName);
	}

	public static void importFileWithSendKeyBrowse(String FilePath, String FileName) throws Exception {
		WebElement browsebutton = GeneralUIUtils.waitForBrowseButton("browseButton");
		browsebutton.sendKeys(FilePath + FileName);
	}

	public static String defineUserId(String userId) {
		WebElement resourceUserIdTextbox = GeneralUIUtils.getWebElementWaitForVisible("contactId");
		resourceUserIdTextbox.clear();
		resourceUserIdTextbox.sendKeys(userId);
		return userId;
	}

	public static void defineVendorRelease(String resourceVendorRelease) {

		WebElement resourceVendorReleaseTextbox = GeneralUIUtils.getWebElementWaitForVisible("vendorRelease");
		resourceVendorReleaseTextbox.clear();
		resourceVendorReleaseTextbox.sendKeys(resourceVendorRelease);
	}

	public static void selectResourceIcon(String resourceIcon) throws Exception {
		WebDriverWait wait = new WebDriverWait(GeneralUIUtils.getDriver(), 10);
		wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@data-tests-id='" + resourceIcon + "']")))
				.click();
	}

	public static String definePropertyName(String name) {

		WebElement nameProperty = GeneralUIUtils.getDriver().findElement(By.name("propertyName"));
		nameProperty.sendKeys(name);
		return name;
	}

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

	public static List<WebElement> getAllObjectsOnWorkspace(WebDriver driver, ResourceReqDetails resource)
			throws Exception {

		WebDriverWait wait = new WebDriverWait(GeneralUIUtils.getDriver(), 10);
		wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@*='" + resource.getName() + "']")));
		return GeneralUIUtils.getDriver()
				.findElements(By.xpath("//div[@class='" + "w-sdc-dashboard-card-info-name" + "']"));

	}

	public static String getErrorMessageText(String text) throws Exception {

		return GeneralUIUtils.getEelementBycontainsClassName(text).getText();

	}

	public static WebElement scrollElement(WebDriver driver) throws Exception {

		return GeneralUIUtils.getDriver().findElement(By.className("ps-scrollbar-y"));
	}

	public static void scrollDownPage() throws AWTException, InterruptedException {
		Robot robot = new Robot();
		robot.keyPress(KeyEvent.VK_PAGE_DOWN);
		robot.keyRelease(KeyEvent.VK_PAGE_DOWN);
		robot.keyPress(KeyEvent.VK_PAGE_DOWN);
		robot.keyRelease(KeyEvent.VK_PAGE_DOWN);
		robot.keyPress(KeyEvent.VK_PAGE_DOWN);
		robot.keyRelease(KeyEvent.VK_PAGE_DOWN);
		robot.keyPress(KeyEvent.VK_PAGE_DOWN);
		robot.keyRelease(KeyEvent.VK_PAGE_DOWN);
		robot.keyPress(KeyEvent.VK_PAGE_DOWN);
		robot.keyRelease(KeyEvent.VK_PAGE_DOWN);
		robot.keyPress(KeyEvent.VK_PAGE_DOWN);
		robot.keyRelease(KeyEvent.VK_PAGE_DOWN);
		robot.keyPress(KeyEvent.VK_PAGE_DOWN);
		robot.keyRelease(KeyEvent.VK_PAGE_DOWN);
	}

	public static void defineNewSelectList(String Text) {
		WebElement mySelectElm = GeneralUIUtils.getDriver().findElement(By.className("i-sdc-form-select"));
		Select mySelectString = new Select(mySelectElm);
		mySelectString.selectByVisibleText(Text);
	}

	public static void defineDefaultValueByType(String Value) {

		WebElement valueString = GeneralUIUtils.getDriver().findElement(By.name("value"));
		valueString.clear();
		valueString.sendKeys(Value);
	}

	public static void defineBoolenDefaultValue(String Value) {

		WebElement elementBoolean = GeneralUIUtils.getDriver().findElement(By.name("value"));
		Select se = new Select(elementBoolean);
		se.selectByValue(Value);
	}

	public static void clickButtonBlue() {
		WebElement clickButtonBlue = GeneralUIUtils.getDriver().findElement(By.className("w-sdc-btn-blue"));
		clickButtonBlue.click();
	}

	public static void clickButton(String selectButton) {

		WebElement clickButton = GeneralUIUtils.getDriver()
				.findElement(By.xpath("//*[@data-tests-id='" + selectButton + "']"));
		clickButton.click();
	}

	public static WebElement Waitfunctionforbuttons(String element, int timeout) {
		WebDriverWait wait = new WebDriverWait(GeneralUIUtils.getDriver(), timeout);
		return wait.until(ExpectedConditions.elementToBeClickable(By.xpath(element)));
	}

	public static WebElement waitToButtonSubmitForTesting() {
		return Waitfunctionforbuttons("//*[@data-tests-id='submitForTesting']", 10);
	}

	public static WebElement waitToFinishButtonEnabled() {
		return Waitfunctionforbuttons("//button[@data-tests-id='Finish']", 10);
	}

	public static WebElement waitToNextButtonEnabled() {
		return Waitfunctionforbuttons("//button[@data-tests-id='Next']", 10);
	}

	public static WebElement waitToHomeMenu() {
		return Waitfunctionforbuttons("//*[@data-tests-id='main-menu-button-home']", 10);
	}

	public static WebElement waitToCatalogMenu() {
		return Waitfunctionforbuttons("//*[@data-tests-id='main-menu-button-catalog']", 10);
	}

	public static WebElement waitSearch() {
		return Waitfunctionforbuttons("//*[@data-tests-id='main-menu-input-search']", 10);
	}

	public static WebElement waitSubmitforTestingCard() {
		return Waitfunctionforbuttons("//*[@data-tests-id='i-sdc-dashboard-card-menu-item-SubmitforTesting']", 10);
	}

	public static WebElement waitViewCard() {
		return Waitfunctionforbuttons("//*[@data-tests-id='i-sdc-dashboard-card-menu-item-View']", 5);
	}

	public static void waitOpenCard(String requiredElementUniqueId) throws Exception {
		WebElement menu = GeneralUIUtils.getDriver()
				.findElement(By.xpath("//*[@data-tests-id='" + requiredElementUniqueId + "']"));
		GeneralUIUtils.actionBuild(menu);
	}

	public static void fillResourceGeneralInformationPage(ResourceReqDetails resource, User user) {
		try {

			ResourceGeneralPage.defineName(resource.getName());
			ResourceGeneralPage.defineDescription(resource.getDescription());
			ResourceGeneralPage.defineCategory(resource.getCategories().get(0).getSubcategories().get(0).getName());
			ResourceGeneralPage.defineVendorName(resource.getVendorName());
			ResourceGeneralPage.defineVendorRelease(resource.getVendorRelease());
			ResourceGeneralPage.defineTagsList(resource, new String[] { "This-is-tag", "another-tag", "Test-automation-tag" });
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	public static void fillNewResourceValues(ResourceReqDetails resource, User user) throws Exception {
		fillResourceGeneralInformationPage(resource, user);
		GeneralUIUtils.clickCreateButton();
	}

	// coded by teddy.
	public static WebElement waitfunctionforallelements(String element) {
		WebDriverWait wait = new WebDriverWait(GeneralUIUtils.getDriver(), 5);
		return wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@*='" + element + "']")));
	}

	public static WebElement waitFunctionForaGetElements(String element, int timeout) {
		WebDriverWait wait = new WebDriverWait(GeneralUIUtils.getDriver(), timeout);
		return wait.until(
				ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@data-tests-id='" + element + "']")));
	}

	public static void getVFCGeneralInfo(ResourceReqDetails resource, User user) throws InterruptedException {
		Thread.sleep(2000);
		String version = GeneralUIUtils.getWebElements("versionvalue").get(0).getText().substring(1);
		String name = GeneralUIUtils.getWebElementWaitForVisible("name").getAttribute("value");
		String description = GeneralUIUtils.getWebElementWaitForVisible("description").getAttribute("value");
		String category = GeneralUIUtils.getSelectList(null, "selectGeneralCategory").getFirstSelectedOption()
				.getText();
		String vendorName = GeneralUIUtils.getWebElementWaitForVisible("vendorName").getAttribute("value");
		String vendorRelease = GeneralUIUtils.getWebElementWaitForVisible("vendorRelease").getAttribute("value");
		List<WebElement> tags = GeneralUIUtils.waitForElementsListVisibility("i-sdc-tag-text");
		String type = GeneralUIUtils.waitForElementsListVisibility("type").get(1).getText();
		int index = type.lastIndexOf(":");
		System.out.println(type.substring(0, index));
		String ContactId = GeneralUIUtils.getWebElementWaitForVisible("contactId").getAttribute("value");
		System.out.println(resource.getVersion());
		assertTrue(resource.getVersion().equals(version));
		assertTrue(resource.getName().equals(name));
		assertTrue(resource.getDescription().equals(description));
		System.out.println(resource.getVendorName());
		System.out.println(resource.getVendorRelease());
		assertTrue(resource.getCategories().get(0).getSubcategories().get(0).getName().equals(category));
		assertTrue(resource.getVendorName().equals(vendorName));
		assertTrue(resource.getVendorRelease().equals(vendorRelease));
		assertTrue(resource.getCreatorUserId().equals(ContactId));
		assertEquals(type.substring(0, index), resource.getResourceType());

		for (int i = 0; i < tags.size(); i++) {
			assertEquals(resource.getTags().get(i), tags.get(i).getText());
		}
	}

	public static void getGeneralInfo(ResourceReqDetails resource, User user) {
		List<WebElement> tags = GeneralUIUtils.waitForElementsListVisibility("tag");

		for (WebElement tag : tags) {
			System.out.println(resource.getTags().get(0));
		}
	}

	public static void getGeneralInfoForTags(ResourceReqDetails resource, User user) {

		clickMore();
		String componentType = waitFunctionForaGetElements("componentType", 3).getText();
		String version = waitFunctionForaGetElements("version", 3).getText();
		String category = waitFunctionForaGetElements("category", 3).getText();// get
																				// right
																				// panel
																				// Category.
		String resourceType = waitFunctionForaGetElements("resourceType", 3).getText();// get
																						// right
																						// panel
																						// SubCategory.
		String date = GeneralUIUtils.getEelementByClassName("creationDate").getText();
		String aouthor = waitfunctionforallelements("author'").getText();
		String vendorName = waitFunctionForaGetElements("vendorName", 3).getText();
		String vendorRelease = waitFunctionForaGetElements("vendorRelease", 3).getText();
		String contactId = waitFunctionForaGetElements("contactId", 3).getText();
		String description = waitFunctionForaGetElements("description", 3).getText();
		List<WebElement> tags = GeneralUIUtils.waitForElementsListVisibility("tag");
		assertTrue(componentType.equals("RESOURCE"));
		assertTrue(version.equals(resource.getVersion()));
		assertTrue(category.equals(resource.getCategories().get(0).getName()));
		assertEquals(resourceType, resource.getResourceType());
		// assertEquals(Date,resource.getCreationDate());
		// assertEquals(Aouthor,resource.getCreatorFullName());
		assertTrue(vendorName.equals(resource.getVendorName()));
		assertTrue(vendorRelease.equals(resource.getVendorRelease()));
		assertTrue(contactId.equals(resource.getContactId()));
		assertTrue(description.equals(resource.getDescription() + "\nLess"));
		assertTrue(tags.equals("Tag-150"));
	}

	public static WebElement searchVFNameInWorkspace(ResourceReqDetails resource, User user) throws Exception {

		List<WebElement> findElements = GeneralUIUtils.getDriver()
				.findElements(By.xpath("//div[@data-tests-id='" + resource.getUniqueId() + "']"));
		assertNotNull("did not find any elements", findElements);
		for (WebElement webElement : findElements) {
			if (webElement.getText().contains(resource.getUniqueId())) {
				System.out.println("I find it");
				return webElement;
			}
		}
		return null;
	}

	public static Boolean searchCheckOutWorkspace(ResourceReqDetails resource, User user,
			CheckBoxStatusEnum checkBoxStatusEnum) throws Exception {

		List<WebElement> findElements = GeneralUIUtils.getDriver()
				.findElements(By.xpath("//div[@data-tests-id='component.lifecycleState']"));
		assertNotNull("did not find any elements", findElements);
		for (WebElement webElement : findElements) {
			if (!webElement.getAttribute("class").contains(checkBoxStatusEnum.name())) {
				return false;
			}
		}
		return true;
	}

	// coded by tedy.
	public static void validateWithRightPalett(ResourceReqDetails resource, User user) {
		// String
		// Type=Waitfunctionforallelements("sharingService.selectedEntity.getTypeForView()",3).getText();
		String ResourceType = waitfunctionforallelements("selectedComponent.resourceType").getText();
		System.out.println(ResourceType);
		String Version = waitfunctionforallelements("selectedComponent.version").getText();
		String Category = waitfunctionforallelements("selectedComponent.categories[0].name").getText();// get
																										// right
																										// panel
																										// Category.
		String CanvasSubCategory = waitfunctionforallelements("selectedComponent.categories[0].subcategories[0].name")
				.getText();// get right panel SubCategory.
		// String Date=Waitfunctionforelements("selectedComponent.creationDate |
		// date: 'MM/dd/yyyy'").getText();
		// String
		// Aouthor=waitfunctionforallelements("selectedComponent.creatorFullName'").getText();
		String VendorName = waitfunctionforallelements("selectedComponent.vendorName").getText();
		String VendorRelease = waitfunctionforallelements("selectedComponent.vendorRelease").getText();
		String contactId = waitfunctionforallelements("selectedComponent.contactId").getText();
		String Description = waitfunctionforallelements("selectedComponent.description").getText();
		String TagVF = waitfunctionforallelements("tag").getText();
		AssertJUnit.assertEquals(ResourceType, resource.getResourceType());
		AssertJUnit.assertEquals(Version, resource.getVersion());
		AssertJUnit.assertEquals(Category, resource.getCategories().get(0).getName());
		AssertJUnit.assertEquals(CanvasSubCategory,
				resource.getCategories().get(0).getSubcategories().get(0).getName());
		// assertEquals(Date,resource.getCreationDate());
		// assertEquals(Aouthor,resource.getCreatorFullName());
		AssertJUnit.assertEquals(VendorName, resource.getVendorName());
		AssertJUnit.assertEquals(VendorRelease, resource.getVendorRelease());
		AssertJUnit.assertEquals(contactId, resource.getContactId());
		AssertJUnit.assertEquals(Description, resource.getDescription() + "\nLess");
		AssertJUnit.assertEquals(TagVF, "qa123");
	}

	public static void clickMore() {
		WebElement clickButtonSubmit = GeneralUIUtils.getDriver()
				.findElement(By.className("ellipsis-directive-more-less"));
		clickButtonSubmit.click();
	}

	public static RestResponse createResourceInUI(ResourceReqDetails resource, User user)
			throws Exception, AWTException {
		System.out.println("creating resource...");
		fillNewResourceValues(resource, user);
		RestResponse getCreatedResource = RestCDUtils.getResource(resource, user);
		AssertJUnit.assertEquals("Did not succeed to get any resource", HttpStatus.SC_OK,
				getCreatedResource.getErrorCode().intValue());

		return getCreatedResource;
	}

	public static RestResponse createResource(ResourceReqDetails resource, User user) throws Exception, AWTException {

		ResourceUIUtils.moveToHTMLElementByClassName("w-sdc-dashboard-card-new");
		ResourceUIUtils.clickOnHTMLElementByDataTestId(DataTestIdEnum.Dashboard.BUTTON_ADD_VF.getValue());
		GeneralUIUtils.waitForLoader();
		// GeneralUIUtils.sleep(1000);
		fillResourceGeneralInformationPage(resource, user);
		GeneralUIUtils.clickCreateButton();
		return null;

	}

	public static RestResponse updateResourceInformationPage(ResourceReqDetails resource, User user)
			throws Exception, AWTException {

		fillResourceGeneralInformationPage(resource, user);
		GeneralUIUtils.clickCreateButton();
		return null;

	}

	public static RestResponse checkInResourceInUI(ResourceReqDetails resource, User user) throws Exception {

		WebElement ASDCLink = GeneralUIUtils.getDriver().findElement(By.className("w-sdc-header-logo-link"));
		ASDCLink.click();
		Thread.sleep(2000);

		List<WebElement> listFormInput = GeneralUIUtils.getDriver()
				.findElements(By.className("i-sdc-left-sidebar-nav-item"));
		WebElement addPropertyElement = listFormInput.get(0);
		addPropertyElement.click();
		Thread.sleep(2000);

		WebElement searchResource = GeneralUIUtils.getDriver()
				.findElement(By.className("w-sdc-header-catalog-search-input"));
		searchResource.sendKeys("newresource4test");

		Thread.sleep(1000);

		WebElement buttonClickMenu = GeneralUIUtils.getDriver()
				.findElement(By.className("w-sdc-dashboard-card-menu-button"));
		buttonClickMenu.click();

		WebElement clickMenu = GeneralUIUtils.getDriver().findElement(By.className("w-sdc-dashboard-card-menu"));
		clickMenu.click();

		List<WebElement> clickCheckIn = GeneralUIUtils.getDriver()
				.findElements(By.className("i-sdc-dashboard-card-menu-item"));
		WebElement clickCheckInMenu = clickCheckIn.get(1);
		clickCheckInMenu.click();

		WebElement descriptionForSubmit = GeneralUIUtils.getDriver()
				.findElement(By.className("w-sdc-modal-body-comment"));
		descriptionForSubmit.sendKeys("checkin resource");
		Thread.sleep(2000);
		WebElement clickButtonSubmitTwo = GeneralUIUtils.getDriver().findElement(By.className("w-sdc-btn-blue"));
		clickButtonSubmitTwo.click();
		Thread.sleep(2000);

		WebElement buttonClickMenu1 = GeneralUIUtils.getDriver()
				.findElement(By.className("w-sdc-dashboard-card-menu-button"));
		buttonClickMenu1.click();

		WebElement clickMenu1 = GeneralUIUtils.getDriver().findElement(By.className("w-sdc-dashboard-card-menu"));
		clickMenu1.click();

		List<WebElement> clickCheckOut = GeneralUIUtils.getDriver()
				.findElements(By.className("i-sdc-dashboard-card-menu-item"));
		WebElement clickCheckOutMenu = clickCheckOut.get(0);
		clickCheckOutMenu.click();

		Thread.sleep(3000);
		RestResponse getResource = RestCDUtils.getResource(resource, user);
		AssertJUnit.assertEquals("Did not succeed to get resource after create", 200,
				getResource.getErrorCode().intValue());
		return getResource;

	}

	public static String lifeCycleStateUI() throws InterruptedException {
		return GeneralUIUtils.getWebElementWaitForVisible("formlifecyclestate").getText();
	}

	public static List<String> catalogFilterResourceCategoriesChecBox(ResourceCategoriesNameEnum enumName)
			throws Exception {
		List<String> categories = Arrays.asList();
		switch (enumName) {
		case APPLICATIONL4:
			GeneralUIUtils.getWebElementWaitForVisible(enumName.getValue()).click();
			categories = Arrays.asList("applicationServer", "defaulticon", "vl", "cp", "call_controll", "borderElement",
					"network", "firewall", "database", "loadBalancer");
			break;
		case APPLICATION_SERVER:
			GeneralUIUtils.getWebElementWaitForVisible(enumName.getValue()).click();
			categories = Arrays.asList("applicationServer", "vl", "cp", "defaulticon");
			break;
		case BORDER_ELEMENT:
			GeneralUIUtils.getWebElementWaitForVisible(enumName.getValue()).click();
			categories = Arrays.asList("borderElement", "vl", "cp", "defaulticon");
			break;
		case CALL_CONTROL:
			GeneralUIUtils.getWebElementWaitForVisible(enumName.getValue()).click();
			categories = Arrays.asList("call_controll", "vl", "cp", "defaulticon");
			break;
		case COMMON_NETWORK_RESOURCES:
			GeneralUIUtils.getEelementByLinkText("Common Network Resources").click();
			categories = Arrays.asList("network", "vl", "cp", "defaulticon");
			break;
		case CONNECTION_POINTS:
			GeneralUIUtils.getWebElementWaitForVisible(enumName.getValue()).click();
			categories = Arrays.asList("cp", "defaulticon");
			break;
		case DATABASE:
			GeneralUIUtils.getWebElementWaitForVisible(enumName.getValue()).click();
			categories = Arrays.asList("database", "vl", "cp", "defaulticon");
			break;
		case DATABASE_GENERIC:
			GeneralUIUtils.getWebElementWaitForVisible(enumName.getValue()).click();
			categories = Arrays.asList("database", "vl", "cp", "defaulticon");
			break;
		case FIREWALL:
			GeneralUIUtils.getWebElementWaitForVisible(enumName.getValue()).click();
			categories = Arrays.asList("firewall", "vl", "cp", "defaulticon");
			break;
		case GATEWAY:
			GeneralUIUtils.getWebElementWaitForVisible(enumName.getValue()).click();
			categories = Arrays.asList("gateway", "vl", "cp", "defaulticon");
			break;
		case INFRASTRUCTURE:
			GeneralUIUtils.getWebElementWaitForVisible(enumName.getValue()).click();
			categories = Arrays.asList("connector", "vl", "cp", "defaulticon");
			break;
		case INFRASTRUCTUREL23:
			GeneralUIUtils.getWebElementWaitForVisible(enumName.getValue()).click();
			categories = Arrays.asList("ucpe", "vl", "cp", "defaulticon");
			break;
		case LAN_CONNECTORS:
			GeneralUIUtils.getWebElementWaitForVisible(enumName.getValue()).click();
			categories = Arrays.asList("network", "port", "connector", "vl", "cp", "defaulticon");
			break;
		case LOAD_BALANCER:
			GeneralUIUtils.getWebElementWaitForVisible(enumName.getValue()).click();
			categories = Arrays.asList("loadBalancer", "vl", "cp", "defaulticon");
			break;
		case MEDIA_SERVERS:
			GeneralUIUtils.getWebElementWaitForVisible(enumName.getValue()).click();
			categories = Arrays.asList("network", "vl", "cp", "defaulticon");
			break;
		case NETWORKL4:
			GeneralUIUtils.getWebElementWaitForVisible(enumName.getValue()).click();
			categories = Arrays.asList("network", "vl", "cp", "defaulticon");
			break;
		case NETWORK_ELEMENTS:
			GeneralUIUtils.getWebElementWaitForVisible(enumName.getValue()).click();
			categories = Arrays.asList("port", "defaulticon", "network", "connector", "vl", "cp");
			break;
		case NETWORK_L23:
			GeneralUIUtils.getWebElementWaitForVisible(enumName.getValue()).click();
			categories = Arrays.asList("network", "vl", "defaulticon", "cp", "router", "port", "connector", "gateway",
					"ucpe");
			break;
		case NETWORK_CONNECTIVITY:
			GeneralUIUtils.getWebElementWaitForVisible(enumName.getValue()).click();
			categories = Arrays.asList("network", "vl", "cp", "defaulticon");
			break;
		case GENERIC:
			GeneralUIUtils.getWebElementWaitForVisible(enumName.getValue()).click();
			categories = Arrays.asList("database", "port", "loadBalancer", "vl", "cp", "objectStorage", "compute",
					"defaulticon", "ucpe", "network", "connector");
			break;
		case ABSTRACT:
			GeneralUIUtils.getWebElementWaitForVisible(enumName.getValue()).click();
			categories = Arrays.asList("objectStorage", "compute", "defaulticon", "cp", "vl");
			break;
		case Router:
			GeneralUIUtils.getWebElementWaitForVisible(enumName.getValue()).click();
			categories = Arrays.asList("router", "vl", "cp", "defaulticon");
			break;
		case VIRTUAL_LINKS:
			GeneralUIUtils.getWebElementWaitForVisible(enumName.getValue()).click();
			categories = Arrays.asList("vl", "defaulticon");
			break;
		case WAN_Connectors:
			GeneralUIUtils.getWebElementWaitForVisible(enumName.getValue()).click();
			categories = Arrays.asList("network", "port", "connector", "vl", "cp", "defaulticon");
			break;
		case WEB_SERVER:
			GeneralUIUtils.getWebElementWaitForVisible(enumName.getValue()).click();
			categories = Arrays.asList("applicationServer", "vl", "cp", "defaulticon");
			break;
		}
		return categories;
	}

	public static void deleteVersionInUI() throws Exception {

		waitToDeleteVersion().click();
		ResourceUIUtils.clickButtonBlue();
	}

	public static void selectTabInRightPallete(String className) throws Exception {
		WebElement tab = GeneralUIUtils.getEelementBycontainsClassName(className);
		tab.click();
	}

	public static WebElement waitToDeleteVersion() {
		return Waitfunctionforbuttons("//*[@data-tests-id='deleteVersion']", 10);
	}

	public static WebElement rihtPanelAPI() {
		return waitFunctionForaGetElements("tab-api", 10);
	}

	/**
	 * Click on HTML element.
	 * 
	 * @param dataTestId
	 * @throws Exception
	 */
	public static void clickOnHTMLElementByDataTestId(String dataTestId) throws Exception {
		WebDriverWait wait = new WebDriverWait(GeneralUIUtils.getDriver(), 20);
		WebElement element = wait
				.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@data-tests-id='" + dataTestId + "']")));
		element.click();
		// wait.until(ExpectedConditions.elemetto)
		// WebElement serviceButton =
		// GeneralUIUtils.getDriver().findElement(By.xpath("//*[@data-tests-id='"
		// + dataTestId + "']"));
		// serviceButton.
		// serviceButton.click();
	}

	/**
	 * Move to HTML element by class name. When moving to the HTML element, it
	 * will raise hover event.
	 * 
	 * @param className
	 */
	public static void moveToHTMLElementByClassName(String className) {
		Actions actions = new Actions(GeneralUIUtils.getDriver());
		final WebElement createButtonsArea = GeneralUIUtils
				.retryMethodOnException(() -> GeneralUIUtils.getDriver().findElement(By.className(className)));
		actions.moveToElement(createButtonsArea).perform();
	}

	/**
	 * Move to HTML element by element id. When moving to the HTML element, it
	 * will raise hover event.
	 * 
	 * @param className
	 */
	static void moveToHTMLElementByDataTestId(String dataTestId) {
		// WebElement hoverArea =
		// GeneralUIUtils.getDriver().findElement(By.xpath("//*[@data-tests-id='"
		// + dataTestId + "']"));
		WebElement hoverArea = GeneralUIUtils.waitForElementVisibility(dataTestId);
		// WebDriverWait wait = new WebDriverWait(GeneralUIUtils.getDriver(),
		// 30);
		// wait.until(ExpectedConditions.visibilityOf(hoverArea));

		Actions actions = new Actions(GeneralUIUtils.getDriver());
		actions.moveToElement(hoverArea).perform();
	}

	// public static ResourceReqDetails createResourceInUI(User user){
	// try{
	// ResourceReqDetails defineResourceDetails =
	// defineResourceDetails(ResourceTypeEnum.VF);
	// ResourceUIUtils.moveToHTMLElementByClassName("w-sdc-dashboard-card-new");
	// ResourceUIUtils.clickOnHTMLElementByDataTestId(DataTestIdEnum.Dashboard.BUTTON_ADD_VF.getValue());
	// GeneralUIUtils.waitForLoader();
	//// GeneralUIUtils.sleep(1000);
	// fillResourceGeneralInformationPage(defineResourceDetails, user);
	// GeneralUIUtils.clickCreateButton();
	// return defineResourceDetails;
	// }
	// catch( Exception e){
	// throw new RuntimeException(e);
	// }
	// }

	/**
	 * Import VFC
	 * 
	 * @param user
	 * @param filePath
	 * @param fileName
	 * @return
	 * @throws Exception
	 */

	public static void importVfc(ResourceReqDetails resourceMetaData, String filePath, String fileName, User user)
			throws Exception {
		GeneralUIUtils.hoverOnArea(Dashboard.IMPORT_AREA.getValue());
		// Insert file to the browse dialog
		final WebElement browseWebElement = GeneralUIUtils
				.getWebElementByDataTestId(DataTestIdEnum.Dashboard.IMPORT_VFC_FILE.getValue());
		browseWebElement.sendKeys(filePath + fileName);

		// Fill the general page fields.
		GeneralUIUtils.waitForLoader();
		fillResourceGeneralInformationPage(resourceMetaData, user);
		GeneralUIUtils.clickCreateButton();

	}

	// public static ResourceReqDetails importVfcInUI(User user, String
	// filePath, String fileName, ResourceTypeEnum resourceType) {
	// ResourceReqDetails defineResourceDetails =
	// defineResourceDetails(resourceType);
	// ResourceUIUtils.moveToHTMLElementByDataTestId(Dashboard.IMPORT_AREA.getValue());
	//
	// // Insert file to the browse dialog
	// final WebElement browseWebElement =
	// GeneralUIUtils.getWebElementByDataTestId(DataTestIdEnum.Dashboard.IMPORT_VFC_FILE.getValue());
	// browseWebElement.sendKeys(filePath + fileName);
	//
	// // Fill the general page fields.
	// GeneralUIUtils.waitForLoader();
	// fillResourceGeneralInformationPage(defineResourceDetails, user);
	// GeneralUIUtils.clickCreateButton();
	// return defineResourceDetails;
	// }

	/**
	 * Import VF
	 * 
	 * @param user
	 * @param filePath
	 * @param fileName
	 * @return
	 * @throws Exception
	 */
	// public static ResourceReqDetails importVfInUI(User user, String filePath,
	// String fileName) throws Exception {
	// ResourceReqDetails defineResourceDetails =
	// defineResourceDetails(ResourceTypeEnum.VF);
	// ResourceUIUtils.moveToHTMLElementByDataTestId(Dashboard.IMPORT_AREA.getValue());
	//
	// // Insert file to the browse dialog
	// final WebElement browseWebElement =
	// GeneralUIUtils.getWebElementByDataTestId(DataTestIdEnum.Dashboard.IMPORT_VF_FILE.getValue());
	// browseWebElement.sendKeys(filePath + fileName);
	//
	// // Fill the general page fields.
	// GeneralUIUtils.waitForLoader();
	// fillResourceGeneralInformationPage(defineResourceDetails, user);
	// GeneralUIUtils.clickCreateButton();
	// return defineResourceDetails;
	// }

	// public static ResourceReqDetails defineResourceDetails(ResourceTypeEnum
	// resourceType) {
	// ResourceReqDetails resource = new ResourceReqDetails();
	// resource = ElementFactory.getDefaultResource(NormativeTypesEnum.ROOT,
	// ResourceCategoryEnum.APPLICATION_L4_CALL_CONTROL);
	// resource.setVersion(INITIAL_VERSION);
	// resource.setIcon(ICON_RESOURCE_NAME);
	// resource.setResourceType(resourceType.toString());
	// resource.setName(getRandomComponentName(RESOURCE_NAME_PREFIX));
	//
	// SetupCDTest.setCreatedComponents(Arrays.asList(resource));
	//
	// return resource;
	// }

	protected static String getRandomComponentName(String prefix) {
		return prefix + new Random().nextInt(10000);
	}

	public static ImmutablePair<String, String> getFirstRIPos(ResourceReqDetails createResourceInUI, User user) {
		String responseAfterDrag = RestCDUtils.getResource(createResourceInUI, user).getResponse();
		JSONObject jsonResource = (JSONObject) JSONValue.parse(responseAfterDrag);
		String xPosPostDrag = (String) ((JSONObject) ((JSONArray) jsonResource.get("componentInstances")).get(0))
				.get("posX");
		String yPosPostDrag = (String) ((JSONObject) ((JSONArray) jsonResource.get("componentInstances")).get(0))
				.get("posY");
		return new ImmutablePair<String, String>(xPosPostDrag, yPosPostDrag);

	}

	public static WebElement getErrorMessageText(WebDriver driver, String text) throws Exception {

		return GeneralUIUtils.getEelementBycontainsClassName(text);

	}

	public static void fillGeneralInfoValuesAndIcon(ResourceReqDetails resource, User user) throws Exception {
		fillResourceGeneralInformationPage(resource, user);
		GeneralUIUtils.clickCreateButton();

		selectRandomResourceIcon();
	}

	// coded by teddy.
	public static void getVFCGeneralInfoAndValidate(ResourceReqDetails resource, User user)
			throws InterruptedException {
		Thread.sleep(2000);
		WebDriver driver = GeneralUIUtils.getDriver();
		String version = GeneralUIUtils.getSelectList(null, "versionHeader").getFirstSelectedOption().getText();
		String name = GeneralUIUtils.getWebElement(driver, "name").getAttribute("value");
		String description = GeneralUIUtils.getWebElement(driver, "description").getAttribute("value");
		String category = GeneralUIUtils.getSelectList(null, "selectGeneralCategory").getFirstSelectedOption()
				.getText();
		String vendorName = GeneralUIUtils.getWebElement(driver, "vendorName").getAttribute("value");
		String vendorRelease = GeneralUIUtils.getWebElement(driver, "vendorRelease").getAttribute("value");
		List<WebElement> tags = GeneralUIUtils.waitForElementsListVisibility("i-sdc-tag-text");
		String type = GeneralUIUtils.waitForElementsListVisibility("type").get(1).getText();
		int index = type.lastIndexOf(":");
		System.out.println(type.substring(0, index));
		String contactId = GeneralUIUtils.getWebElement(driver, "contactId").getAttribute("value");
		System.out.println(resource.getVersion());
		assertTrue(resource.getVersion().equals(version.substring(1)));
		assertTrue(resource.getName().equals(name));
		assertTrue(resource.getDescription().equals(description));
		System.out.println(resource.getVendorName());
		System.out.println(resource.getVendorRelease());
		assertTrue(resource.getCategories().get(0).getSubcategories().get(0).getName().equals(category));
		assertTrue(resource.getVendorName().equals(vendorName));
		assertTrue(resource.getVendorRelease().equals(vendorRelease));
		assertTrue(resource.getCreatorUserId().equals(contactId));
		assertEquals(type.substring(0, index), resource.getResourceType());

		for (int i = 0; i < tags.size(); i++) {
			assertEquals(resource.getTags().get(i), tags.get(i).getText());
		}
	}

	public static RestResponse createResourceNG(ResourceReqDetails resource, User user) throws Exception, AWTException {

		ResourceUIUtils.moveToHTMLElementByClassName("w-sdc-dashboard-card-new");
		ResourceUIUtils.clickOnHTMLElementByDataTestId(DataTestIdEnum.Dashboard.BUTTON_ADD_VF.getValue());
		fillResourceGeneralInformationPage(resource, user);
		GeneralUIUtils.clickOnHTMLElementByDataTestId(DataTestIdEnum.LifeCyleChangeButtons.CREATE.getValue());
		return null;

	}
}