package com.thoughtworks.selenium;

import junit.framework.*;

import org.openqa.selenium.server.*;
import org.openqa.selenium.server.browserlaunchers.*;

/**
 * A test of the Apache MyFaces JSF AJAX auto-suggest sandbox application at www.irian.at.
 *  
 * 
 *  @author danielf
 *
 */
public class ApacheMyFacesSuggestTest extends TestCase {

    DefaultSelenium selenium;
    
    protected void setUp() throws Exception {
    }
    
    public void testAJAXFirefox() throws Throwable {
        selenium = new DefaultSelenium("localhost", SeleniumServer.DEFAULT_PORT, "*firefox", "http://www.irian.at");
        selenium.start();
        ajaxTester();
    }
    
    public void testAJAXIExplore() throws Throwable {
        if (!WindowsUtils.thisIsWindows()) return;
        selenium = new DefaultSelenium("localhost", SeleniumServer.DEFAULT_PORT, "*iexplore", "http://www.irian.at");
        selenium.start();
        ajaxTester();
    }
    
    public void ajaxTester() throws Throwable {
        selenium.open("http://www.irian.at/myfaces-sandbox/inputSuggestAjax.jsf");
        assertTrue(selenium.isTextPresent("suggest"));
        String elementID = "document.forms[0].elements[2]";
            //"//input[@id='' and @type='text']";
        selenium.type(elementID, "foo");
        selenium.setCursorPosition(elementID, "-1");
        // DGF On Mozilla a keyPress is needed, and types a letter.
        // On IE6, a keyDown is needed, and no letter is typed. :-p
        // On firefox 1.0.6-1.5.0.1, keyPress needed, no letter typed;
        // On firefox 1.5.0.2 (and higher), keyPress needed, letter typed
        // That's due to Firefox bug 303713 https://bugzilla.mozilla.org/show_bug.cgi?id=303713
        
        String verificationText = "regexp:foox?1";
        selenium.keyDown(elementID, Integer.toString('x'));
        selenium.keyUp(elementID, Integer.toString('x'));
        Thread.sleep(2000);
        assertTrue(selenium.isTextPresent(verificationText));
    }
    
    public void tearDown() {
        if (selenium == null) return;
        selenium.stop();
    }
}

@@ -1027,869 +1027,404 @@
  %7B%0D%0A
-        selenium.open(%22http://www.irian.at/myfaces-sandbox/inputSuggestAjax.jsf%22);%0D%0A        assertTrue(selenium.isTextPresent(%22suggest%22));%0D%0A        String elementID = %22document.forms%5B0%5D.elements%5B2%5D%22;%0D%0A            //%22//input%5B@id='' and @type='text'%5D%22;%0D%0A        selenium.type(elementID, %22foo
+%09%09String inputId = %22ac4%22;%0D%0A%09%09String updateId = %22ac4update%22;%0D%0A%0D%0A        selenium.open(%22http://www.irian.at/selenium-server/tests/html/ajax/ajax_autocompleter2_test.html%22);%0D%0A%09%09selenium.keyPress(inputId, %22%5C%5C74
 %22);%0D%0A
-        selenium.setCursorPosition(elementID, %22-1
+%09%09Thread.sleep(500);%0D%0A%09%09selenium.keyPress(inputId, %22%5C%5C97
 %22);%0D%0A
-        // DGF On Mozilla a keyPress is needed, and types a letter.%0D%0A        // On IE6, a keyDown is needed, and no letter is typed. :-p%0D%0A        // On firefox 1.0.6-1.5.0.1, keyPress needed, no letter typed;%0D%0A        // On firefox 1.5.0.2 (and higher), keyPress needed, letter typed%0D%0A        // That's due to Firefox bug 303713 https://bugzilla.mozilla.org/show_bug.cgi?id=303713%0D%0A        %0D%0A        String verificationText = %22regexp:foox?1%22;%0D%0A        selenium.keyDown(elementID, Integer.toString('x'));%0D%0A        
+%09%09selenium.keyPress(inputId, %22%5C%5C110%22);%0D%0A%09%09Thread.sleep(500);%0D%0A%09%09assertEquals(%22Jane Agnews%22, selenium.getText(updateId));%0D%0A%09%09
 sele
@@ -1435,55 +1435,34 @@
 .key
-Up(elementID, Integer.toString('x'));%0D%0A        
+Press(inputId, %22%5C%5C9%22);%0D%0A%09%09
 Thre
@@ -1474,74 +1474,70 @@
 eep(
-20
+5
 00);%0D%0A
-        assertTrue(selenium.isTextPresent(verificationText
+%09%09assertEquals(%22Jane Agnews%22, selenium.getValue(inputId
 ));%0D
@@ -1540,34 +1540,27 @@
 ));%0D%0A    %7D%0D%0A
-    %0D%0A    
+%0D%0A%09
 public void 

change ajax test case of Java client driver, in order to make build faster. NOTE: you may need update local maven repository with latest version of Selenium-Core, otherwise the new test case may fail.