Skip to content

Commit 246de9e

Browse files
authored
Fix screenshot path issue when set screenshot directory (#74)
1 parent c50828d commit 246de9e

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

PuppeteerLibrary/keywords/screenshot.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@ class ScreenshotKeywords(LibraryComponent):
99

1010
def __init__(self, ctx):
1111
super().__init__(ctx)
12-
self.log_dir = os.curdir
1312

1413
def get_async_keyword_group(self) -> iScreenshotAsync:
1514
return self.ctx.get_current_library_context().get_async_keyword_group(type(self).__name__)
1615

1716
@keyword
1817
def set_screenshot_directory(self, path):
19-
self.log_dir = path
20-
if not os.path.exists(path):
21-
os.makedirs(path)
18+
self.ctx.get_current_library_context().set_screenshot_path(path)
19+
20+
@keyword
21+
def get_screenshot_directory(self):
22+
return self.ctx.get_current_library_context().get_screenshot_path()
2223

2324
@keyword
2425
def capture_page_screenshot(self, filename=DEFAULT_FILENAME_PAGE, fullPage=False):
@@ -41,7 +42,7 @@ def capture_page_screenshot(self, filename=DEFAULT_FILENAME_PAGE, fullPage=False
4142
self._embed_to_log_as_file(path, 800)
4243

4344
def _get_screenshot_path(self, filename):
44-
directory = self.log_dir
45+
directory = self.ctx.get_current_library_context().get_screenshot_path()
4546
filename = filename.replace('/', os.sep)
4647
index = 0
4748
while True:
@@ -62,7 +63,7 @@ def _embed_to_log_as_file(self, path, width):
6263
"""
6364
self.info('</td></tr><tr><td colspan="3">'
6465
'<a href="{src}"><img src="{src}" width="{width}px"></a>'
65-
.format(src=get_link_path(path, self.log_dir), width=width), html=True)
66+
.format(src=get_link_path(path, os.curdir), width=width), html=True)
6667

6768
class _SafeFormatter(dict):
6869

PuppeteerLibrary/library_context/ilibrary_context.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
from PuppeteerLibrary.custom_elements.base_page import BasePage
1+
import os
22
from abc import ABC, abstractmethod
3+
from PuppeteerLibrary.custom_elements.base_page import BasePage
34

45

56
class iLibraryContext(ABC):
67

78
browser_type: str = None
9+
screenshot_path: str = None
810
timeout: int = 30
911

1012
def __init__(self, browser_type: str):
1113
self.browser_type = browser_type
14+
self.screenshot_path = os.curdir
1215

1316
@abstractmethod
1417
async def start_server(self, options: dict=None):
@@ -53,3 +56,11 @@ async def close_window(self):
5356
@abstractmethod
5457
def get_async_keyword_group(self, keyword_group_name: str):
5558
pass
59+
60+
def set_screenshot_path(self, path: str):
61+
self.screenshot_path = path
62+
if not os.path.exists(self.screenshot_path):
63+
os.makedirs(self.screenshot_path)
64+
65+
def get_screenshot_path(self):
66+
return self.screenshot_path

0 commit comments

Comments
 (0)