/*******************************************************************************
 * This file is part of OpenNMS(R).
 *
 * Copyright (C) 2011-2012 The OpenNMS Group, Inc.
 * OpenNMS(R) is Copyright (C) 1999-2012 The OpenNMS Group, Inc.
 *
 * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
 *
 * OpenNMS(R) is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published
 * by the Free Software Foundation, either version 3 of the License,
 * or (at your option) any later version.
 *
 * OpenNMS(R) is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with OpenNMS(R).  If not, see:
 *      http://www.gnu.org/licenses/
 *
 * For more information contact:
 *     OpenNMS(R) Licensing <license@opennms.org>
 *     http://www.opennms.org/
 *     http://www.opennms.com/
 *******************************************************************************/

package org.opennms.smoketest;

import org.junit.After;
import org.junit.Before;
import org.opennms.test.mock.MockLogAppender;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverBackedSelenium;
import org.openqa.selenium.firefox.FirefoxDriver;

import com.thoughtworks.selenium.SeleneseTestBase;

public class OpenNMSSeleniumTestCase extends SeleneseTestBase {

    protected static final String LOAD_TIMEOUT = "30000";

    @Before
    public void setUp() throws Exception {
        MockLogAppender.setupLogging(true, "DEBUG");

        // Google Chrome
        // System.setProperty("webdriver.chrome.driver", "/Users/ranger/Downloads/chromedriver");
        // WebDriver driver = new ChromeDriver();

        // Selenium remote server
        // DesiredCapabilities capability = DesiredCapabilities.firefox();
        // WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);

        // Firefox
        WebDriver driver = new FirefoxDriver();

        String baseUrl = "http://localhost:8980/";
        selenium = new WebDriverBackedSelenium(driver, baseUrl);
        selenium.open("/opennms/login.jsp");
        selenium.type("name=j_username", "admin");
        selenium.type("name=j_password", "admin");
        selenium.click("name=Login");
        waitForPageToLoad();
    }

    @After
    public void tearDown() throws Exception {
        selenium.stop();
    }

    protected void waitForPageToLoad() {
        selenium.waitForPageToLoad(LOAD_TIMEOUT);
    }

}

@@ -1211,16 +1211,38 @@
 etest;%0A%0A
+import java.io.File;%0A%0A
 import o
@@ -1418,16 +1418,64 @@
 lenium;%0A
+import org.openqa.selenium.chrome.ChromeDriver;%0A
 import o
@@ -1814,43 +1814,143 @@
     
-// Google Chrome%0A        //
+WebDriver driver = null;%0A%0A        // Google Chrome if chrome driver property is set%0A        final String chromeDriverLocation =
  System.
 setP
@@ -1945,17 +1945,17 @@
  System.
-s
+g
 etProper
@@ -1986,86 +1986,107 @@
 ver%22
-, %22/Users/ranger/Downloads/
+);%0A        if (
 chrome
-d
+D
 river
-%22);%0A        // WebDriver driver
+Location != null) %7B%0A            final File chromeDriverFile
  = new 
-C
+File(c
 hrom
@@ -2096,226 +2096,233 @@
 iver
-();%0A%0A        // Selenium remote server%0A        // DesiredCapabilities capability = DesiredCapabilities.firefox();%0A        // WebDriver driver = new RemoteWebDriver(new URL(%22http://localhost:4444/wd/hub%22), capability);%0A
+Location);%0A            if (chromeDriverFile.exists() && chromeDriverFile.canExecute()) %7B%0A                System.err.println(%22using chrome driver%22);%0A                driver = new ChromeDriver();%0A            %7D%0A        %7D%0A        
 %0A   
@@ -2328,16 +2328,27 @@
       //
+ otherwise,
  Firefox
@@ -2352,34 +2352,58 @@
 fox%0A        
-WebD
+if (d
 river 
+== null) %7B%0A            
 driver = new
@@ -2419,16 +2419,26 @@
 river();
+%0A        %7D
 %0A%0A      
@@ -2824,32 +2824,54 @@
 eption %7B%0A       
+ if (selenium != null)
  selenium.stop()

make the handling of the chrome driver a little nicer