Skip to content

Instantly share code, notes, and snippets.

@freynaud
Created September 13, 2011 12:48
Show Gist options
  • Save freynaud/1213730 to your computer and use it in GitHub Desktop.
Save freynaud/1213730 to your computer and use it in GitHub Desktop.
package com.ebay.regression.tests;
import java.net.URL;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
public class ThreadLocalDriver {
private static ThreadLocal<WebDriver> threadBoundDriver = new ThreadLocal<WebDriver>();
// get the driver currently used for the thread.Lazy loaded, if there is not driver yet, create it.
public static WebDriver get(){
WebDriver currentDriver = threadBoundDriver.get();
if (currentDriver==null){
currentDriver = new RemoteWebDriver(new URL(""),DesiredCapabilities.firefox());
threadBoundDriver.set(currentDriver);
}
return threadBoundDriver.get();
}
// close everything.
public static void quit(){
WebDriver currentDriver = threadBoundDriver.get();
if (currentDriver!=null){
currentDriver.quit();
threadBoundDriver.set(null);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment