Created
September 13, 2011 12:48
-
-
Save freynaud/1213730 to your computer and use it in GitHub Desktop.
This file contains 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 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