|
25 | 25 | import org.openqa.selenium.SessionNotCreatedException; |
26 | 26 | import org.openqa.selenium.WebDriver; |
27 | 27 | import org.openqa.selenium.chrome.ChromeOptions; |
| 28 | +import org.openqa.selenium.devtools.DevTools; |
| 29 | +import org.openqa.selenium.devtools.HasDevTools; |
28 | 30 | import org.openqa.selenium.firefox.FirefoxOptions; |
29 | 31 | import org.openqa.selenium.ie.InternetExplorerOptions; |
30 | 32 | import org.openqa.selenium.json.Json; |
@@ -383,6 +385,70 @@ public void shouldAugmentDriverIfPossible() { |
383 | 385 | assertThat(number).isEqualTo(1); |
384 | 386 | } |
385 | 387 |
|
| 388 | + @Test |
| 389 | + public void shouldAugmentDriverWhenUsingDriverService() throws IOException { |
| 390 | + URI uri = URI.create("http://localhost:9898"); |
| 391 | + URL url = uri.toURL(); |
| 392 | + |
| 393 | + DriverService service = new FakeDriverService() { |
| 394 | + @Override |
| 395 | + public URL getUrl() { |
| 396 | + return url; |
| 397 | + } |
| 398 | + }; |
| 399 | + |
| 400 | + HttpResponse response = new HttpResponse() |
| 401 | + .setContent(Contents.asJson(ImmutableMap.of( |
| 402 | + "value", ImmutableMap.of( |
| 403 | + "sessionId", SESSION_ID, |
| 404 | + "capabilities", new ImmutableCapabilities("firefox", "caps"))))); |
| 405 | + |
| 406 | + Augmenter augmenter = new Augmenter().addDriverAugmentation("firefox", |
| 407 | + AugmenterTest.HasMagicNumbers.class, |
| 408 | + (c, exe) -> () -> 1); |
| 409 | + WebDriver driver = RemoteWebDriver.builder() |
| 410 | + .oneOf(new FirefoxOptions()) |
| 411 | + .withDriverService(service) |
| 412 | + .augmentUsing(augmenter) |
| 413 | + .connectingWith(config -> req -> response) |
| 414 | + .build(); |
| 415 | + |
| 416 | + int number = ((AugmenterTest.HasMagicNumbers) driver).getMagicNumber(); |
| 417 | + |
| 418 | + assertThat(driver).isInstanceOf(AugmenterTest.HasMagicNumbers.class); |
| 419 | + assertThat(number).isEqualTo(1); |
| 420 | + } |
| 421 | + |
| 422 | + @Test |
| 423 | + public void shouldAugmentWithDevToolsWhenUsingDriverService() throws IOException { |
| 424 | + URI uri = URI.create("http://localhost:9898"); |
| 425 | + URL url = uri.toURL(); |
| 426 | + |
| 427 | + DriverService service = new FakeDriverService() { |
| 428 | + @Override |
| 429 | + public URL getUrl() { |
| 430 | + return url; |
| 431 | + } |
| 432 | + }; |
| 433 | + |
| 434 | + HttpResponse response = new HttpResponse() |
| 435 | + .setContent(Contents.asJson(ImmutableMap.of( |
| 436 | + "value", ImmutableMap.of( |
| 437 | + "sessionId", SESSION_ID, |
| 438 | + "capabilities", new ImmutableCapabilities("firefox", "caps", |
| 439 | + "browserName", "firefox", |
| 440 | + "moz:debuggerAddress", uri.toString()))))); |
| 441 | + |
| 442 | + WebDriver driver = RemoteWebDriver.builder() |
| 443 | + .oneOf(new FirefoxOptions()) |
| 444 | + .withDriverService(service) |
| 445 | + .augmentUsing(new Augmenter()) |
| 446 | + .connectingWith(config -> req -> response) |
| 447 | + .build(); |
| 448 | + |
| 449 | + assertThat(driver).isInstanceOf(HasDevTools.class); |
| 450 | + } |
| 451 | + |
386 | 452 | @SuppressWarnings("unchecked") |
387 | 453 | private List<Capabilities> listCapabilities(HttpRequest request) { |
388 | 454 | Map<String, Object> converted = new Json().toType(Contents.string(request), MAP_TYPE); |
|
0 commit comments