From b1ca7314407437307b6135317fb58ba8684b90d0 Mon Sep 17 00:00:00 2001 From: seethinajayadileep Date: Fri, 20 Feb 2026 21:11:40 +0530 Subject: [PATCH 1/4] Improve diagnostic message when screenshot file write fails Adds contextual information to WebDriverException thrown during temporary screenshot file creation or write failure. Preserves original IOException as cause. --- java/src/org/openqa/selenium/OutputType.java | 30 +++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/java/src/org/openqa/selenium/OutputType.java b/java/src/org/openqa/selenium/OutputType.java index 1d0e013e41266..6c2c92cebb2a2 100644 --- a/java/src/org/openqa/selenium/OutputType.java +++ b/java/src/org/openqa/selenium/OutputType.java @@ -13,7 +13,6 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations -// under the License. package org.openqa.selenium; @@ -82,16 +81,25 @@ public File convertFromPngBytes(byte[] data) { return save(data); } - private File save(byte[] data) { - try { - Path tmpFilePath = Files.createTempFile("screenshot", ".png"); - File tmpFile = tmpFilePath.toFile(); - tmpFile.deleteOnExit(); - Files.write(tmpFilePath, data); - return tmpFile; - } catch (IOException e) { - throw new WebDriverException(e); - } + private File save(byte[] data) { + Path tmpFilePath = null; + try { + tmpFilePath = Files.createTempFile("screenshot", ".png"); + Files.write(tmpFilePath, data); + } catch (IOException e) { + String pathInfo = (tmpFilePath != null) + ? tmpFilePath.toAbsolutePath().toString() + : "temporary file could not be created"; + + throw new WebDriverException( + "Failed to create or write screenshot to temporary file: " + pathInfo, + e); + } + + File tmpFile = tmpFilePath.toFile(); + tmpFile.deleteOnExit(); + return tmpFile; + } public String toString() { From 91c824bc9e18f7125de4acefa2d5b5cffe350bac Mon Sep 17 00:00:00 2001 From: seethinajayadileep Date: Fri, 20 Feb 2026 21:29:18 +0530 Subject: [PATCH 2/4] Restore accidentally removed line --- java/src/org/openqa/selenium/OutputType.java | 1 + 1 file changed, 1 insertion(+) diff --git a/java/src/org/openqa/selenium/OutputType.java b/java/src/org/openqa/selenium/OutputType.java index 6c2c92cebb2a2..81616dc6b2ea1 100644 --- a/java/src/org/openqa/selenium/OutputType.java +++ b/java/src/org/openqa/selenium/OutputType.java @@ -13,6 +13,7 @@ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations +// under the License. package org.openqa.selenium; From 18ee9e70f992114cb3e499ed7c434d770d8427a2 Mon Sep 17 00:00:00 2001 From: seethinajayadileep Date: Wed, 25 Feb 2026 09:43:05 +0530 Subject: [PATCH 3/4] Apply formatting --- java/src/org/openqa/selenium/OutputType.java | 31 ++++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/java/src/org/openqa/selenium/OutputType.java b/java/src/org/openqa/selenium/OutputType.java index 81616dc6b2ea1..3019dbadd70d1 100644 --- a/java/src/org/openqa/selenium/OutputType.java +++ b/java/src/org/openqa/selenium/OutputType.java @@ -82,25 +82,24 @@ public File convertFromPngBytes(byte[] data) { return save(data); } - private File save(byte[] data) { - Path tmpFilePath = null; - try { - tmpFilePath = Files.createTempFile("screenshot", ".png"); - Files.write(tmpFilePath, data); - } catch (IOException e) { - String pathInfo = (tmpFilePath != null) - ? tmpFilePath.toAbsolutePath().toString() - : "temporary file could not be created"; + private File save(byte[] data) { + Path tmpFilePath = null; + try { + tmpFilePath = Files.createTempFile("screenshot", ".png"); + Files.write(tmpFilePath, data); + } catch (IOException e) { + String pathInfo = + (tmpFilePath != null) + ? tmpFilePath.toAbsolutePath().toString() + : "temporary file could not be created"; throw new WebDriverException( - "Failed to create or write screenshot to temporary file: " + pathInfo, - e); - } - - File tmpFile = tmpFilePath.toFile(); - tmpFile.deleteOnExit(); - return tmpFile; + "Failed to create or write screenshot to temporary file: " + pathInfo, e); + } + File tmpFile = tmpFilePath.toFile(); + tmpFile.deleteOnExit(); + return tmpFile; } public String toString() { From 2979ff73caada87ba5c126ba016744ae3419c394 Mon Sep 17 00:00:00 2001 From: seethinajayadileep Date: Wed, 25 Feb 2026 19:33:20 +0530 Subject: [PATCH 4/4] Refactor screenshot temp file creation error handling --- java/src/org/openqa/selenium/OutputType.java | 23 +++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/java/src/org/openqa/selenium/OutputType.java b/java/src/org/openqa/selenium/OutputType.java index 3019dbadd70d1..3a3997cfd6cb1 100644 --- a/java/src/org/openqa/selenium/OutputType.java +++ b/java/src/org/openqa/selenium/OutputType.java @@ -83,18 +83,14 @@ public File convertFromPngBytes(byte[] data) { } private File save(byte[] data) { - Path tmpFilePath = null; + Path tmpFilePath = createScreenshotFile(); try { - tmpFilePath = Files.createTempFile("screenshot", ".png"); Files.write(tmpFilePath, data); } catch (IOException e) { - String pathInfo = - (tmpFilePath != null) - ? tmpFilePath.toAbsolutePath().toString() - : "temporary file could not be created"; - throw new WebDriverException( - "Failed to create or write screenshot to temporary file: " + pathInfo, e); + "Failed to create or write screenshot to temporary file: " + + tmpFilePath.toAbsolutePath().toString(), + e); } File tmpFile = tmpFilePath.toFile(); @@ -102,6 +98,17 @@ private File save(byte[] data) { return tmpFile; } + private Path createScreenshotFile() { + try { + return Files.createTempFile("screenshot", ".png"); + } catch (IOException e) { + throw new WebDriverException( + "Failed to create or write screenshot to temporary file: " + + "temporary file could not be created", + e); + } + } + public String toString() { return "OutputType.FILE"; }