@@ -0,0 +1,3394 @@
+/*%0A * Copyright 2015 www.seleniumtests.com%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A * http://www.apache.org/licenses/LICENSE-2.0%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage com.seleniumtests.browserfactory;%0A%0Aimport com.seleniumtests.driver.DriverConfig;%0Aimport org.openqa.selenium.WebDriver;%0Aimport org.openqa.selenium.WebDriverException;%0Aimport org.openqa.selenium.firefox.FirefoxDriver;%0A%0Aimport java.util.concurrent.TimeUnit;%0A%0Apublic class MarionetteDriverFactory extends AbstractWebDriverFactory implements IWebDriverFactory %7B%0A    private long timeout = 60;%0A%0A    /**%0A     * @param  cfg  the configuration of the marionetteDriver%0A     */%0A    public MarionetteDriverFactory(final DriverConfig cfg) %7B%0A        super(cfg);%0A    %7D%0A%0A    /**%0A     * create native driver instance, designed for unit testing.%0A     *%0A     * @return%0A     */%0A    protected WebDriver createNativeDriver() %7B%0A        return new FirefoxDriver(new MarionetteCapabilitiesFactory().createCapabilities(webDriverConfig));%0A    %7D%0A%0A    @Override%0A    public WebDriver createWebDriver() %7B%0A        DriverConfig cfg = this.getWebDriverConfig();%0A%0A        System.out.println(%22start create marionette%22);%0A        driver = createWebDriverWithTimeout();%0A%0A        System.out.println(%22end create marionette%22);%0A%0A        // Implicit Waits to handle dynamic element. The default value is 5%0A        // seconds.%0A        setImplicitWaitTimeout(cfg.getImplicitWaitTimeout());%0A        if (cfg.getPageLoadTimeout() %3E= 0) %7B%0A            setPageLoadTimeout(cfg.getPageLoadTimeout());%0A        %7D%0A%0A        this.setWebDriver(driver);%0A        return driver;%0A    %7D%0A%0A    /**%0A     * Create webDriver, capture socket customexception and retry with timeout.%0A     *%0A     * @return  WebDriver%0A     */%0A    protected WebDriver createWebDriverWithTimeout() %7B%0A        long time = 0;%0A        while (time %3C getTimeout()) %7B%0A            try %7B%0A                driver = createNativeDriver();%0A                return driver;%0A            %7D catch (WebDriverException ex) %7B%0A                if (ex.getMessage().contains(%22SocketException%22)%0A                        %7C%7C ex.getMessage().contains(%22Failed to connect to binary FirefoxBinary%22)%0A                        %7C%7C ex.getMessage().contains(%22Unable to bind to locking port 7054 within 45000 ms%22)) %7B%0A                    try %7B%0A                        Thread.sleep(1000);%0A                    %7D catch (InterruptedException e) %7B %7D%0A%0A                    time++;%0A                %7D else %7B%0A                    throw new RuntimeException(ex);%0A                %7D%0A            %7D%0A        %7D%0A%0A        throw new RuntimeException(%22Got customexception when creating webDriver with socket timeout 1 minute%22);%0A    %7D%0A%0A    /**%0A     * It's designed for shorten tiemout in unit testing.%0A     *%0A     * @return  timeout%0A     */%0A    protected long getTimeout() %7B%0A        return timeout;%0A    %7D%0A%0A    protected void setPageLoadTimeout(final long timeout) %7B%0A        driver.manage().timeouts().pageLoadTimeout(timeout, TimeUnit.SECONDS);%0A    %7D%0A%7D%0A

add Marionette Driver Factory