org.openecomp.sdc.ci.tests.utilities.ResourceUIUtils.java Source code

Java tutorial

Introduction

Here is the source code for org.openecomp.sdc.ci.tests.utilities.ResourceUIUtils.java

Source

/*-
 * ============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;

    }
}