Skip to content

Commit cd07794

Browse files
authored
Screenshot file suffix as parameter in library init (#236)
* add keyword to modify screenshot file suffix * screenshot file suffix as library import argument * update changelog to new screenshot file suffix keyword * run of robotidy
1 parent 5b51fc5 commit cd07794

File tree

5 files changed

+62
-3
lines changed

5 files changed

+62
-3
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
77

88
## [Unreleased][]
99

10+
### Added
11+
12+
- [#234] (https://github.com/GDATASoftwareAG/robotframework-flaui/pull/234) New keyword to set screenshot file suffix
13+
- Set Screenshot File Suffix <SUFFIX>
14+
- [] () Include screenshot_suffix as parameter in library init.
15+
1016
## [Release][4.0.0] [4.0.0][3.7.0-4.0.0] - 2025-04-26
1117

1218
### Updated

atests/Screenshot.robot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,5 @@ Reset Screenshot Environment To Default
135135
Set Screenshot Log Mode File
136136
Take Screenshots On Failure ${True}
137137
Set Screenshot Directory
138+
Set Screenshot File Suffix
138139
Run Keyword And Ignore Error Stop Application ${pid}

atests/ScreenshotFileSuffix.robot

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
*** Settings ***
2+
Documentation Test suite for screenshot keywords.
3+
... XPath not found error handling for all keywords must be implemented under ErrorHandling.robot
4+
...
5+
6+
Library Process
7+
Library String
8+
Library OperatingSystem
9+
Library StringFormat
10+
Library FlaUILibrary uia=${UIA} screenshot_on_failure=True screenshot_suffix=png
11+
Resource util/Common.resource
12+
Resource util/Error.resource
13+
Resource util/XPath.resource
14+
15+
16+
*** Variables ***
17+
${SCREENSHOT_FOLDER} screenshots/default
18+
19+
20+
*** Test Cases ***
21+
Take Screenshot Of Window As Png From Library Import
22+
[Setup] Start Application
23+
${PID} Attach Application By Name ${TEST_APP}
24+
Set Screenshot Directory ${SCREENSHOT_FOLDER}
25+
${FILENAME} Get Expected Filename ${TEST_NAME} png
26+
File Should Not Exist ${OUTPUT DIR}/${SCREENSHOT_FOLDER}/${FILENAME}
27+
Take Screenshot ${MAIN_WINDOW}
28+
File Should Exist ${OUTPUT DIR}/${SCREENSHOT_FOLDER}/${FILENAME}
29+
[Teardown] Run Keyword And Ignore Error Stop Application ${PID}
30+
31+
32+
*** Keywords ***
33+
Get Expected Filename
34+
[Arguments] ${TEST_FILENAME} ${SUFFIX}=jpg
35+
${FILENAME} Convert To Lowercase ${TEST_FILENAME}
36+
${HOSTNAME} Convert To Lowercase %{COMPUTERNAME}
37+
38+
Should Be Lowercase ${FILENAME}
39+
40+
${FILENAME} Replace String ${FILENAME} ${space} _
41+
${FILENAME} Catenate SEPARATOR=_ ${HOSTNAME} ${FILENAME}
42+
${FILENAME} Catenate SEPARATOR=_ test ${FILENAME}
43+
${FILENAME} Catenate SEPARATOR=_ ${FILENAME} [0-9]*
44+
${FILENAME} Catenate SEPARATOR=. ${FILENAME} ${SUFFIX}
45+
46+
RETURN ${FILENAME}

src/FlaUILibrary/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ def __init__(self,
107107
screenshot_on_failure='True',
108108
screenshot_dir=None,
109109
timeout=1000,
110-
screenshot_mode='FILE'):
110+
screenshot_mode='FILE',
111+
screenshot_suffix='jpg'):
111112
"""
112113
FlaUiLibrary can be imported by following optional arguments:
113114
@@ -116,6 +117,7 @@ def __init__(self,
116117
``screenshot_dir`` is the directory where screenshots are saved.
117118
``timeout`` maximum amount of waiting time in ms for an element find action. Default value is 1000ms.
118119
``screenshot_mode`` screenshot mode how to persist screenshots as FILE or BASE64
120+
``screenshot_suffix`` screenshot file type and suffix for screenshots saved as FILE
119121
120122
If the given directory does not already exist, it will be created when the first screenshot is taken.
121123
If the argument is not given, the default location for screenshots is the output directory of the Robot run,
@@ -148,7 +150,8 @@ def __init__(self,
148150
FlaUILibrary.KeywordModules.SCREENSHOT: ScreenshotKeywords(self.container,
149151
screenshot_dir,
150152
screenshot_on_failure == 'True',
151-
screenshot_mode),
153+
screenshot_mode,
154+
screenshot_suffix),
152155
FlaUILibrary.KeywordModules.TEXTBOX: TextBoxKeywords(self.container),
153156
FlaUILibrary.KeywordModules.WINDOW: WindowKeywords(self.container),
154157
FlaUILibrary.KeywordModules.RADIOBUTTON: RadioButtonKeywords(self.container),

src/FlaUILibrary/keywords/screenshot.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,21 @@ def __init__(self,
1212
container: AutomationInterfaceContainer,
1313
directory: str,
1414
is_enabled: bool,
15-
mode: str):
15+
mode: str,
16+
suffix: str):
1617
"""Creates screenshot keywords module to handle image capturing.
1718
1819
``container`` User automation container to handle element interaction
1920
``directory`` Screenshot directory to set.
2021
``is_enabled`` Flag to identify if feature is active or not.
2122
``mode`` Mode how to persists screenshots.
23+
``suffix`` File type and suffix for writing.
2224
"""
2325
self._container = container
2426
self.set_screenshot_directory(directory)
2527
self.take_screenshots_on_failure(is_enabled)
2628
self.set_screenshot_log_mode(mode)
29+
self.set_screenshot_file_suffix(suffix)
2730

2831
@keyword
2932
def get_screenshot_log_mode(self):

0 commit comments

Comments
 (0)