package com.talend.component;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.openqa.selenium.By;
import org.openqa.selenium.NotFoundException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

import java.util.Iterator;

/**
 * SidePanel is used to easy access to WebElements of the react-talend-component SidePanel component.
 *
 */
public class SidePanel extends Component {

    private static final Logger LOGGER = LogManager.getLogger(SidePanel.class);

    static final String NAME = "SidePanel";

    static final String SELECTOR = ".tc-side-panel";

    static final String MENU_ITEMS_SELECTOR = ".tc-side-panel-list-item span";

    /**
     * SidePanel constructor
     *
     * @param driver Selenium WebDriver
     */
    SidePanel(WebDriver driver) {
        super(driver, NAME, SELECTOR);
    }

    /**
     * Get menu item from its label
     *
     * @param label item menu label
     * @return WebElement of menu item
     * @throws NotFoundException if no elements with this label are found
     */
    public WebElement getMenu(String label) throws NotFoundException {
        LOGGER.info(NAME + ".getMenu " + label);
        Iterator<WebElement> elements = this.getElement().findElements(By.cssSelector(MENU_ITEMS_SELECTOR)).iterator();
        while (elements.hasNext()) {
            WebElement el = elements.next();
            if (el.getText().equals(label)) {
                return el;
            }
        }
        throw new NotFoundException(label);
    }
}

@@ -704,24 +704,117 @@
 tem span%22;%0A%0A
+    static final String MENU_ITEM_ACTIVE_SELECTOR = %22.tc-side-panel-list-item.active span%22;%0A%0A
     /**%0A    
@@ -1649,11 +1649,332 @@
 );%0A    %7D
+%0A%0A    /**%0A     * Get current active menu item%0A     *%0A     * @return WebElement of menu item%0A     * @throws NotFoundException if no active element is find%0A     */%0A    public WebElement getActiveMenu() throws NotFoundException %7B%0A        return this.getElement().findElement(By.cssSelector(MENU_ITEM_ACTIVE_SELECTOR));%0A    %7D
 %0A%7D%0A

add new method to get active menu item (#372)