ThreadGuard
This class is only available in the Java Binding
ThreadGuard checks that a driver is called only from the same thread that created it. Threading issues especially when running tests in Parallel may have mysterious and hard to diagnose errors. Using this wrapper prevents this category of errors and will raise an exception when it happens.
The following example simulate a clash of threads:
The result shown below:
As seen in the example:
protectedDriverWill be created in Main thread- We use Java
Runnableto spin up a new process and a newThreadto run the process - Both
Threadwill clash because the Main Thread does not haveprotectedDriverin it’s memory. ThreadGuard.protectwill throw an exception.
Note:
This does not replace the need for using ThreadLocal to manage drivers when running parallel.




