Skip to content

Commit a50bf5e

Browse files
Ossi Rajuvaaraaaltat
authored andcommitted
Use correct directory for screenshots when EMBED is default
It's possible to set EMBED as the default option for screenshots and override it in a per keyword basis to actual file paths. It worked correctly by accident with absolute paths, because of how os.path.join() works, but created a 'EMBED' folder with relative paths.
1 parent 4b7fec6 commit a50bf5e

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

atest/acceptance/keywords/screenshots_embed.robot

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ Capture Element Screenshot EMBED As File Name
3333
Should Be Equal ${file} EMBED
3434
Verify That .png Files Do Not Exist
3535

36+
Capture Page Screenshot Override EMBED
37+
[Tags] NoGrid
38+
[Setup] Remove .png Files
39+
Set Screenshot Directory EMBED
40+
${file}= Capture Page Screenshot override-embed-screenshot.png
41+
Should Be Equal ${file} ${OUTPUTDIR}/override-embed-screenshot.png
42+
File Should Exist ${OUTPUTDIR}/override-embed-screenshot.png
43+
File Should Not Exist ${EXECDIR}/*.png
44+
File Should Not Exist ${EXECDIR}/EMBED/*.png
45+
3646
*** Keywords ***
3747
Remove .png Files
3848
Remove Files ${OUTPUTDIR}/*.png
@@ -42,4 +52,4 @@ Remove .png Files
4252
Verify That .png Files Do Not Exist
4353
File Should Not Exist ${OUTPUTDIR}/*.png
4454
File Should Not Exist ${EXECDIR}/*.png
45-
File Should Not Exist ${EXECDIR}/Embed/*.png
55+
File Should Not Exist ${EXECDIR}/EMBED/*.png

src/SeleniumLibrary/keywords/screenshot.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,10 @@ def _decide_embedded(self, filename):
185185
return False
186186

187187
def _get_screenshot_path(self, filename):
188-
directory = self._screenshot_root_directory or self.log_dir
188+
if self._screenshot_root_directory != EMBED:
189+
directory = self._screenshot_root_directory or self.log_dir
190+
else:
191+
directory = self.log_dir
189192
filename = filename.replace('/', os.sep)
190193
index = 0
191194
while True:

utest/test/keywords/test_screen_shot.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from os.path import dirname, abspath
1+
from os.path import dirname, abspath, join
22

33
import pytest
44
from mockito import mock, unstub
@@ -42,6 +42,13 @@ def test_file_name_embeded(screen_shot):
4242
assert screen_shot._decide_embedded(EMBED) is True
4343

4444

45+
def test_screenshot_path_embedded(screen_shot):
46+
screen_shot.ctx.screenshot_root_directory = EMBED
47+
assert screen_shot._get_screenshot_path('override.png') == join(
48+
screen_shot.log_dir, 'override.png'
49+
)
50+
51+
4552
def test_sl_init_embed():
4653
sl = SeleniumLibrary(screenshot_root_directory='EmBed')
4754
assert sl.screenshot_root_directory == EMBED

0 commit comments

Comments
 (0)