DriverFactory - Create and Destroy

Consider the following code.

public class DriverFactory {

    protected static WebDriver driver;


    public DriverFactory() {
        initialize();
    }

    public void initialize() {
        if (driver == null)
            createNewDriverInstance();
    }

    private void createNewDriverInstance() {
        driver = new FirefoxDriver();
    }

    public WebDriver getDriver() {
        return driver;
    }

    public void destroyDriver() {
        driver.quit();
        driver = null;
    }
}

Now we can use the destroyDriver() method to kill the driver in the right way. So if all the tests want to start their own driver instance and kill the same at the end, this code would keep it clean.

So how do we use this code in the right way, let's see.

results matching ""

    No results matching ""