|
45 | 45 | import java.util.logging.Level; |
46 | 46 | import org.junit.jupiter.api.Tag; |
47 | 47 | import org.junit.jupiter.api.Test; |
| 48 | +import org.mockito.MockedStatic; |
| 49 | +import org.mockito.Mockito; |
48 | 50 | import org.openqa.selenium.Alert; |
49 | 51 | import org.openqa.selenium.By; |
50 | 52 | import org.openqa.selenium.Cookie; |
|
58 | 60 | import org.openqa.selenium.WebDriverException; |
59 | 61 | import org.openqa.selenium.WebElement; |
60 | 62 | import org.openqa.selenium.WindowType; |
| 63 | +import org.openqa.selenium.internal.Debug; |
61 | 64 | import org.openqa.selenium.virtualauthenticator.VirtualAuthenticator; |
62 | 65 | import org.openqa.selenium.virtualauthenticator.VirtualAuthenticatorOptions; |
63 | 66 |
|
@@ -705,6 +708,62 @@ void canHandleGeneralExceptionThrownByCommandExecutor() { |
705 | 708 | fixture.verifyCommands(new CommandPayload(DriverCommand.GET_CURRENT_URL, emptyMap())); |
706 | 709 | } |
707 | 710 |
|
| 711 | + @Test |
| 712 | + void canHandleGeneralExceptionInNonDebugModeThrownByCommandExecutor() { |
| 713 | + try (MockedStatic<Debug> debugMock = Mockito.mockStatic(Debug.class)) { |
| 714 | + final ImmutableMap<String, String> parameters = ImmutableMap.of( |
| 715 | + "url", "https://user:[email protected]", "token", "12345Secret"); |
| 716 | + final CommandPayload commandPayload = new CommandPayload(DriverCommand.GET, parameters); |
| 717 | + debugMock.when(Debug::isDebugging).thenReturn(false); |
| 718 | + WebDriverFixture fixture = new WebDriverFixture( |
| 719 | + new ImmutableCapabilities( |
| 720 | + "browserName", "cheese", "platformName", "WINDOWS"), |
| 721 | + echoCapabilities, exceptionResponder); |
| 722 | + assertThatExceptionOfType(WebDriverException.class) |
| 723 | + .isThrownBy(() -> fixture.driver.execute(commandPayload)) |
| 724 | + .withMessageStartingWith("Error communicating with the remote browser. It may have died.") |
| 725 | + .withMessageContaining("Build info: ") |
| 726 | + .withMessageContaining( |
| 727 | + "Driver info: org.openqa.selenium.remote.RemoteWebDriver") |
| 728 | + .withMessageContaining(String.format( |
| 729 | + "Session ID: %s", fixture.driver.getSessionId())) |
| 730 | + .withMessageContaining(String.format( |
| 731 | + "%s", fixture.driver.getCapabilities())) |
| 732 | + .withMessageContaining(String.format( |
| 733 | + "Command: [%s, get [url, token]]", fixture.driver.getSessionId())) |
| 734 | + .havingCause() |
| 735 | + .withMessage("BOOM!!!"); |
| 736 | + } |
| 737 | + } |
| 738 | + |
| 739 | + @Test |
| 740 | + void canHandleGeneralExceptionInDebugModeThrownByCommandExecutor() { |
| 741 | + try (MockedStatic<Debug> debugMock = Mockito.mockStatic(Debug.class)) { |
| 742 | + final ImmutableMap<String, String> parameters = ImmutableMap.of( |
| 743 | + "url", "https://user:[email protected]", "token", "12345Secret"); |
| 744 | + final CommandPayload commandPayload = new CommandPayload(DriverCommand.GET, parameters); |
| 745 | + debugMock.when(Debug::isDebugging).thenReturn(true); |
| 746 | + WebDriverFixture fixture = new WebDriverFixture( |
| 747 | + new ImmutableCapabilities( |
| 748 | + "browserName", "cheese", "platformName", "WINDOWS"), |
| 749 | + echoCapabilities, exceptionResponder); |
| 750 | + assertThatExceptionOfType(WebDriverException.class) |
| 751 | + .isThrownBy(() -> fixture.driver.execute(commandPayload)) |
| 752 | + .withMessageStartingWith("Error communicating with the remote browser. It may have died.") |
| 753 | + .withMessageContaining("Build info: ") |
| 754 | + .withMessageContaining( |
| 755 | + "Driver info: org.openqa.selenium.remote.RemoteWebDriver") |
| 756 | + .withMessageContaining(String.format( |
| 757 | + "Session ID: %s", fixture.driver.getSessionId())) |
| 758 | + .withMessageContaining(String.format( |
| 759 | + "%s", fixture.driver.getCapabilities())) |
| 760 | + .withMessageContaining(String.format( |
| 761 | + "Command: [%s, get %s]", fixture.driver.getSessionId(), parameters)) |
| 762 | + .havingCause() |
| 763 | + .withMessage("BOOM!!!"); |
| 764 | + } |
| 765 | + } |
| 766 | + |
708 | 767 | @Test |
709 | 768 | void canHandleWebDriverExceptionReturnedByCommandExecutor() { |
710 | 769 | WebDriverFixture fixture = |
|
0 commit comments