Skip to content

Commit 15e4fdf

Browse files
committed
use WebDriverBuilder for driver
1 parent 2efeb62 commit 15e4fdf

File tree

1 file changed

+32
-22
lines changed

1 file changed

+32
-22
lines changed

java/test/org/openqa/selenium/firefox/FirefoxDriverConcurrentTest.java

+32-22
Original file line numberDiff line numberDiff line change
@@ -172,28 +172,38 @@ void multipleFirefoxInstancesWithBiDiEnabledCanRunSimultaneously() {
172172
FirefoxOptions options1 = new FirefoxOptions().enableBiDi();
173173
FirefoxOptions options2 = new FirefoxOptions().enableBiDi();
174174

175-
FirefoxDriver driver1;
176-
FirefoxDriver driver2;
175+
WebDriver driver1 = null;
176+
WebDriver driver2 = null;
177177

178-
// Start the first Firefox instance
179-
driver1 = new FirefoxDriver(options1);
180-
BiDi biDi1 = driver1.getBiDi();
181-
assertThat(biDi1).isNotNull();
182-
183-
// Extract the BiDi websocket URL and port for the first instance
184-
String webSocketUrl1 = (String) driver1.getCapabilities().getCapability("webSocketUrl");
185-
String port1 = webSocketUrl1.replaceAll("^ws://[^:]+:(\\d+)/.*$", "$1");
186-
187-
// Start the second Firefox instance
188-
driver2 = new FirefoxDriver(options2);
189-
BiDi biDi2 = driver2.getBiDi();
190-
assertThat(biDi2).isNotNull();
191-
192-
// Extract the BiDi websocket URL and port for the second instance
193-
String webSocketUrl2 = (String) driver2.getCapabilities().getCapability("webSocketUrl");
194-
String port2 = webSocketUrl2.replaceAll("^ws://[^:]+:(\\d+)/.*$", "$1");
195-
196-
// Verify that the ports are different
197-
assertThat(port1).isNotEqualTo(port2);
178+
try {
179+
driver1 = new WebDriverBuilder().get(options1);
180+
BiDi biDi1 = ((FirefoxDriver) driver1).getBiDi();
181+
assertThat(biDi1).isNotNull();
182+
183+
// Extract the BiDi websocket URL and port for the first instance
184+
String webSocketUrl1 =
185+
(String) ((FirefoxDriver) driver1).getCapabilities().getCapability("webSocketUrl");
186+
String port1 = webSocketUrl1.replaceAll("^ws://[^:]+:(\\d+)/.*$", "$1");
187+
188+
driver2 = new WebDriverBuilder().get(options2);
189+
BiDi biDi2 = ((FirefoxDriver) driver2).getBiDi();
190+
assertThat(biDi2).isNotNull();
191+
192+
// Extract the BiDi websocket URL and port for the second instance
193+
String webSocketUrl2 =
194+
(String) ((FirefoxDriver) driver2).getCapabilities().getCapability("webSocketUrl");
195+
String port2 = webSocketUrl2.replaceAll("^ws://[^:]+:(\\d+)/.*$", "$1");
196+
197+
// Verify that the ports are different
198+
assertThat(port1).isNotEqualTo(port2);
199+
} finally {
200+
// Clean up
201+
if (driver1 != null) {
202+
driver1.quit();
203+
}
204+
if (driver2 != null) {
205+
driver2.quit();
206+
}
207+
}
198208
}
199209
}

0 commit comments

Comments
 (0)