Q:

Is it possible to use Selenium 2 WebDriverWait with ColdFusion?

from http://seleniumhq.org/docs/03_webdriver.jsp it shows the following Java sample code
(new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
  public Boolean apply(WebDriver d) {
    return d.getTitle().toLowerCase().startsWith("cheese!");
  }
});

Is it possible to write the code above in CFML, maybe with help of CF10's dynamic proxy?
It would be awesome if we can get CF10's closure to work with the code sample above, but it doesn't seem like it'll work because of the expected Java interface and Java return type, am I correct?

A:

I am not sure which is the better option. But it is possible using a dynamic proxy. Just create a cfc that implements the ExpectedCondition interface:
component {
    public boolean function apply(Any d) {
        return d.getTitle().toLowerCase().startsWith("cheese!");
    } 
}

Then create an instance of the proxy and pass it into the constructor of WebDriverWait
<cfscript>
    driver = createObject("java", "org.openqa.selenium.firefox.FirefoxDriver").init();
    driver.get("http://www.google.com");

    by = createObject("java", "org.openqa.selenium.By");
    element = driver.findElement(By.name("q"));

    WriteDump("Page title is: "& driver.getTitle());

    element.sendKeys(["Cheese!"]);
    element.submit();

    conditionProxy = createDynamicProxy("test.ExpectedConditionProxy", ["org.openqa.selenium.support.ui.ExpectedCondition"]); 
    WebDriverWait = createObject("java", "org.openqa.selenium.support.ui.WebDriverWait");
    WebDriverWait.init(driver, 10).until( conditionProxy );
    WriteDump("Page title is: "& driver.getTitle());

    driver.quit();
</cfscript>

