package org.osiam.addons.administration.config;

import javax.annotation.PreDestroy;
import javax.inject.Inject;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.safari.SafariDriver;
import org.osiam.addons.administration.selenium.Browser;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * This configuration is responsible for creating a {@link Browser} instance.
 */
@Configuration
public class SeleniumFactory {

    @Inject
    private Browser browser;

    @Bean
    public Browser browser() {
        WebDriver driver;

        try {
            driver = new InternetExplorerDriver();
        } catch (Exception e) {
            try {
                driver = new SafariDriver();
            } catch (Exception e1) {
                try {
                    driver = new FirefoxDriver();
                } catch (Exception e2) {
                    driver = new HtmlUnitDriver(true);
                }
            }
        }

        Browser browser = new Browser(driver);
        return browser;
    }

    @PreDestroy
    void closeBrowser() {
        browser.quit();
    }
}

@@ -42,16 +42,55 @@
 onfig;%0A%0A
+import java.util.concurrent.TimeUnit;%0A%0A
 import j
@@ -1269,22 +1269,185 @@
     
-return browser
+configure(browser);%0A        %0A        return browser;%0A    %7D%0A%0A    private void configure(Browser browser) %7B%0A        browser.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS)
 ;%0A  

configure implicit wait for selenium-driver