Skip to content

Commit f8dacda

Browse files
committed
Fixed screenshot linking in logs
1 parent 53b6c7a commit f8dacda

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

src/Selenium2Library/keywords/_logging.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from robot.api import logger
44
from keywordgroup import KeywordGroup
55
from robot.libraries.BuiltIn import BuiltIn
6+
from robot.libraries.BuiltIn import RobotNotRunningError
67

78
class _LoggingKeywords(KeywordGroup):
89

@@ -12,12 +13,16 @@ def _debug(self, message):
1213
logger.debug(message)
1314

1415
def _get_log_dir(self):
15-
variables = BuiltIn().get_variables()
16+
try:
17+
variables = BuiltIn().get_variables()
1618

17-
logfile = variables['${LOG FILE}']
18-
if logfile != 'NONE':
19-
return os.path.dirname(logfile)
20-
return variables['${OUTPUTDIR}']
19+
logfile = variables['${LOG FILE}']
20+
if logfile != 'NONE':
21+
return os.path.dirname(logfile)
22+
return variables['${OUTPUTDIR}']
23+
24+
except RobotNotRunningError:
25+
return os.getcwd()
2126

2227
def _html(self, message):
2328
logger.info(message, True, False)

src/Selenium2Library/keywords/_screenshot.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
from Selenium2Library import utils
55
from keywordgroup import KeywordGroup
6-
from robot.libraries.BuiltIn import RobotNotRunningError
76

87

98
class _ScreenshotKeywords(KeywordGroup):
@@ -18,12 +17,13 @@ def __init__(self):
1817
def set_screenshot_directory(self, path, persist=False):
1918
"""Sets the root output directory for captured screenshots.
2019
21-
``path`` argument specifies the location to where the screenshots should
20+
``path`` argument specifies the absolute path where the screenshots should
2221
be written to. If the specified ``path`` does not exist, it will be created.
2322
Setting ``persist`` specifies that the given ``path`` should
2423
be used for the rest of the test execution, otherwise the path will be restored
2524
at the end of the currently executing scope.
2625
"""
26+
path = os.path.abspath(path)
2727
self._create_directory(path)
2828
if persist is False:
2929
self._screenshot_path_stack.append(self.screenshot_root_directory)
@@ -80,12 +80,7 @@ def _get_screenshot_directory(self):
8080
return self.screenshot_root_directory
8181

8282
# Otherwise use RF's log directory
83-
try:
84-
return self._get_log_dir()
85-
86-
# Unless robotframework isn't running, then use working directory
87-
except RobotNotRunningError:
88-
return os.getcwd()
83+
return self._get_log_dir()
8984

9085
# should only be called by set_screenshot_directory
9186
def _restore_screenshot_directory(self):
@@ -97,7 +92,9 @@ def _get_screenshot_paths(self, filename):
9792
filename = 'selenium-screenshot-%d.png' % self._screenshot_index
9893
else:
9994
filename = filename.replace('/', os.sep)
95+
10096
screenshotDir = self._get_screenshot_directory()
97+
logDir = self._get_log_dir()
10198
path = os.path.join(screenshotDir, filename)
102-
link = robot.utils.get_link_path(path, screenshotDir)
99+
link = robot.utils.get_link_path(path, logDir)
103100
return path, link

test/acceptance/keywords/screenshots.robot

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ Capture page screenshot to non-existing directory
3333
File Should Exist ${OUTPUTDIR}/screenshot/test-screenshot.png
3434

3535
Capture page screenshot to custom root directory
36-
[Setup] Remove Directory ${OUTPUTDIR}/screenshot recursive
37-
Set Screenshot Directory ${OUTPUTDIR}/screenshot
36+
[Setup] Remove Directory ${OUTPUTDIR}/custom-root recursive
37+
Set Screenshot Directory ${OUTPUTDIR}/custom-root
3838
Capture Page Screenshot custom-root-screenshot.png
39-
File Should Exist ${OUTPUTDIR}/screenshot/custom-root-screenshot.png
39+
File Should Exist ${OUTPUTDIR}/custom-root/custom-root-screenshot.png
4040

4141
Ensure screenshot captures revert to default root directory
4242
[Setup] Remove Files ${OUTPUTDIR}/default-root-screenshot.png

0 commit comments

Comments
 (0)