/**
 * 
 */
package org.richfaces;

/**
 * @author asmirnov
 * 
 */
import static org.testng.Assert.*;

import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

import com.thoughtworks.selenium.DefaultSelenium;

public class SeleniumExampleTest

{
    private DefaultSelenium selenium;

    protected DefaultSelenium createSeleniumClient(String url, String browser){
	return new DefaultSelenium("localhost", 4444,
		browser, url);
    }
    @BeforeTest
    @Parameters({ "browser" })
    public void startSelenium(String browser){
	selenium = createSeleniumClient("http://localhost:8080/", browser);
	selenium.start();	
    }

    @Test
    public void testSomethingSimple() throws Exception {
	selenium.open("http://localhost:8080/seleniumTest/faces/test.xhtml");
	selenium.waitForPageToLoad("5000");

	//
	System.out.println("body [" + selenium.getHtmlSource() + "]");
	//
	// selenium.getEval("window.done=false;A4J.AJAX.AddListener(new
	// A4J.AJAX.Listener(function(){window.done=true}))");
	selenium.click("id=fff:lnk");
	selenium.waitForCondition(
		"selenium.browserbot.getCurrentWindow().done==true", "3000");
	System.out.println("ajax body [" + selenium.getHtmlSource() + "]");
	assertEquals("testOk", selenium.getText("id=fff:out"));

	// Test help link
    }
    /**
     * 
     */
    @AfterTest
    public void stopSelenium() {
	selenium.stop();
	selenium = null;
    }
}