Created
January 9, 2025 17:06
-
-
Save borodicht/780c2128c6c590576e7997dbdd4cfe42 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ui.drivers; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.chrome.ChromeDriver; | |
import org.openqa.selenium.chrome.ChromeOptions; | |
import org.openqa.selenium.firefox.FirefoxDriver; | |
import org.openqa.selenium.firefox.FirefoxOptions; | |
public class DriverManager { | |
private static ThreadLocal <WebDriver> driver = new ThreadLocal<>(); | |
private DriverManager() {}; | |
public static WebDriver getDriver() { | |
if (driver.get() == null) { | |
iniztialiazeDriver(); | |
} | |
return driver.get(); | |
} | |
private static void iniztialiazeDriver() { | |
String browser = System.getProperty("browser", "chrome"); | |
switch (browser.toLowerCase()) { | |
case "chrome": | |
ChromeOptions options = new ChromeOptions(); | |
options.addArguments("--headless"); | |
driver.set(new ChromeDriver(options)); | |
case "firefox": | |
FirefoxOptions options1 = new FirefoxOptions(); | |
options1.addArguments("--headless"); | |
driver.set(new FirefoxDriver(options1)); | |
default: | |
throw new IllegalArgumentException(browser); | |
} | |
} | |
public void tearDown() { | |
if(driver.get() != null) { | |
driver.get().quit(); | |
driver.remove(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment