Skip to content

Commit

Permalink
Merge pull request #84 from dvsa/revert-83-browserLog
Browse files Browse the repository at this point in the history
Revert "chore: log browser"
  • Loading branch information
sr4850 authored Dec 10, 2024
2 parents f057a5e + 66644ac commit e8ec217
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions src/main/java/activesupport/driver/Browser.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public class Browser {
private static String portNumber;
private static String platform;
private static String browserVersion;
protected static ThreadLocal<WebDriver> threadLocalDriver = new ThreadLocal<>();
protected static
ThreadLocal<WebDriver> threadLocalDriver = new ThreadLocal<>();
private static final Logger LOGGER = LogManager.getLogger(Browser.class);

static Local bsLocal = new Local();
Expand Down Expand Up @@ -76,17 +77,17 @@ public static WebDriver navigate() {
try {
whichBrowser(System.getProperty("browser"));
} catch (IllegalBrowserException | MalformedURLException e) {
LOGGER.error("Error setting up browser: ", e);
LOGGER.info("STACK TRACE: ".concat(e.toString()));
}
}
return getDriver();
}

public static WebDriver getDriver() {
public static WebDriver getDriver(){
return threadLocalDriver.get();
}

public static String hubURL() {
public static String hubURL(){
gridURL = gridURL == null ? "http://localhost:4444/wd/hub" : gridURL;
return gridURL;
}
Expand All @@ -97,8 +98,6 @@ private static void whichBrowser(String browserName) throws IllegalBrowserExcept
FirefoxSetUp firefox = new FirefoxSetUp();
EdgeSetUp edge = new EdgeSetUp();

LOGGER.info("Setting up browser: " + browserName);

switch (browserName) {
case "chrome":
driver = chrome.driver();
Expand All @@ -110,40 +109,36 @@ private static void whichBrowser(String browserName) throws IllegalBrowserExcept
driver = firefox.driver();
break;
case "safari":
// Add Safari setup if needed
break;
case "headless":
chrome.getChromeOptions().addArguments("--headless");
driver = chrome.driver();
break;
case "chrome-proxy":
chrome.getChromeOptions().setProxy(ProxyConfig.dvsaProxy().setSslProxy(getIpAddress().concat(":" + getPortNumber())));
chrome.getChromeOptions().setProxy(ProxyConfig.dvsaProxy().setSslProxy(getIpAddress().concat(":"+getPortNumber())));
driver = chrome.driver();
break;
case "firefox-proxy":
firefox.getOptions().setProxy(ProxyConfig.dvsaProxy().setSslProxy(getIpAddress().concat(":" + getPortNumber())));
firefox.getOptions().setProxy(ProxyConfig.dvsaProxy().setSslProxy(getIpAddress().concat(":"+getPortNumber())));
driver = firefox.driver();
break;
default:
throw new IllegalBrowserException();
}
threadLocalDriver.set(driver);
LOGGER.info("Browser setup complete: " + browserName);
getDriver();
}

public static void closeBrowser() throws Exception {
if (getDriver() != null) {
LOGGER.info("Closing browser");
if (getDriver() != null)
getDriver().quit();
}
bsLocal.stop();
threadLocalDriver.remove();
LOGGER.info("Browser closed and resources cleaned up");
}

public static boolean isBrowserOpen() {
boolean isOpen = getDriver() != null;
LOGGER.info("Checking if browser is open: " + isOpen);
boolean isOpen;
isOpen = getDriver() != null;
return isOpen;
}
}
}

0 comments on commit e8ec217

Please sign in to comment.