Using the PropertyReader

Now that we have moved the browser key into the property file, lets use the same to create a driver instance in the DriverFactory class.

Consider the following code for the same.

public class DriverFactory {

    protected static WebDriver driver;

    public DriverFactory() {

    public void initialize() {
        if (driver == null)

    private void createNewDriverInstance() {
        String browser = new PropertyReader().readProperty("browser");
        if (browser.equals("firefox")) {
            driver = new FirefoxDriver();
        } else {
            System.out.println("can't read browser type");

    public WebDriver getDriver() {
        return driver;

    public void destroyDriver() {
        driver = null;

So we can switch the driver creation based on what value we pass from the "browser" property key.

results matching ""

    No results matching ""