Skip to content
This repository was archived by the owner on Feb 2, 2025. It is now read-only.

Commit 20e0943

Browse files
authored
Merge pull request #48 from dunand/master
Use of {index} in the filename of a screenshot
2 parents db708e9 + 809ad3b commit 20e0943

File tree

1 file changed

+8
-2
lines changed
  • src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords

1 file changed

+8
-2
lines changed

src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Screenshot.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@ public String setScreenshotDirectory(String path) {
5454

5555
@RobotKeyword("Take a screenshot of the current page and embed it into the log.\r\n" +
5656
"\r\n" +
57-
"The ``filename`` argument specifies the name of the file to write the screenshot into. If no filename is given, the screenshot is saved into file selenium-screenshot-<counter>.png under the directory where the Robot Framework log file is written into. The filename is also considered relative to the same directory, if it is not given in absolute format.\r\n" +
57+
"The ``filename`` argument specifies the name of the file to write the screenshot into. If no filename is given, the screenshot is saved into file selenium-screenshot-{index}.png under the directory where the Robot Framework log file is written into. The filename is also considered relative to the same directory, if it is not given in absolute format.\r\n" +
5858
"\r\n" +
59+
"if ``filename`` contains marker {index}, it will be automatically replaced with unique running index preventing files to be overwritten. Indices start from 1.\r\n" +
60+
"\r\n" +
5961
"A CSS can be used to modify how the screenshot is taken. By default the background color is changed to avoid possible problems with background leaking when the page layout is somehow broken.")
60-
@ArgumentNames({ "filename=NONE" })
62+
@ArgumentNames({ "filename=selenium-screenshot-{index}.png" })
6163
public void capturePageScreenshot(String...params) {
6264
String filename = robot.getParamsValue(params, 0, null);
6365
File logdir = screenshotDir != null ? screenshotDir : logging.getLogDir();
@@ -114,6 +116,10 @@ protected String normalizeFilename(String filename) {
114116
if (filename == null) {
115117
screenshotIndex++;
116118
filename = String.format("selenium-screenshot-%d.png", screenshotIndex);
119+
} else if(filename.contains("{index}")) {
120+
screenshotIndex++;
121+
filename = filename.replace("{index}", "%d");
122+
filename = String.format(filename, screenshotIndex);
117123
} else {
118124
filename = filename.replace('/', File.separatorChar);
119125
}

0 commit comments

Comments
 (0)