import java.io.File;

import junit.framework.TestCase;

import com.thoughtworks.selenium.BrowserLauncher;
import com.thoughtworks.selenium.CommandProcessor;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;
import com.thoughtworks.selenium.embedded.jetty.DirectoryStaticContentHandler;
import com.thoughtworks.selenium.embedded.jetty.JettyCommandProcessor;
import com.thoughtworks.selenium.launchers.WindowsIEBrowserLauncher;

/**
 * @author Darren Cotterill
 */
public class SeleniumDrivenTest extends TestCase {

    private Selenium selenium;
    private BrowserLauncher launcher;
    
    // This is the root of the web app to be tested. Under my 'web' directory I have
    // css / images / javascript / jsp / WEB-INF directories.
    // My Java source directory for the web-app is simply included in the classpath
    // when I run the test.
    private static final String WEB_APP_ROOT = "c:/darrensWorkspace/solcon/src/web";
    
    // This is the root of the Selenium browserbot directory - where you installed it.
    private static final String SELENIUM_BROWSERBOT_ROOT = "c:/darrensWorkspace/selenium-0.6.0-java/browser-bot/";
    
    public void setUp() {
        CommandProcessor processor = 
            new JettyCommandProcessor(new File(WEB_APP_ROOT), "selenium-driver", 
                new DirectoryStaticContentHandler(new File(SELENIUM_BROWSERBOT_ROOT)));

        launcher = new WindowsIEBrowserLauncher(); 
        selenium = new DefaultSelenium(processor, launcher);

        selenium.start();
    }
    
    public void testDefaultDrivenSeleniumShouldPass() {
        selenium.open("/TestLogin.do");
        selenium.type("macId", "21020797");
        selenium.clickAndWait("loginButton");
        selenium.verifyTextPresent("Loan summary");
    }

    public void testDefaultDrivenSeleniumShouldFail() {
        selenium.open("/TestLogin.do");
        selenium.type("macId", "21020797");
        selenium.clickAndWait("loginButton");
        selenium.verifyTextPresent("Loan summary");
        selenium.verifyTextPresent("text not there");
    }
    
    public void tearDown() {
        selenium.stop();
        //launcher.close();
    }
}
