[SDC-29] rebase continue work to align source
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / utilities / ResourceUIUtils.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.assertNotNull;
25 import static org.testng.AssertJUnit.assertTrue;
26
27 import java.awt.AWTException;
28 import java.awt.Robot;
29 import java.awt.Toolkit;
30 import java.awt.datatransfer.Clipboard;
31 import java.awt.datatransfer.StringSelection;
32 import java.awt.event.KeyEvent;
33 import java.io.File;
34 import java.util.Arrays;
35 import java.util.List;
36 import java.util.Random;
37
38 import org.apache.commons.lang3.tuple.ImmutablePair;
39 import org.apache.http.HttpStatus;
40 import org.json.simple.JSONArray;
41 import org.json.simple.JSONObject;
42 import org.json.simple.JSONValue;
43 import org.openecomp.sdc.be.model.User;
44 import org.openecomp.sdc.ci.tests.datatypes.CheckBoxStatusEnum;
45 import org.openecomp.sdc.ci.tests.datatypes.CreateAndImportButtonsEnum;
46 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
47 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum.Dashboard;
48 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum.StepsEnum;
49 import org.openecomp.sdc.ci.tests.datatypes.ResourceCategoriesNameEnum;
50 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
51 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
52 import org.openecomp.sdc.ci.tests.execute.setup.ExtentTestActions;
53 import org.openecomp.sdc.ci.tests.execute.setup.SetupCDTest;
54 import org.openecomp.sdc.ci.tests.pages.GeneralPageElements;
55 import org.openecomp.sdc.ci.tests.pages.ResourceGeneralPage;
56 import org.openqa.selenium.By;
57 import org.openqa.selenium.ElementNotVisibleException;
58 import org.openqa.selenium.WebDriver;
59 import org.openqa.selenium.WebElement;
60 import org.openqa.selenium.support.ui.ExpectedConditions;
61 import org.openqa.selenium.support.ui.Select;
62 import org.openqa.selenium.support.ui.WebDriverWait;
63 import org.testng.AssertJUnit;
64
65 import com.aventstack.extentreports.Status;
66
67 public final class ResourceUIUtils {
68         public static final String RESOURCE_NAME_PREFIX = "ResourceCDTest-";
69         protected static final boolean IS_BEFORE_TEST = true;
70         public static final String INITIAL_VERSION = "0.1";
71         public static final String ICON_RESOURCE_NAME = "call_controll";
72         protected static final String UPDATED_RESOURCE_ICON_NAME = "objectStorage";
73
74         private ResourceUIUtils() {
75         }
76
77         static WebDriver driver = GeneralUIUtils.getDriver();
78
79         public static void defineResourceName(String resourceName) {
80
81                 WebElement resourceNameTextbox = GeneralUIUtils.getDriver().findElement(By.name("componentName"));
82                 resourceNameTextbox.clear();
83                 resourceNameTextbox.sendKeys(resourceName);
84         }
85
86         public static void defineResourceCategory(String category, String datatestsid) {
87
88                 GeneralUIUtils.getSelectList(category, datatestsid);
89         }
90
91         // public static void uploadFileWithJavaRobot(String FilePath,String
92         // FileName) throws Exception{
93         //
94         // StringSelection Path= new StringSelection(FilePath+FileName);
95         // Thread.sleep(1000);
96         // java.awt.Toolkit.getDefaultToolkit().getSystemClipboard().setContents(Path,
97         // null);
98         // Robot robot = new Robot();
99         // robot.delay(1000);
100         // robot.keyPress(KeyEvent.VK_CONTROL);
101         // robot.keyPress(KeyEvent.VK_V);
102         // robot.keyRelease(KeyEvent.VK_V);
103         // robot.keyRelease(KeyEvent.VK_CONTROL);
104         // robot.delay(1000);
105         // robot.keyPress(KeyEvent.VK_ENTER);
106         // robot.keyRelease(KeyEvent.VK_ENTER);
107         // robot.delay(1000);
108         // }
109         // click and upload tosca file //**to be changed.
110         public static void importFileWithSendKey(String FilePath, String FileName, CreateAndImportButtonsEnum type)
111                         throws Exception {
112                 WebElement importButton = HomeUtils.createAndImportButtons(type, driver).findElement(By.tagName("input"));
113                 importButton.sendKeys(FilePath + FileName);
114         }
115
116         public static void importFileWithSendKeyBrowse(String FilePath, String FileName) throws Exception {
117                 WebElement browsebutton = GeneralUIUtils.getWebElementByTestID("browseButton");
118                 browsebutton.sendKeys(FilePath + FileName);
119         }
120
121         // public static void defineVendorName(String resourceVendorName) {
122         //
123         // WebElement resourceVendorNameTextbox =
124         // GeneralUIUtils.getWebElementByTestID("vendorName");
125         // resourceVendorNameTextbox.clear();
126         // resourceVendorNameTextbox.sendKeys(resourceVendorName);
127         // }
128
129         // public static void defineTagsList(ResourceReqDetails resource,String
130         // []resourceTags) {
131         // List<String>taglist = new ArrayList<String>();;
132         // WebElement resourceTagsTextbox =
133         // GeneralUIUtils.getWebElementByTestID("i-sdc-tag-input");
134         // for (String tag : resourceTags) {
135         // resourceTagsTextbox.clear();
136         // resourceTagsTextbox.sendKeys(tag);
137         // resourceTagsTextbox.sendKeys(Keys.ENTER);
138         // taglist.add(tag);
139         // }
140         // resource.setTags(taglist);
141         // }
142
143         public static String defineUserId(String userId) {
144                 //
145                 WebElement resourceUserIdTextbox = ResourceGeneralPage.getContactIdField();
146                 resourceUserIdTextbox.clear();
147                 resourceUserIdTextbox.sendKeys(userId);
148                 return userId;
149         }
150
151         public static void defineVendorRelease(String resourceVendorRelease) {
152
153                 WebElement resourceVendorReleaseTextbox = GeneralUIUtils.getWebElementByTestID("vendorRelease");
154                 resourceVendorReleaseTextbox.clear();
155                 resourceVendorReleaseTextbox.sendKeys(resourceVendorRelease);
156         }
157
158         public static void selectResourceIcon(String resourceIcon) throws Exception {
159                 WebDriverWait wait = new WebDriverWait(GeneralUIUtils.getDriver(), 10);
160                 wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@data-tests-id='" + resourceIcon + "']")))
161                                 .click();
162         }
163
164         public static String definePropertyName(String name) {
165
166                 WebElement nameProperty = GeneralUIUtils.getDriver().findElement(By.name("propertyName"));
167                 nameProperty.sendKeys(name);
168                 return name;
169         }
170
171         public static void selectRandomResourceIcon() throws Exception {
172                 GeneralUIUtils.moveToStep(StepsEnum.ICON);
173                 WebDriverWait wait = new WebDriverWait(GeneralUIUtils.getDriver(), 4);
174                 wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[contains(@data-tests-id, 'iconBox')]")));
175                 List<WebElement> iconElement = GeneralUIUtils.getDriver()
176                                 .findElements(By.xpath("//*[contains(@data-tests-id, 'iconBox')]"));
177                 iconElement.get(0).click();
178         }
179
180         public static List<WebElement> getAllObjectsOnWorkspace(WebDriver driver, ResourceReqDetails resource)
181                         throws Exception {
182
183                 WebDriverWait wait = new WebDriverWait(GeneralUIUtils.getDriver(), 10);
184                 wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@*='" + resource.getName() + "']")));
185                 return GeneralUIUtils.getDriver()
186                                 .findElements(By.xpath("//div[@class='" + "w-sdc-dashboard-card-info-name" + "']"));
187
188         }
189
190         public static String getErrorMessageText(String text) throws Exception {
191
192                 return GeneralUIUtils.getWebElementByClassName(text).getText();
193
194         }
195
196         public static WebElement scrollElement(WebDriver driver) throws Exception {
197
198                 return GeneralUIUtils.getDriver().findElement(By.className("ps-scrollbar-y"));
199         }
200
201         public static void scrollDownPage() throws AWTException, InterruptedException {
202                 Robot robot = new Robot();
203                 robot.keyPress(KeyEvent.VK_PAGE_DOWN);
204                 robot.keyRelease(KeyEvent.VK_PAGE_DOWN);
205                 robot.keyPress(KeyEvent.VK_PAGE_DOWN);
206                 robot.keyRelease(KeyEvent.VK_PAGE_DOWN);
207                 robot.keyPress(KeyEvent.VK_PAGE_DOWN);
208                 robot.keyRelease(KeyEvent.VK_PAGE_DOWN);
209                 robot.keyPress(KeyEvent.VK_PAGE_DOWN);
210                 robot.keyRelease(KeyEvent.VK_PAGE_DOWN);
211                 robot.keyPress(KeyEvent.VK_PAGE_DOWN);
212                 robot.keyRelease(KeyEvent.VK_PAGE_DOWN);
213                 robot.keyPress(KeyEvent.VK_PAGE_DOWN);
214                 robot.keyRelease(KeyEvent.VK_PAGE_DOWN);
215                 robot.keyPress(KeyEvent.VK_PAGE_DOWN);
216                 robot.keyRelease(KeyEvent.VK_PAGE_DOWN);
217         }
218
219         public static void defineNewSelectList(String Text) {
220                 WebElement mySelectElm = GeneralUIUtils.getDriver().findElement(By.className("i-sdc-form-select"));
221                 Select mySelectString = new Select(mySelectElm);
222                 mySelectString.selectByVisibleText(Text);
223         }
224
225         public static void defineDefaultValueByType(String Value) {
226
227                 WebElement valueString = GeneralUIUtils.getDriver().findElement(By.name("value"));
228                 valueString.clear();
229                 valueString.sendKeys(Value);
230         }
231
232         public static void defineBoolenDefaultValue(String Value) {
233
234                 WebElement elementBoolean = GeneralUIUtils.getDriver().findElement(By.name("value"));
235                 Select se = new Select(elementBoolean);
236                 se.selectByValue(Value);
237         }
238
239         public static void clickButtonBlue() {
240                 WebElement clickButtonBlue = GeneralUIUtils.getDriver().findElement(By.className("w-sdc-btn-blue"));
241                 clickButtonBlue.click();
242         }
243
244         public static void clickButton(String selectButton) {
245
246                 WebElement clickButton = GeneralUIUtils.getDriver()
247                                 .findElement(By.xpath("//*[@data-tests-id='" + selectButton + "']"));
248                 clickButton.click();
249         }
250
251         public static WebElement Waitfunctionforbuttons(String element, int timeout) {
252                 WebDriverWait wait = new WebDriverWait(GeneralUIUtils.getDriver(), timeout);
253                 return wait.until(ExpectedConditions.elementToBeClickable(By.xpath(element)));
254         }
255
256         public static WebElement waitToButtonSubmitForTesting() {
257                 return Waitfunctionforbuttons("//*[@data-tests-id='submitForTesting']", 10);
258         }
259
260         public static WebElement waitToFinishButtonEnabled() {
261                 return Waitfunctionforbuttons("//button[@data-tests-id='Finish']", 10);
262         }
263
264         public static WebElement waitToNextButtonEnabled() {
265                 return Waitfunctionforbuttons("//button[@data-tests-id='Next']", 10);
266         }
267
268         public static WebElement waitToHomeMenu() {
269                 return Waitfunctionforbuttons("//*[@data-tests-id='main-menu-button-home']", 10);
270         }
271
272         public static WebElement waitToCatalogMenu() {
273                 return Waitfunctionforbuttons("//*[@data-tests-id='main-menu-button-catalog']", 10);
274         }
275
276         public static WebElement waitSearch() {
277                 return Waitfunctionforbuttons("//*[@data-tests-id='main-menu-input-search']", 10);
278         }
279
280         public static WebElement waitSubmitforTestingCard() {
281                 return Waitfunctionforbuttons("//*[@data-tests-id='i-sdc-dashboard-card-menu-item-SubmitforTesting']", 10);
282         }
283
284         public static WebElement waitViewCard() {
285                 return Waitfunctionforbuttons("//*[@data-tests-id='i-sdc-dashboard-card-menu-item-View']", 5);
286         }
287
288 //      public static void waitOpenCard(String requiredElementUniqueId) throws Exception {
289 //              WebElement menu = GeneralUIUtils.getDriver()
290 //                              .findElement(By.xpath("//*[@data-tests-id='" + requiredElementUniqueId + "']"));
291 //              GeneralUIUtils.hoverOnAreaByTestId(menu);
292 //      }
293
294         public static void fillResourceGeneralInformationPage(ResourceReqDetails resource, User user, boolean isNewResource) {
295                 try {
296                         ResourceGeneralPage.defineName(resource.getName());
297                         ResourceGeneralPage.defineDescription(resource.getDescription());
298                         ResourceGeneralPage.defineCategory(resource.getCategories().get(0).getSubcategories().get(0).getName());
299                         ResourceGeneralPage.defineVendorName(resource.getVendorName());
300                         ResourceGeneralPage.defineVendorRelease(resource.getVendorRelease());
301                         if (isNewResource){
302                                 ResourceGeneralPage.defineTagsList(resource, new String[] { "This-is-tag", "another-tag", "Test-automation-tag" });
303                         }
304                         else{
305                                 ResourceGeneralPage.defineTagsList(resource, new String[] { "one-more-tag" });
306                         }
307                 } catch (Exception e) {
308                         throw new RuntimeException(e);
309                 }
310         }
311         
312         public static void fillMaxValueResourceGeneralInformationPage(ResourceReqDetails resource) {
313                         String stringPattern = "ABCDabcd123456";
314                         GeneralUIUtils.addStringtoClipboard(buildStringFromPattern(stringPattern, 5000));                 
315                     ResourceGeneralPage.defineNameWithPaste();
316                     ResourceGeneralPage.defineDescriptionWithPaste();
317                     ResourceGeneralPage.defineVendorNameWithPaste();
318                     ResourceGeneralPage.defineVendorReleaseWithPaste();
319 //                      ResourceGeneralPage.defineName(buildStringFromPattern(stringPattern, 5000));
320 //                      ResourceGeneralPage.defineDescription(buildStringFromPattern(stringPattern, 5000));
321 //                      ResourceGeneralPage.defineVendorName(buildStringFromPattern(stringPattern, 5000));
322 //                      ResourceGeneralPage.defineVendorRelease(buildStringFromPattern(stringPattern, 5000));
323 //                      ResourceGeneralPage.defineTagsList(resource, new String[] { buildStringFromPattern(stringPattern, 5000) });
324                     ResourceGeneralPage.defineTagsListWithPaste();
325                         GeneralUIUtils.waitForAngular();
326         }
327         
328         public static String buildStringFromPattern(String stringPattern, int stringLength){
329                 char[] chars = stringPattern.toCharArray();
330                 StringBuilder sb = new StringBuilder();
331                 Random random = new Random();
332                 for (int i = 0; i < stringLength; i++) {
333                     char c = chars[random.nextInt(chars.length)];
334                     sb.append(c);
335                 }
336                 return sb.toString();
337         }
338
339         public static void fillNewResourceValues(ResourceReqDetails resource, User user) throws Exception {
340                 fillResourceGeneralInformationPage(resource, user, true);
341                 GeneralPageElements.clickCreateButton();
342                 // selectIcon();
343         }
344
345         // coded by teddy.
346
347         public static WebElement waitfunctionforallelements(String element) {
348                 WebDriverWait wait = new WebDriverWait(GeneralUIUtils.getDriver(), 5);
349                 return wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@*='" + element + "']")));
350         }
351
352         public static WebElement waitFunctionForaGetElements(String element, int timeout) {
353                 WebDriverWait wait = new WebDriverWait(GeneralUIUtils.getDriver(), timeout);
354                 return wait.until(
355                                 ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@data-tests-id='" + element + "']")));
356         }
357
358         public static void getVFCGeneralInfo(ResourceReqDetails resource, User user) throws InterruptedException {
359                 Thread.sleep(2000);
360                 String version = GeneralUIUtils.getWebElementsListByTestID("versionvalue").get(0).getText().substring(1);
361                 String name = GeneralUIUtils.getWebElementByTestID("name").getAttribute("value");
362                 String description = GeneralUIUtils.getWebElementByTestID("description").getAttribute("value");
363                 String category = GeneralUIUtils.getSelectList(null, "selectGeneralCategory").getFirstSelectedOption()
364                                 .getText();
365                 String vendorName = GeneralUIUtils.getWebElementByTestID("vendorName").getAttribute("value");
366                 String vendorRelease = GeneralUIUtils.getWebElementByTestID("vendorRelease").getAttribute("value");
367                 List<WebElement> tags = GeneralUIUtils.getWebElementsListByTestID("i-sdc-tag-text");
368                 String type = GeneralUIUtils.getWebElementsListByTestID("type").get(1).getText();
369                 int index = type.lastIndexOf(":");
370                 System.out.println(type.substring(0, index));
371                 String AttContact = GeneralUIUtils.getWebElementByTestID("attContact").getAttribute("value");
372                 System.out.println(resource.getVersion());
373                 assertTrue(resource.getVersion().equals(version));
374                 assertTrue(resource.getName().equals(name));
375                 assertTrue(resource.getDescription().equals(description));
376                 System.out.println(resource.getVendorName());
377                 System.out.println(resource.getVendorRelease());
378                 assertTrue(resource.getCategories().get(0).getSubcategories().get(0).getName().equals(category));
379                 assertTrue(resource.getVendorName().equals(vendorName));
380                 assertTrue(resource.getVendorRelease().equals(vendorRelease));
381                 assertTrue(resource.getCreatorUserId().equals(AttContact));
382                 assertEquals(type.substring(0, index), resource.getResourceType());
383
384                 for (int i = 0; i < tags.size(); i++) {
385                         assertEquals(resource.getTags().get(i), tags.get(i).getText());
386                 }
387         }
388
389         public static void getGeneralInfo(ResourceReqDetails resource, User user) {
390
391                 // clickMore();
392                 // String
393                 // componentType=waitFunctionForaGetElements("componentType",3).getText();
394                 // String version=waitFunctionForaGetElements("version",3).getText();
395                 // String
396                 // category=waitFunctionForaGetElements("category",3).getText();//get
397                 // right panel Category.
398                 // String
399                 // resourceType=waitFunctionForaGetElements("resourceType",3).getText();//get
400                 // right panel SubCategory.
401                 // String date=waitfunctionforelements("creationDate",3).getText();
402                 // String aouthor=waitfunctionforallelements("author'",3).getText();
403                 // String
404                 // vendorName=waitFunctionForaGetElements("vendorName",3).getText();
405                 // String
406                 // vendorRelease=waitFunctionForaGetElements("vendorRelease",3).getText();
407                 // String
408                 // AttContact=waitFunctionForaGetElements("attContact",3).getText();
409                 // String
410                 // Description=waitFunctionForaGetElements("description",3).getText();
411                 List<WebElement> tags = GeneralUIUtils.getWebElementsListByTestID("tag");
412                 // // String TagVF=waitFunctionForaGetElements("tag",3).getText();
413                 // assertTrue(componentType.equals("RESOURCE"));
414                 // assertTrue(version.equals(resource.getVersion()));
415                 // assertTrue(category.equals(resource.getCategories().get(0).getName()));
416                 // assertEquals(resourceType,resource.getResourceType());
417                 // // assertEquals(Date,resource.getCreationDate());
418                 // // assertEquals(Aouthor,resource.getCreatorFullName());
419                 // assertTrue(vendorName.equals(resource.getVendorName()));
420                 // assertTrue(vendorRelease.equals(resource.getVendorRelease()));
421                 // assertTrue(AttContact.equals(resource.getAttContact()));
422                 // assertTrue(Description.equals(resource.getDescription()+"\nLess"));
423                 for (WebElement tag : tags) {
424                         System.out.println(resource.getTags().get(0));
425                 }
426         }
427
428         public static void getGeneralInfoForTags(ResourceReqDetails resource, User user) {
429
430                 clickMore();
431                 String componentType = waitFunctionForaGetElements("componentType", 3).getText();
432                 String version = waitFunctionForaGetElements("version", 3).getText();
433                 String category = waitFunctionForaGetElements("category", 3).getText();// get
434                                                                                                                                                                 // right
435                                                                                                                                                                 // panel
436                                                                                                                                                                 // Category.
437                 String resourceType = waitFunctionForaGetElements("resourceType", 3).getText();// get
438                                                                                                                                                                                 // right
439                                                                                                                                                                                 // panel
440                                                                                                                                                                                 // SubCategory.
441                 String date = GeneralUIUtils.getWebElementByClassName("creationDate").getText();
442                 String aouthor = waitfunctionforallelements("author'").getText();
443                 String vendorName = waitFunctionForaGetElements("vendorName", 3).getText();
444                 String vendorRelease = waitFunctionForaGetElements("vendorRelease", 3).getText();
445                 String attContact = waitFunctionForaGetElements("attContact", 3).getText();
446                 String description = waitFunctionForaGetElements("description", 3).getText();
447                 List<WebElement> tags = GeneralUIUtils.getWebElementsListByTestID("tag");
448                 assertTrue(componentType.equals("RESOURCE"));
449                 assertTrue(version.equals(resource.getVersion()));
450                 assertTrue(category.equals(resource.getCategories().get(0).getName()));
451                 assertEquals(resourceType, resource.getResourceType());
452                 // assertEquals(Date,resource.getCreationDate());
453                 // assertEquals(Aouthor,resource.getCreatorFullName());
454                 assertTrue(vendorName.equals(resource.getVendorName()));
455                 assertTrue(vendorRelease.equals(resource.getVendorRelease()));
456                 assertTrue(attContact.equals(resource.getContactId()));
457                 assertTrue(description.equals(resource.getDescription() + "\nLess"));
458                 assertTrue(tags.equals("Tag-150"));
459         }
460
461         public static WebElement searchVFNameInWorkspace(ResourceReqDetails resource, User user) throws Exception {
462
463                 List<WebElement> findElements = GeneralUIUtils.getDriver()
464                                 .findElements(By.xpath("//div[@data-tests-id='" + resource.getUniqueId() + "']"));
465                 assertNotNull("did not find any elements", findElements);
466                 for (WebElement webElement : findElements) {
467                         if (webElement.getText().contains(resource.getUniqueId())) {
468                                 System.out.println("I find it");
469                                 return webElement;
470                         }
471                 }
472                 return null;
473         }
474
475         public static Boolean searchCheckOutWorkspace(ResourceReqDetails resource, User user,
476                         CheckBoxStatusEnum checkBoxStatusEnum) throws Exception {
477
478                 List<WebElement> findElements = GeneralUIUtils.getDriver()
479                                 .findElements(By.xpath("//div[@data-tests-id='component.lifecycleState']"));
480                 assertNotNull("did not find any elements", findElements);
481                 for (WebElement webElement : findElements) {
482                         if (!webElement.getAttribute("class").contains(checkBoxStatusEnum.name())) {
483                                 return false;
484                         }
485                 }
486                 return true;
487         }
488
489         // coded by tedy.
490         public static void validateWithRightPalett(ResourceReqDetails resource, User user) {
491                 // String
492                 // Type=Waitfunctionforallelements("sharingService.selectedEntity.getTypeForView()",3).getText();
493                 String ResourceType = waitfunctionforallelements("selectedComponent.resourceType").getText();
494                 System.out.println(ResourceType);
495                 String Version = waitfunctionforallelements("selectedComponent.version").getText();
496                 String Category = waitfunctionforallelements("selectedComponent.categories[0].name").getText();// get
497                                                                                                                                                                                                                 // right
498                                                                                                                                                                                                                 // panel
499                                                                                                                                                                                                                 // Category.
500                 String CanvasSubCategory = waitfunctionforallelements("selectedComponent.categories[0].subcategories[0].name")
501                                 .getText();// get right panel SubCategory.
502                 // String Date=Waitfunctionforelements("selectedComponent.creationDate |
503                 // date: 'MM/dd/yyyy'").getText();
504                 // String
505                 // Aouthor=waitfunctionforallelements("selectedComponent.creatorFullName'").getText();
506                 String VendorName = waitfunctionforallelements("selectedComponent.vendorName").getText();
507                 String VendorRelease = waitfunctionforallelements("selectedComponent.vendorRelease").getText();
508                 String AttContact = waitfunctionforallelements("selectedComponent.attContact").getText();
509                 String Description = waitfunctionforallelements("selectedComponent.description").getText();
510                 String TagVF = waitfunctionforallelements("tag").getText();
511                 AssertJUnit.assertEquals(ResourceType, resource.getResourceType());
512                 AssertJUnit.assertEquals(Version, resource.getVersion());
513                 AssertJUnit.assertEquals(Category, resource.getCategories().get(0).getName());
514                 AssertJUnit.assertEquals(CanvasSubCategory,
515                                 resource.getCategories().get(0).getSubcategories().get(0).getName());
516                 // assertEquals(Date,resource.getCreationDate());
517                 // assertEquals(Aouthor,resource.getCreatorFullName());
518                 AssertJUnit.assertEquals(VendorName, resource.getVendorName());
519                 AssertJUnit.assertEquals(VendorRelease, resource.getVendorRelease());
520                 AssertJUnit.assertEquals(AttContact, resource.getContactId());
521                 AssertJUnit.assertEquals(Description, resource.getDescription() + "\nLess");
522                 AssertJUnit.assertEquals(TagVF, "qa123");
523         }
524
525         public static void clickMore() {
526                 WebElement clickButtonSubmit = GeneralUIUtils.getDriver()
527                                 .findElement(By.className("ellipsis-directive-more-less"));
528                 clickButtonSubmit.click();
529         }
530         
531         public static RestResponse createResourceInUI(ResourceReqDetails resource, User user)
532                         throws Exception, AWTException {
533                 System.out.println("creating resource...");
534                 fillNewResourceValues(resource, user);
535                 RestResponse getCreatedResource = RestCDUtils.getResource(resource, user);
536                 AssertJUnit.assertEquals("Did not succeed to get any resource", HttpStatus.SC_OK,
537                                 getCreatedResource.getErrorCode().intValue());
538
539                 return getCreatedResource;
540         }
541
542         public static  void createResource(ResourceReqDetails resource, User user) throws Exception {
543                 ExtentTestActions.log(Status.INFO, "Going to create a new VF.");
544                 WebElement addVFButton = null;
545         try {
546                         GeneralUIUtils.ultimateWait();
547                         try{
548                                 GeneralUIUtils.hoverOnAreaByClassName("w-sdc-dashboard-card-new");
549                                 addVFButton = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.Dashboard.BUTTON_ADD_VF.getValue());
550                         }
551                         catch (Exception e){
552                                 File imageFilePath = GeneralUIUtils.takeScreenshot(null, SetupCDTest.getScreenshotFolder(), "Warning_" + resource.getName());
553                                 final String absolutePath = new File(SetupCDTest.getReportFolder()).toURI().relativize(imageFilePath.toURI()).getPath();
554                                 SetupCDTest.getExtendTest().log(Status.WARNING, "Add VF button is not visible after hover on import area of Home page, moving on ..." + SetupCDTest.getExtendTest().addScreenCaptureFromPath(absolutePath));
555                                 showButtonsADD();
556                                 addVFButton = GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.Dashboard.BUTTON_ADD_VF.getValue());
557                         }
558                         addVFButton.click();
559                                 GeneralUIUtils.ultimateWait();
560                 } 
561         catch (Exception e ) {
562                 SetupCDTest.getExtendTest().log(Status.WARNING, String.format("Exeption catched on ADD VF button, retrying ... "));
563                 GeneralUIUtils.hoverOnAreaByClassName("w-sdc-dashboard-card-new");
564                         GeneralUIUtils.ultimateWait();
565                         GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.Dashboard.BUTTON_ADD_VF.getValue()).click();
566                         GeneralUIUtils.ultimateWait();
567         }
568                 fillResourceGeneralInformationPage(resource, user, true);
569                 resource.setVersion("0.1");
570                 GeneralPageElements.clickCreateButton();
571         }
572         
573         public static void updateResource(ResourceReqDetails resource, User user){
574                 ResourceGeneralPage.defineContactId(resource.getContactId());
575                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Updating General screen fields ..."));
576                 fillResourceGeneralInformationPage(resource, user, false);
577                 ResourceGeneralPage.clickUpdateButton();
578         }
579         
580         
581
582         public static RestResponse updateResourceInformationPage(ResourceReqDetails resource, User user)
583                         throws Exception, AWTException {
584
585                 fillResourceGeneralInformationPage(resource, user, true);
586                 GeneralPageElements.clickCreateButton();
587                 return null;
588
589         }
590
591         public static RestResponse checkInResourceInUI(ResourceReqDetails resource, User user) throws Exception {
592
593                 WebElement ASDCLink = GeneralUIUtils.getDriver().findElement(By.className("w-sdc-header-logo-link"));
594                 ASDCLink.click();
595                 Thread.sleep(2000);
596
597                 List<WebElement> listFormInput = GeneralUIUtils.getDriver()
598                                 .findElements(By.className("i-sdc-left-sidebar-nav-item"));
599                 WebElement addPropertyElement = listFormInput.get(0);
600                 addPropertyElement.click();
601                 Thread.sleep(2000);
602
603                 WebElement searchResource = GeneralUIUtils.getDriver()
604                                 .findElement(By.className("w-sdc-header-catalog-search-input"));
605                 searchResource.sendKeys("newresource4test");
606
607                 Thread.sleep(1000);
608
609                 WebElement buttonClickMenu = GeneralUIUtils.getDriver()
610                                 .findElement(By.className("w-sdc-dashboard-card-menu-button"));
611                 buttonClickMenu.click();
612
613                 WebElement clickMenu = GeneralUIUtils.getDriver().findElement(By.className("w-sdc-dashboard-card-menu"));
614                 clickMenu.click();
615
616                 List<WebElement> clickCheckIn = GeneralUIUtils.getDriver()
617                                 .findElements(By.className("i-sdc-dashboard-card-menu-item"));
618                 WebElement clickCheckInMenu = clickCheckIn.get(1);
619                 clickCheckInMenu.click();
620
621                 WebElement descriptionForSubmit = GeneralUIUtils.getDriver()
622                                 .findElement(By.className("w-sdc-modal-body-comment"));
623                 descriptionForSubmit.sendKeys("checkin resource");
624                 Thread.sleep(2000);
625                 WebElement clickButtonSubmitTwo = GeneralUIUtils.getDriver().findElement(By.className("w-sdc-btn-blue"));
626                 clickButtonSubmitTwo.click();
627                 Thread.sleep(2000);
628
629                 WebElement buttonClickMenu1 = GeneralUIUtils.getDriver()
630                                 .findElement(By.className("w-sdc-dashboard-card-menu-button"));
631                 buttonClickMenu1.click();
632
633                 WebElement clickMenu1 = GeneralUIUtils.getDriver().findElement(By.className("w-sdc-dashboard-card-menu"));
634                 clickMenu1.click();
635
636                 List<WebElement> clickCheckOut = GeneralUIUtils.getDriver()
637                                 .findElements(By.className("i-sdc-dashboard-card-menu-item"));
638                 WebElement clickCheckOutMenu = clickCheckOut.get(0);
639                 clickCheckOutMenu.click();
640
641                 Thread.sleep(3000);
642                 RestResponse getResource = RestCDUtils.getResource(resource, user);
643                 AssertJUnit.assertEquals("Did not succeed to get resource after create", 200,
644                                 getResource.getErrorCode().intValue());
645                 return getResource;
646
647         }
648
649         public static String lifeCycleStateUI() throws InterruptedException {
650                 return GeneralUIUtils.getWebElementByTestID("formlifecyclestate").getText();
651         }
652
653         public static List<String> catalogFilterResourceCategoriesChecBox(ResourceCategoriesNameEnum enumName)
654                         throws Exception {
655                 List<String> categories = Arrays.asList();
656                 switch (enumName) {
657                 case APPLICATIONL4:
658                         GeneralUIUtils.getWebElementByTestID(enumName.getValue()).click();
659                         categories = Arrays.asList("applicationServer", "defaulticon", "vl", "cp", "call_controll", "borderElement",
660                                         "network", "firewall", "database", "loadBalancer");
661                         break;
662                 case APPLICATION_SERVER:
663                         GeneralUIUtils.getWebElementByTestID(enumName.getValue()).click();
664                         categories = Arrays.asList("applicationServer", "vl", "cp", "defaulticon");
665                         break;
666                 case BORDER_ELEMENT:
667                         GeneralUIUtils.getWebElementByTestID(enumName.getValue()).click();
668                         categories = Arrays.asList("borderElement", "vl", "cp", "defaulticon");
669                         break;
670                 case CALL_CONTROL:
671                         GeneralUIUtils.getWebElementByTestID(enumName.getValue()).click();
672                         categories = Arrays.asList("call_controll", "vl", "cp", "defaulticon");
673                         break;
674                 case COMMON_NETWORK_RESOURCES:
675                         GeneralUIUtils.getWebElementByLinkText("Common Network Resources").click();
676                         categories = Arrays.asList("network", "vl", "cp", "defaulticon");
677                         break;
678                 case CONNECTION_POINTS:
679                         GeneralUIUtils.getWebElementByTestID(enumName.getValue()).click();
680                         categories = Arrays.asList("cp", "defaulticon");
681                         break;
682                 case DATABASE:
683                         GeneralUIUtils.getWebElementByTestID(enumName.getValue()).click();
684                         categories = Arrays.asList("database", "vl", "cp", "defaulticon");
685                         break;
686                 case DATABASE_GENERIC:
687                         GeneralUIUtils.getWebElementByTestID(enumName.getValue()).click();
688                         categories = Arrays.asList("database", "vl", "cp", "defaulticon");
689                         break;
690                 case FIREWALL:
691                         GeneralUIUtils.getWebElementByTestID(enumName.getValue()).click();
692                         categories = Arrays.asList("firewall", "vl", "cp", "defaulticon");
693                         break;
694                 case GATEWAY:
695                         GeneralUIUtils.getWebElementByTestID(enumName.getValue()).click();
696                         categories = Arrays.asList("gateway", "vl", "cp", "defaulticon");
697                         break;
698                 case INFRASTRUCTURE:
699                         GeneralUIUtils.getWebElementByTestID(enumName.getValue()).click();
700                         categories = Arrays.asList("connector", "vl", "cp", "defaulticon");
701                         break;
702                 case INFRASTRUCTUREL23:
703                         GeneralUIUtils.getWebElementByTestID(enumName.getValue()).click();
704                         categories = Arrays.asList("ucpe", "vl", "cp", "defaulticon");
705                         break;
706                 case LAN_CONNECTORS:
707                         GeneralUIUtils.getWebElementByTestID(enumName.getValue()).click();
708                         categories = Arrays.asList("network", "port", "connector", "vl", "cp", "defaulticon");
709                         break;
710                 case LOAD_BALANCER:
711                         GeneralUIUtils.getWebElementByTestID(enumName.getValue()).click();
712                         categories = Arrays.asList("loadBalancer", "vl", "cp", "defaulticon");
713                         break;
714                 case MEDIA_SERVERS:
715                         GeneralUIUtils.getWebElementByTestID(enumName.getValue()).click();
716                         categories = Arrays.asList("network", "vl", "cp", "defaulticon");
717                         break;
718                 case NETWORKL4:
719                         GeneralUIUtils.getWebElementByTestID(enumName.getValue()).click();
720                         categories = Arrays.asList("network", "vl", "cp", "defaulticon");
721                         break;
722                 case NETWORK_ELEMENTS:
723                         GeneralUIUtils.getWebElementByTestID(enumName.getValue()).click();
724                         categories = Arrays.asList("port", "defaulticon", "network", "connector", "vl", "cp");
725                         break;
726                 case NETWORK_L23:
727                         GeneralUIUtils.getWebElementByTestID(enumName.getValue()).click();
728                         categories = Arrays.asList("network", "vl", "defaulticon", "cp", "router", "port", "connector", "gateway",
729                                         "ucpe");
730                         break;
731                 case NETWORK_CONNECTIVITY:
732                         GeneralUIUtils.getWebElementByTestID(enumName.getValue()).click();
733                         categories = Arrays.asList("network", "vl", "cp", "defaulticon");
734                         break;
735                 case GENERIC:
736                         GeneralUIUtils.getWebElementByTestID(enumName.getValue()).click();
737                         categories = Arrays.asList("database", "port", "loadBalancer", "vl", "cp", "objectStorage", "compute",
738                                         "defaulticon", "ucpe", "network", "connector");
739                         break;
740                 case ABSTRACT:
741                         GeneralUIUtils.getWebElementByTestID(enumName.getValue()).click();
742                         categories = Arrays.asList("objectStorage", "compute", "defaulticon", "cp", "vl");
743                         break;
744                 case Router:
745                         GeneralUIUtils.getWebElementByTestID(enumName.getValue()).click();
746                         categories = Arrays.asList("router", "vl", "cp", "defaulticon");
747                         break;
748                 case VIRTUAL_LINKS:
749                         GeneralUIUtils.getWebElementByTestID(enumName.getValue()).click();
750                         categories = Arrays.asList("vl", "defaulticon");
751                         break;
752                 case WAN_Connectors:
753                         GeneralUIUtils.getWebElementByTestID(enumName.getValue()).click();
754                         categories = Arrays.asList("network", "port", "connector", "vl", "cp", "defaulticon");
755                         break;
756                 case WEB_SERVER:
757                         GeneralUIUtils.getWebElementByTestID(enumName.getValue()).click();
758                         categories = Arrays.asList("applicationServer", "vl", "cp", "defaulticon");
759                         break;
760                 }
761                 return categories;
762         }
763
764         public static void deleteVersionInUI() throws Exception {
765
766                 waitToDeleteVersion().click();
767                 ResourceUIUtils.clickButtonBlue();
768         }
769
770         public static void selectTabInRightPallete(String className) throws Exception {
771                 WebElement tab = GeneralUIUtils.getWebElementByClassName(className);
772                 tab.click();
773         }
774
775         public static WebElement waitToDeleteVersion() {
776                 return Waitfunctionforbuttons("//*[@data-tests-id='deleteVersion']", 10);
777         }
778
779         public static WebElement rihtPanelAPI() {
780                 return waitFunctionForaGetElements("tab-api", 10);
781         }
782
783         /**
784          * Click on HTML element.
785          * 
786          * @param dataTestId
787          * @throws Exception
788          */
789         public static void getWebElementByTestID(String dataTestId) throws Exception {
790                 WebDriverWait wait = new WebDriverWait(GeneralUIUtils.getDriver(), 20);
791                 WebElement element = wait
792                                 .until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@data-tests-id='" + dataTestId + "']")));
793                 element.click();
794                 // wait.until(ExpectedConditions.elemetto)
795                 // WebElement serviceButton =
796                 // GeneralUIUtils.getDriver().findElement(By.xpath("//*[@data-tests-id='"
797                 // + dataTestId + "']"));
798                 // serviceButton.
799                 // serviceButton.click();
800         }
801
802         /**
803          * Move to HTML element by class name. When moving to the HTML element, it
804          * will raise hover event.
805          * 
806          * @param className
807          */
808 //      public static void moveToHTMLElementByClassName(String className) {
809 //              Actions actions = new Actions(GeneralUIUtils.getDriver());
810 //              final WebElement createButtonsArea = GeneralUIUtils
811 //                              .retryMethodOnException(() -> GeneralUIUtils.getDriver().findElement(By.className(className)));
812 //              actions.moveToElement(createButtonsArea).perform();
813 //      }
814
815         /**
816          * Move to HTML element by element id. When moving to the HTML element, it
817          * will raise hover event.
818          * 
819          * @param className
820          */
821 //      static void moveToHTMLElementByDataTestId(String dataTestId) {
822 //              // WebElement hoverArea =
823 //              // GeneralUIUtils.getDriver().findElement(By.xpath("//*[@data-tests-id='"
824 //              // + dataTestId + "']"));
825 //              WebElement hoverArea = GeneralUIUtils.waitForElementVisibility(dataTestId);
826 //              // WebDriverWait wait = new WebDriverWait(GeneralUIUtils.getDriver(),
827 //              // 30);
828 //              // wait.until(ExpectedConditions.visibilityOf(hoverArea));
829 //
830 //              Actions actions = new Actions(GeneralUIUtils.getDriver());
831 //              actions.moveToElement(hoverArea).perform();
832 //      }
833
834         // public static ResourceReqDetails createResourceInUI(User user){
835         // try{
836         // ResourceReqDetails defineResourceDetails =
837         // defineResourceDetails(ResourceTypeEnum.VF);
838         // ResourceUIUtils.moveToHTMLElementByClassName("w-sdc-dashboard-card-new");
839         // ResourceUIUtils.getWebElementByTestID(DataTestIdEnum.Dashboard.BUTTON_ADD_VF.getValue());
840         // GeneralUIUtils.waitForLoader();
841         //// GeneralUIUtils.sleep(1000);
842         // fillResourceGeneralInformationPage(defineResourceDetails, user);
843         // GeneralPageElements.clickCreateButton();
844         // return defineResourceDetails;
845         // }
846         // catch( Exception e){
847         // throw new RuntimeException(e);
848         // }
849         // }
850
851         /**
852          * Import VFC
853          * 
854          * @param user
855          * @param filePath
856          * @param fileName
857          * @return
858          * @throws Exception
859          */
860
861         public static void importVfc(ResourceReqDetails resourceMetaData, String filePath, String fileName, User user)
862                         throws Exception {
863                 GeneralUIUtils.ultimateWait();
864                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Creating new VFC resource ", resourceMetaData.getName()));
865                 GeneralUIUtils.hoverOnAreaByTestId(Dashboard.IMPORT_AREA.getValue());
866                 GeneralUIUtils.ultimateWait();
867                 // Insert file to the browse dialog             
868                 WebElement buttonVFC = GeneralUIUtils.findByText("Import VFC");
869                 WebElement fileInputElement = GeneralUIUtils.getInputElement(DataTestIdEnum.Dashboard.IMPORT_VFC_FILE.getValue());
870                 if (!buttonVFC.isDisplayed()){
871                         File imageFilePath = GeneralUIUtils.takeScreenshot(null, SetupCDTest.getScreenshotFolder(), "Warning_" + resourceMetaData.getName());
872                         final String absolutePath = new File(SetupCDTest.getReportFolder()).toURI().relativize(imageFilePath.toURI()).getPath();
873                         SetupCDTest.getExtendTest().log(Status.WARNING, "VFC button not visible after hover on import area of Home page, moving on ..." + SetupCDTest.getExtendTest().addScreenCaptureFromPath(absolutePath));                  
874                 }
875                 try{
876                         fileInputElement.sendKeys(filePath + fileName);
877                 } catch (ElementNotVisibleException e) {
878                         SetupCDTest.getExtendTest().log(Status.WARNING, String.format("Exeption catched on file input, converting VFC file input to visible"));
879                         showButtons();
880                         fileInputElement.sendKeys(filePath + fileName);
881                 } 
882                 // Fill the general page fields.
883                 GeneralUIUtils.ultimateWait();
884                 fillResourceGeneralInformationPage(resourceMetaData, user, true);
885                 GeneralPageElements.clickCreateButton();
886         }
887         
888         public static void importVfcNoCreate(ResourceReqDetails resourceMetaData, String filePath, String fileName, User user)
889                         throws Exception {
890                 GeneralUIUtils.hoverOnAreaByTestId(Dashboard.IMPORT_AREA.getValue());
891                 // Insert file to the browse dialog
892                 WebElement buttonVFC = GeneralUIUtils.findByText("Import VFC");
893                 WebElement fileInputElement = GeneralUIUtils.getInputElement(DataTestIdEnum.Dashboard.IMPORT_VFC_FILE.getValue());
894                 if (!buttonVFC.isDisplayed()){
895                         File imageFilePath = GeneralUIUtils.takeScreenshot(null, SetupCDTest.getScreenshotFolder(), "Warning_" + resourceMetaData.getName());
896                         final String absolutePath = new File(SetupCDTest.getReportFolder()).toURI().relativize(imageFilePath.toURI()).getPath();
897                         SetupCDTest.getExtendTest().log(Status.WARNING, "VFC button not visible after hover on import area of Home page, moving on ..." + SetupCDTest.getExtendTest().addScreenCaptureFromPath(absolutePath));                  
898                 }
899                 try{
900                         fileInputElement.sendKeys(filePath + fileName);
901                 } catch (ElementNotVisibleException e) {
902                         SetupCDTest.getExtendTest().log(Status.WARNING, String.format("Exeption catched on file input, converting VFC file input to visible"));
903                         showButtons();
904                         fileInputElement.sendKeys(filePath + fileName);
905                 }
906                 // Fill the general page fields.
907                 GeneralUIUtils.waitForLoader();
908                 fillResourceGeneralInformationPage(resourceMetaData, user, true);
909         }
910         
911         
912         public static void importVfFromCsar(ResourceReqDetails resourceMetaData, String filePath, String fileName, User user)
913                         throws Exception {
914                 GeneralUIUtils.ultimateWait();
915                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Creating new VF asset resource %s", resourceMetaData.getName()));  
916                 GeneralUIUtils.hoverOnAreaByTestId(Dashboard.IMPORT_AREA.getValue());
917                 GeneralUIUtils.ultimateWait();
918                 // Insert file to the browse dialog     
919                 WebElement buttonDCAE = GeneralUIUtils.findByText("Import DCAE asset");
920                 WebElement fileInputElement = GeneralUIUtils.getInputElement(DataTestIdEnum.Dashboard.IMPORT_VF_FILE.getValue());
921                 if (!buttonDCAE.isDisplayed()){
922                         File imageFilePath = GeneralUIUtils.takeScreenshot(null, SetupCDTest.getScreenshotFolder(), "Warning_" + resourceMetaData.getName());
923                         final String absolutePath = new File(SetupCDTest.getReportFolder()).toURI().relativize(imageFilePath.toURI()).getPath();
924                         SetupCDTest.getExtendTest().log(Status.WARNING, "DCAE button not visible after hover on import area of Home page, moving on ..." + SetupCDTest.getExtendTest().addScreenCaptureFromPath(absolutePath));                 
925                 }
926                 try{
927                         fileInputElement.sendKeys(filePath + fileName);
928                 } catch (ElementNotVisibleException e) {
929                         SetupCDTest.getExtendTest().log(Status.WARNING, String.format("Exeption catched on file input, converting DCAE file input to visible"));
930                         showButtons();
931                         fileInputElement.sendKeys(filePath + fileName);
932                 }    
933                 // Fill the general page fields.
934                 GeneralUIUtils.ultimateWait();
935                 fillResourceGeneralInformationPage(resourceMetaData, user, true);
936                 GeneralPageElements.clickCreateButton(10*60);
937 //              GeneralUIUtils.ultimateWait(); "don't change import of csar can take longer then 3 minutes"
938                 GeneralUIUtils.waitForLoader(10*60);
939         }
940         
941         public static void importVfFromCsarNoCreate(ResourceReqDetails resourceMetaData, String filePath, String fileName, User user)
942                         throws Exception {
943                 GeneralUIUtils.ultimateWait();
944                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Creating new VF asset resource %s, Create button will not be clicked", resourceMetaData.getName()));  
945                 GeneralUIUtils.hoverOnAreaByTestId(Dashboard.IMPORT_AREA.getValue());
946                 GeneralUIUtils.ultimateWait();
947                 // Insert file to the browse dialog
948                 WebElement buttonDCAE = GeneralUIUtils.findByText("Import DCAE asset");
949                 WebElement fileInputElement = GeneralUIUtils.getInputElement(DataTestIdEnum.Dashboard.IMPORT_VF_FILE.getValue());
950                 if (!buttonDCAE.isDisplayed()){
951                         File imageFilePath = GeneralUIUtils.takeScreenshot(null, SetupCDTest.getScreenshotFolder(), "Warning_" + resourceMetaData.getName());
952                         final String absolutePath = new File(SetupCDTest.getReportFolder()).toURI().relativize(imageFilePath.toURI()).getPath();
953                         SetupCDTest.getExtendTest().log(Status.WARNING, "DCAE button not visible after hover on import area of Home page, moving on ..." + SetupCDTest.getExtendTest().addScreenCaptureFromPath(absolutePath));
954                 }
955                 try{
956                         fileInputElement.sendKeys(filePath + fileName);
957                 } catch (ElementNotVisibleException e) {
958                         SetupCDTest.getExtendTest().log(Status.WARNING, String.format("Exeption catched on file input, converting DCAE file input to visible"));
959                         showButtons();
960                         fileInputElement.sendKeys(filePath + fileName);
961                 }
962                 // Fill the general page fields.
963                 GeneralUIUtils.ultimateWait();
964                 fillResourceGeneralInformationPage(resourceMetaData, user, true);
965                 GeneralUIUtils.waitForLoader(10*60);
966         }
967         
968         public static void updateVfWithCsar(String filePath, String fileName) {
969                 ExtentTestActions.log(Status.INFO, "Updating VF with updated CSAR file named " + fileName);
970                 WebElement browseWebElement = GeneralUIUtils.getInputElement(DataTestIdEnum.GeneralElementsEnum.UPLOAD_FILE_INPUT.getValue());
971                 browseWebElement.sendKeys(filePath + fileName);
972                 GeneralUIUtils.ultimateWait();
973                 GeneralPageElements.clickUpdateButton();
974                 GeneralUIUtils.waitForLoader();
975                 ExtentTestActions.log(Status.INFO, "VF is updated.");
976         }
977         
978         
979
980         // public static ResourceReqDetails importVfcInUI(User user, String
981         // filePath, String fileName, ResourceTypeEnum resourceType) {
982         // ResourceReqDetails defineResourceDetails =
983         // defineResourceDetails(resourceType);
984         // ResourceUIUtils.moveToHTMLElementByDataTestId(Dashboard.IMPORT_AREA.getValue());
985         //
986         // // Insert file to the browse dialog
987         // final WebElement browseWebElement =
988         // GeneralUIUtils.getWebElementByDataTestId(DataTestIdEnum.Dashboard.IMPORT_VFC_FILE.getValue());
989         // browseWebElement.sendKeys(filePath + fileName);
990         //
991         // // Fill the general page fields.
992         // GeneralUIUtils.waitForLoader();
993         // fillResourceGeneralInformationPage(defineResourceDetails, user);
994         // GeneralPageElements.clickCreateButton();
995         // return defineResourceDetails;
996         // }
997
998         /**
999          * Import VF
1000          * 
1001          * @param user
1002          * @param filePath
1003          * @param fileName
1004          * @return
1005          * @throws Exception
1006          */
1007         // public static ResourceReqDetails importVfInUI(User user, String filePath,
1008         // String fileName) throws Exception {
1009         // ResourceReqDetails defineResourceDetails =
1010         // defineResourceDetails(ResourceTypeEnum.VF);
1011         // ResourceUIUtils.moveToHTMLElementByDataTestId(Dashboard.IMPORT_AREA.getValue());
1012         //
1013         // // Insert file to the browse dialog
1014         // final WebElement browseWebElement =
1015         // GeneralUIUtils.getWebElementByDataTestId(DataTestIdEnum.Dashboard.IMPORT_VF_FILE.getValue());
1016         // browseWebElement.sendKeys(filePath + fileName);
1017         //
1018         // // Fill the general page fields.
1019         // GeneralUIUtils.waitForLoader();
1020         // fillResourceGeneralInformationPage(defineResourceDetails, user);
1021         // GeneralPageElements.clickCreateButton();
1022         // return defineResourceDetails;
1023         // }
1024
1025         // public static ResourceReqDetails defineResourceDetails(ResourceTypeEnum
1026         // resourceType) {
1027         // ResourceReqDetails resource = new ResourceReqDetails();
1028         // resource = ElementFactory.getDefaultResource(NormativeTypesEnum.ROOT,
1029         // ResourceCategoryEnum.APPLICATION_L4_CALL_CONTROL);
1030         // resource.setVersion(INITIAL_VERSION);
1031         // resource.setIcon(ICON_RESOURCE_NAME);
1032         // resource.setResourceType(resourceType.toString());
1033         // resource.setName(getRandomComponentName(RESOURCE_NAME_PREFIX));
1034         //
1035         // SetupCDTest.setCreatedComponents(Arrays.asList(resource));
1036         //
1037         // return resource;
1038         // }
1039
1040         protected static String getRandomComponentName(String prefix) {
1041                 return prefix + new Random().nextInt(10000);
1042         }
1043
1044         public static ImmutablePair<String, String> getFirstRIPos(ResourceReqDetails createResourceInUI, User user) {
1045                 String responseAfterDrag = RestCDUtils.getResource(createResourceInUI, user).getResponse();
1046                 JSONObject jsonResource = (JSONObject) JSONValue.parse(responseAfterDrag);
1047                 String xPosPostDrag = (String) ((JSONObject) ((JSONArray) jsonResource.get("componentInstances")).get(0))
1048                                 .get("posX");
1049                 String yPosPostDrag = (String) ((JSONObject) ((JSONArray) jsonResource.get("componentInstances")).get(0))
1050                                 .get("posY");
1051                 return new ImmutablePair<String, String>(xPosPostDrag, yPosPostDrag);
1052
1053         }
1054
1055         public static WebElement getErrorMessageText(WebDriver driver, String text) throws Exception {
1056
1057                 return GeneralUIUtils.getWebElementByClassName(text);
1058
1059         }
1060
1061         public static void fillGeneralInfoValuesAndIcon(ResourceReqDetails resource, User user) throws Exception {
1062                 fillResourceGeneralInformationPage(resource, user, true);
1063                 
1064                 GeneralPageElements.clickCreateButton();
1065
1066                 selectRandomResourceIcon();
1067         }
1068
1069         // coded by teddy.
1070         public static void getVFCGeneralInfoAndValidate(ResourceReqDetails resource, User user)
1071                         throws InterruptedException {
1072                 Thread.sleep(2000);
1073                 WebDriver driver = GeneralUIUtils.getDriver();
1074                 String version = GeneralUIUtils.getSelectList(null, "versionHeader").getFirstSelectedOption().getText();
1075                 String name = GeneralUIUtils.getWebElementByTestID( "name").getAttribute("value");
1076                 String description = GeneralUIUtils.getWebElementByTestID( "description").getAttribute("value");
1077                 String category = GeneralUIUtils.getSelectList(null, "selectGeneralCategory").getFirstSelectedOption()
1078                                 .getText();
1079                 String vendorName = GeneralUIUtils.getWebElementByTestID( "vendorName").getAttribute("value");
1080                 String vendorRelease = GeneralUIUtils.getWebElementByTestID( "vendorRelease").getAttribute("value");
1081                 List<WebElement> tags = GeneralUIUtils.getWebElementsListByTestID("i-sdc-tag-text");
1082                 String type = GeneralUIUtils.getWebElementsListByTestID("type").get(1).getText();
1083                 int index = type.lastIndexOf(":");
1084                 System.out.println(type.substring(0, index));
1085                 String AttContact = GeneralUIUtils.getWebElementByTestID( "attContact").getAttribute("value");
1086                 System.out.println(resource.getVersion());
1087                 assertTrue(resource.getVersion().equals(version.substring(1)));
1088                 assertTrue(resource.getName().equals(name));
1089                 assertTrue(resource.getDescription().equals(description));
1090                 System.out.println(resource.getVendorName());
1091                 System.out.println(resource.getVendorRelease());
1092                 assertTrue(resource.getCategories().get(0).getSubcategories().get(0).getName().equals(category));
1093                 assertTrue(resource.getVendorName().equals(vendorName));
1094                 assertTrue(resource.getVendorRelease().equals(vendorRelease));
1095                 assertTrue(resource.getCreatorUserId().equals(AttContact));
1096                 assertEquals(type.substring(0, index), resource.getResourceType());
1097
1098                 for (int i = 0; i < tags.size(); i++) {
1099                         assertEquals(resource.getTags().get(i), tags.get(i).getText());
1100                 }
1101         }
1102
1103         public static RestResponse createResourceNG(ResourceReqDetails resource, User user) throws Exception, AWTException {
1104
1105                 GeneralUIUtils.hoverOnAreaByTestId("w-sdc-dashboard-card-new");
1106                 ResourceUIUtils.getWebElementByTestID(DataTestIdEnum.Dashboard.BUTTON_ADD_VF.getValue());
1107                 fillResourceGeneralInformationPage(resource, user, true);
1108                 GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.LifeCyleChangeButtons.CREATE.getValue());
1109                 return null;
1110
1111         }
1112         
1113         public static void showButtons(){
1114                 String parentElementClassAttribute = "sdc-dashboard-import-element-container";
1115                 WebElement fileInputElementWithVisible = GeneralUIUtils.getDriver().findElement(By.className(parentElementClassAttribute));
1116                 GeneralUIUtils.unhideElement(fileInputElementWithVisible, parentElementClassAttribute);
1117                 GeneralUIUtils.ultimateWait();
1118                 SetupCDTest.getExtendTest().log(Status.WARNING, String.format("Input buttons now visible..."));
1119         }
1120         
1121         public static void showButtonsADD(){
1122                 try {
1123                         GeneralUIUtils.ultimateWait();
1124                         String parentElementClassAttribute = "sdc-dashboard-create-element-container";
1125                         WebElement fileInputElementWithVisible = GeneralUIUtils.getDriver().findElement(By.className(parentElementClassAttribute));
1126                         GeneralUIUtils.unhideElement(fileInputElementWithVisible, parentElementClassAttribute);
1127                         GeneralUIUtils.ultimateWait();
1128                 } catch (Exception e ){
1129                         GeneralUIUtils.ultimateWait();
1130                         String parentElementClassAttribute = "sdc-dashboard-create-element-container";
1131                         WebElement fileInputElementWithVisible = GeneralUIUtils.getDriver().findElement(By.className(parentElementClassAttribute));
1132                         GeneralUIUtils.unhideElement(fileInputElementWithVisible, parentElementClassAttribute);
1133                         GeneralUIUtils.ultimateWait();
1134                 }
1135                 SetupCDTest.getExtendTest().log(Status.WARNING, String.format("Input buttons now visible..."));
1136         }
1137         
1138         public static void clickOnElementByText(String textToClick, String customizationFoLog){
1139                 String customizationFoLogLocal = customizationFoLog != null ? customizationFoLog : "";
1140                 SetupCDTest.getExtendTest().log(Status.INFO, String.format("Clicking on %s %s", textToClick, customizationFoLogLocal));
1141                 GeneralUIUtils.clickOnElementByText(textToClick);
1142         }
1143 }