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

com.polonium.webdriver.DriverFactory Maven / Gradle / Ivy

package com.polonium.webdriver;

import static com.polonium.webdriver.Browser.FIREFOX;

import java.io.File;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

/**
 * Create once static Driver object. Type dependent on static DEFAULT_BROWSER
 * field
 * 
 * @author Marek Serwanski
 */
public class DriverFactory {
	// default browser is firefox
	public static Browser[] TARGET_BROWSERS = {};
	public static Browser CURRENT_BROWSER = FIREFOX;
	public static Browser DEFAULT_BROWSER = FIREFOX;
	private static WebDriver WEB_DRIVER;

	public static WebDriver getDriver() {
		if (WEB_DRIVER == null) {
			switch (CURRENT_BROWSER) {
			case FIREFOX:
				WEB_DRIVER = new FirefoxDriver();
				break;
			case IEXPLORER:
				File file = new File("C:/IEDriverServer.exe");
				System.setProperty("webdriver.ie.driver",
						file.getAbsolutePath());
				WEB_DRIVER = new InternetExplorerDriver();
				break;
			case CHROME:
				WEB_DRIVER = new ChromeDriver();
				break;
			}
		}
		return WEB_DRIVER;
	}

	public static void clearDriver() {
		WEB_DRIVER = null;
	}
	
	public static void setDefaultBrowser(){
		TARGET_BROWSERS = new Browser[] {DEFAULT_BROWSER};
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy