All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.thucydides.core.webdriver.WebdriverManager Maven / Gradle / Ivy

There is a newer version: 0.9.275
Show newest version
package net.thucydides.core.webdriver;

import org.openqa.selenium.WebDriver;

/**
 * Manage WebDriver instances.
 * It instantiates browser drivers, based on the test configuration, and manages them for the
 * duration of the tests.
 * 
 * @author johnsmart
 *
 */
public class WebdriverManager {

    /**
     * A WebDriver instance is shared across all the tests executed by the runner in a given test run.
     */
    private final WebDriver webdriver;

    private final WebDriverFactory webDriverFactory;

    public WebdriverManager(final WebDriverFactory webDriverFactory) {
        this.webDriverFactory = webDriverFactory;
        webdriver = newDriver();
    }

    /**
     * Create a new driver instance based on system property values. You can
     * override this method to use a custom driver if you really know what you
     * are doing.
     * 
     * @throws UnsupportedDriverException
     *             if the driver type is not supported.
     */
    protected WebDriver newDriver() {
        SupportedWebDriver supportedDriverType = Configuration.getDriverType();
        Class webDriverType = WebDriverFactory.getClassFor(supportedDriverType);
        return WebdriverProxyFactory.getFactory().proxyFor(webDriverType, webDriverFactory);
    }
    
    public void closeDriver() {
        if (getWebdriver() != null) {
            getWebdriver().close();
            getWebdriver().quit();
        }
    }

    public WebDriver getWebdriver() {
        return webdriver;
    }

    public Class getWebDriverClass() {
        return WebDriverFactory.getClassFor(Configuration.getDriverType());
     }

}    




© 2015 - 2025 Weber Informatics LLC | Privacy Policy