package org.kie.smoke.wb.selenium.model;

/*
 * Copyright 2015 JBoss Inc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * 
 *      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.
 */
import static org.kie.smoke.wb.selenium.util.ByUtil.xpath;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class PrimaryNavbar extends PageObject {

    private static final String TOP_MENU //Contains both the link to expand menu as well as menu item links
            = "//ul[contains(@class,'navbar-primary')] / li[contains(@class,'dropdown')] [a[contains(text(),'%s')]]";

    public PrimaryNavbar(WebDriver driver) {
        super(driver);
    }

    private WebElement openMenu(String menuTitle) {
        WebElement menu = driver.findElement(xpath(TOP_MENU, menuTitle));
        menu.findElement(By.tagName("a")).click();
        return menu;
    }

    private void navigateTo(String menuText, String itemText) {
        WebElement menu = openMenu(menuText);
        WebElement menuItem = menu.findElement(By.linkText(itemText));
        menuItem.click();
    }

    public void logout() {
        navigateTo("User:", "Log Out");
    }

    public void projectAuthoring() {
        navigateTo("Authoring", "Project Authoring");
    }

    //TODO all items to navigate to other perspectivesS
}

@@ -837,19 +837,19 @@
  String 
-TOP
+NAV
 _MENU //
@@ -934,67 +934,23 @@
  %22//
-ul%5Bcontains(@class,'navbar-primary')%5D / li%5Bcontains(
+nav//li%5B
 @class
-,
+=
 'dro
@@ -959,11 +959,9 @@
 own'
-)%5D 
+%5D
 %5Ba%5Bc
@@ -984,16 +984,192 @@
 %25s')%5D%5D%22;
+%0A    private static final By LOGOUT_MENU // Unlike other navbar menus this has no stable link text%0A            = By.cssSelector(%22li%5Btitle='Reset all Perspective layouts'%5D+li%22);
 %0A%0A    pu
@@ -1344,11 +1344,11 @@
 ath(
-TOP
+NAV
 _MEN
@@ -1463,63 +1463,19 @@
 oid 
-navigateTo(String menuText, String itemText) %7B%0A        
+selectItem(
 WebE
@@ -1484,35 +1484,39 @@
 ment
- menu =
  open
+ed
 Menu
-(menu
+, String item
 Text)
-;
+ %7B
 %0A   
@@ -1542,17 +1542,23 @@
 uItem = 
-m
+openedM
 enu.find
@@ -1661,26 +1661,133 @@
     
-navigateTo(%22User:%22
+WebElement menu = driver.findElement(LOGOUT_MENU);%0A        menu.findElement(By.tagName(%22a%22)).click();%0A        selectItem(menu
 , %22L
@@ -1852,30 +1852,72 @@
     
-navigateTo(%22Authoring%22
+WebElement menu = openMenu(%22Authoring%22);%0A        selectItem(menu
 , %22P

Fix selenium LoginIntegrationTest