-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UnreachableBrowserException logs the command parameter details only i…
…n debug mode (#11328) * UnreachableBrowserException logs the command parameter details only in debug mode * [java] Refining PR --------- Co-authored-by: Diego Molina <[email protected]> Co-authored-by: Diego Molina <[email protected]>
- Loading branch information
1 parent
bc3b548
commit 9ff4c2b
Showing
7 changed files
with
109 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,8 @@ | |
import java.util.logging.Level; | ||
import org.junit.jupiter.api.Tag; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.MockedStatic; | ||
import org.mockito.Mockito; | ||
import org.openqa.selenium.Alert; | ||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.Cookie; | ||
|
@@ -58,6 +60,7 @@ | |
import org.openqa.selenium.WebDriverException; | ||
import org.openqa.selenium.WebElement; | ||
import org.openqa.selenium.WindowType; | ||
import org.openqa.selenium.internal.Debug; | ||
import org.openqa.selenium.virtualauthenticator.VirtualAuthenticator; | ||
import org.openqa.selenium.virtualauthenticator.VirtualAuthenticatorOptions; | ||
|
||
|
@@ -698,13 +701,69 @@ void canHandleGeneralExceptionThrownByCommandExecutor() { | |
.withMessageContaining(String.format("Session ID: %s", fixture.driver.getSessionId())) | ||
.withMessageContaining(String.format("%s", fixture.driver.getCapabilities())) | ||
.withMessageContaining( | ||
String.format("Command: [%s, getCurrentUrl {}]", fixture.driver.getSessionId())) | ||
String.format("Command: [%s, getCurrentUrl []]", fixture.driver.getSessionId())) | ||
.havingCause() | ||
.withMessage("BOOM!!!"); | ||
|
||
fixture.verifyCommands(new CommandPayload(DriverCommand.GET_CURRENT_URL, emptyMap())); | ||
} | ||
|
||
@Test | ||
void canHandleGeneralExceptionInNonDebugModeThrownByCommandExecutor() { | ||
try (MockedStatic<Debug> debugMock = Mockito.mockStatic(Debug.class)) { | ||
final ImmutableMap<String, String> parameters = ImmutableMap.of( | ||
"url", "https://user:[email protected]", "token", "12345Secret"); | ||
final CommandPayload commandPayload = new CommandPayload(DriverCommand.GET, parameters); | ||
debugMock.when(Debug::isDebugging).thenReturn(false); | ||
WebDriverFixture fixture = new WebDriverFixture( | ||
new ImmutableCapabilities( | ||
"browserName", "cheese", "platformName", "WINDOWS"), | ||
echoCapabilities, exceptionResponder); | ||
assertThatExceptionOfType(UnreachableBrowserException.class) | ||
.isThrownBy(() -> fixture.driver.execute(commandPayload)) | ||
.withMessageStartingWith("Error communicating with the remote browser. It may have died.") | ||
.withMessageContaining("Build info: ") | ||
.withMessageContaining( | ||
"Driver info: org.openqa.selenium.remote.RemoteWebDriver") | ||
.withMessageContaining(String.format( | ||
"Session ID: %s", fixture.driver.getSessionId())) | ||
.withMessageContaining(String.format( | ||
"%s", fixture.driver.getCapabilities())) | ||
.withMessageContaining(String.format( | ||
"Command: [%s, get [url, token]]", fixture.driver.getSessionId())) | ||
.havingCause() | ||
.withMessage("BOOM!!!"); | ||
} | ||
} | ||
|
||
@Test | ||
void canHandleGeneralExceptionInDebugModeThrownByCommandExecutor() { | ||
try (MockedStatic<Debug> debugMock = Mockito.mockStatic(Debug.class)) { | ||
final ImmutableMap<String, String> parameters = ImmutableMap.of( | ||
"url", "https://user:[email protected]", "token", "12345Secret"); | ||
final CommandPayload commandPayload = new CommandPayload(DriverCommand.GET, parameters); | ||
debugMock.when(Debug::isDebugging).thenReturn(true); | ||
WebDriverFixture fixture = new WebDriverFixture( | ||
new ImmutableCapabilities( | ||
"browserName", "cheese", "platformName", "WINDOWS"), | ||
echoCapabilities, exceptionResponder); | ||
assertThatExceptionOfType(UnreachableBrowserException.class) | ||
.isThrownBy(() -> fixture.driver.execute(commandPayload)) | ||
.withMessageStartingWith("Error communicating with the remote browser. It may have died.") | ||
.withMessageContaining("Build info: ") | ||
.withMessageContaining( | ||
"Driver info: org.openqa.selenium.remote.RemoteWebDriver") | ||
.withMessageContaining(String.format( | ||
"Session ID: %s", fixture.driver.getSessionId())) | ||
.withMessageContaining(String.format( | ||
"%s", fixture.driver.getCapabilities())) | ||
.withMessageContaining(String.format( | ||
"Command: [%s, get %s]", fixture.driver.getSessionId(), parameters)) | ||
.havingCause() | ||
.withMessage("BOOM!!!"); | ||
} | ||
} | ||
|
||
@Test | ||
void canHandleWebDriverExceptionReturnedByCommandExecutor() { | ||
WebDriverFixture fixture = | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters