@@ -44,6 +44,7 @@ public class SeleniumTestRule implements TestRule {
44
44
private final Duration regularWait ;
45
45
private final Duration shortWait ;
46
46
private final RuleChain chain ;
47
+ private boolean nullDriver = false ;
47
48
48
49
public SeleniumTestRule () {
49
50
this (Duration .ofSeconds (10 ), Duration .ofSeconds (5 ));
@@ -77,6 +78,10 @@ public <X> X shortWaitUntil(Function<? super WebDriver, X> condition) {
77
78
78
79
79
80
public WebDriver getDriver () {
81
+ if (nullDriver ) {
82
+ return null ;
83
+ }
84
+
80
85
LOG .info ("CREATING DRIVER" );
81
86
WebDriver driver = actuallyCreateDriver ();
82
87
LOG .info ("CREATED " + driver );
@@ -100,6 +105,7 @@ private WebDriver actuallyCreateDriver(Capabilities capabilities) {
100
105
(current .driver instanceof RemoteWebDriver && ((RemoteWebDriver ) current .driver ).getSessionId () == null )) {
101
106
StaticResources .ensureAvailable ();
102
107
WebDriver driver = new WebDriverBuilder ().get (capabilities );
108
+ nullDriver = false ;
103
109
instances .set (new Instances (driver , regularWait , shortWait ));
104
110
}
105
111
return instances .get ().driver ;
@@ -148,6 +154,7 @@ protected void starting(Description description) {
148
154
if (killSharedDriver != null && current .matches (killSharedDriver .value ())) {
149
155
LOG .info ("Destroying driver before test " + description );
150
156
removeDriver ();
157
+ nullDriver = true ;
151
158
return ;
152
159
}
153
160
NeedsFreshDriver annotation = description .getAnnotation (NeedsFreshDriver .class );
0 commit comments