3535import org .junit .jupiter .api .BeforeEach ;
3636import org .junit .jupiter .api .Test ;
3737import org .openqa .selenium .By ;
38+ import org .openqa .selenium .MutableCapabilities ;
3839import org .openqa .selenium .NoSuchSessionException ;
3940import org .openqa .selenium .WebDriver ;
41+ import org .openqa .selenium .WebDriverException ;
4042import org .openqa .selenium .grid .config .MapConfig ;
4143import org .openqa .selenium .grid .config .MemoizedConfig ;
4244import org .openqa .selenium .grid .config .TomlConfig ;
@@ -73,7 +75,9 @@ public void setupServers() {
7375 + "driver-implementation = "
7476 + browser .displayName ()
7577 + "\n "
76- + "session-timeout = 15" )));
78+ + "session-timeout = 11"
79+ + "\n "
80+ + "enable-managed-downloads = true" )));
7781 tearDowns .add (deployment );
7882
7983 server = deployment .getServer ();
@@ -114,7 +118,10 @@ void multipleSimultaneousSessions() throws Exception {
114118 try {
115119 WebDriver driver =
116120 RemoteWebDriver .builder ()
117- .oneOf (browser .getCapabilities ())
121+ .oneOf (
122+ browser
123+ .getCapabilities ()
124+ .merge (new MutableCapabilities (Map .of ("se:downloadsEnabled" , true ))))
118125 .address (server .getUrl ())
119126 .build ();
120127
@@ -134,13 +141,42 @@ void multipleSimultaneousSessions() throws Exception {
134141 }
135142
136143 @ Test
137- void testStopTimedOutSession () throws Exception {
144+ void multipleSimultaneousSessionsTimedOut () throws Exception {
138145 assertThat (server .isStarted ()).isTrue ();
139- WebDriver driver =
140- RemoteWebDriver .builder ().oneOf (browser .getCapabilities ()).address (server .getUrl ()).build ();
141- driver .get (appServer .getUrl ().toString ());
142- Thread .sleep (15000 );
143- NoSuchSessionException exception = assertThrows (NoSuchSessionException .class , driver ::getTitle );
144- assertTrue (exception .getMessage ().startsWith ("Cannot find session with id:" ));
146+
147+ CompletableFuture <?>[] futures = new CompletableFuture <?>[10 ];
148+ for (int i = 0 ; i < futures .length ; i ++) {
149+ CompletableFuture <Object > future = new CompletableFuture <>();
150+ futures [i ] = future ;
151+
152+ executor .submit (
153+ () -> {
154+ try {
155+ WebDriver driver =
156+ RemoteWebDriver .builder ()
157+ .oneOf (browser .getCapabilities ())
158+ .address (server .getUrl ())
159+ .build ();
160+ driver .get (appServer .getUrl ().toString ());
161+ Thread .sleep (11000 );
162+ NoSuchSessionException exception =
163+ assertThrows (NoSuchSessionException .class , driver ::getTitle );
164+ assertTrue (exception .getMessage ().startsWith ("Cannot find session with id:" ));
165+ WebDriverException webDriverException =
166+ assertThrows (
167+ WebDriverException .class ,
168+ () -> ((RemoteWebDriver ) driver ).getDownloadableFiles ());
169+ assertTrue (
170+ webDriverException
171+ .getMessage ()
172+ .startsWith ("Cannot find downloads file system for session id:" ));
173+ future .complete (true );
174+ } catch (Exception e ) {
175+ future .completeExceptionally (e );
176+ }
177+ });
178+ }
179+
180+ CompletableFuture .allOf (futures ).get (5 , MINUTES );
145181 }
146182}
0 commit comments