Skip to content

Commit 5e384fc

Browse files
committed
[java] fixed the ScreenshotException message
1 parent 0e3d4bc commit 5e384fc

File tree

3 files changed

+9
-84
lines changed

3 files changed

+9
-84
lines changed

java/src/org/openqa/selenium/remote/ScreenshotException.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,20 @@
2121

2222
public class ScreenshotException extends WebDriverException {
2323

24-
private final String screenshot;
24+
public ScreenshotException(String message) {
25+
super(message);
26+
}
2527

26-
public ScreenshotException(String screenGrab) {
27-
super("Screen shot has been taken");
28-
this.screenshot = screenGrab;
28+
public ScreenshotException(Throwable cause) {
29+
super(cause);
2930
}
3031

31-
public ScreenshotException(String screenGrab, Throwable cause) {
32-
super("Screen shot has been taken", cause);
33-
this.screenshot = screenGrab;
32+
public ScreenshotException(String message, Throwable cause) {
33+
super(message, cause);
3434
}
3535

36+
@Deprecated(forRemoval = true)
3637
public String getBase64EncodedScreenshot() {
37-
return screenshot;
38+
return null;
3839
}
3940
}

java/test/org/openqa/selenium/remote/ErrorHandlerTest.java

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -201,36 +201,6 @@ void testShouldBeAbleToRebuildASerializedException() {
201201
});
202202
}
203203

204-
@Test
205-
void testShouldIncludeScreenshotIfProvided() {
206-
RuntimeException serverError = new RuntimeException("foo bar baz!");
207-
Map<String, Object> data = toMap(serverError);
208-
data.put("screen", "screenGrabText");
209-
210-
assertThatExceptionOfType(WebDriverException.class)
211-
.isThrownBy(
212-
() ->
213-
handler.throwIfResponseFailed(
214-
createResponse(ErrorCodes.UNHANDLED_ERROR, data), 123))
215-
.withMessage(
216-
new WebDriverException(
217-
serverError.getMessage() + "\nCommand duration or timeout: 123 milliseconds",
218-
new WebDriverException())
219-
.getMessage())
220-
.withCauseInstanceOf(ScreenshotException.class)
221-
.satisfies(
222-
expected -> {
223-
Throwable cause = expected.getCause();
224-
assertThat(((ScreenshotException) cause).getBase64EncodedScreenshot())
225-
.isEqualTo("screenGrabText");
226-
Throwable realCause = cause.getCause();
227-
assertThat(realCause).isNotNull();
228-
assertThat(realCause.getClass()).isEqualTo(serverError.getClass());
229-
assertThat(realCause.getMessage()).isEqualTo(serverError.getMessage());
230-
assertStackTracesEqual(serverError.getStackTrace(), realCause.getStackTrace());
231-
});
232-
}
233-
234204
@Test
235205
void testShouldDefaultToWebDriverExceptionIfClassIsNotSpecified() {
236206
RuntimeException serverError = new RuntimeException("foo bar baz!");
@@ -459,29 +429,6 @@ void testShouldIndicateWhenTheServerReturnedAnExceptionThatWasSuppressed() {
459429
.withMessageContaining(new WebDriverException().getMessage());
460430
}
461431

462-
@Test
463-
void testShouldStillIncludeScreenshotEvenIfServerSideExceptionsAreDisabled() {
464-
RuntimeException serverError = new RuntimeException("foo bar baz!");
465-
Map<String, Object> data = toMap(serverError);
466-
data.put("screen", "screenGrabText");
467-
468-
handler.setIncludeServerErrors(false);
469-
470-
assertThatExceptionOfType(WebDriverException.class)
471-
.isThrownBy(
472-
() ->
473-
handler.throwIfResponseFailed(
474-
createResponse(ErrorCodes.UNHANDLED_ERROR, data), 123))
475-
.withMessageStartingWith("foo bar baz!")
476-
.withCauseInstanceOf(ScreenshotException.class)
477-
.satisfies(
478-
expected -> {
479-
ScreenshotException screenshot = (ScreenshotException) expected.getCause();
480-
assertThat(screenshot.getBase64EncodedScreenshot()).isEqualTo("screenGrabText");
481-
assertThat(screenshot).hasNoCause();
482-
});
483-
}
484-
485432
@Test
486433
void testStatusCodesRaisedBackToStatusMatches() {
487434
Map<Integer, Class<?>> exceptions = new HashMap<>();

java/test/org/openqa/selenium/remote/RemoteWebDriverScreenshotTest.java

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,38 +18,15 @@
1818
package org.openqa.selenium.remote;
1919

2020
import static org.assertj.core.api.Assertions.assertThat;
21-
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
2221
import static org.openqa.selenium.OutputType.BASE64;
2322

2423
import org.junit.jupiter.api.Test;
25-
import org.openqa.selenium.By;
26-
import org.openqa.selenium.NoSuchElementException;
2724
import org.openqa.selenium.TakesScreenshot;
2825
import org.openqa.selenium.WebDriver;
29-
import org.openqa.selenium.testing.Ignore;
3026
import org.openqa.selenium.testing.JupiterTestBase;
3127

3228
class RemoteWebDriverScreenshotTest extends JupiterTestBase {
3329

34-
@Test
35-
@Ignore
36-
public void testShouldBeAbleToGrabASnapshotOnException() {
37-
if (!(driver instanceof RemoteWebDriver)) {
38-
System.out.println("Skipping test: driver is not a remote webdriver");
39-
return;
40-
}
41-
42-
driver.get(pages.simpleTestPage);
43-
44-
assertThatExceptionOfType(NoSuchElementException.class)
45-
.isThrownBy(() -> driver.findElement(By.id("doesnayexist")))
46-
.satisfies(
47-
e ->
48-
assertThat(
49-
((ScreenshotException) e.getCause()).getBase64EncodedScreenshot().length())
50-
.isPositive());
51-
}
52-
5330
@Test
5431
void testCanAugmentWebDriverInstanceIfNecessary() {
5532
if (!(driver instanceof RemoteWebDriver)) {

0 commit comments

Comments
 (0)