Skip to content

Commit 675de55

Browse files
committed
Update file-handling
1 parent 906246d commit 675de55

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

seleniumbase/fixtures/base_case.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,10 +1429,14 @@ def load_html_file(self, html_file, new_page=True):
14291429
if len(html_file) < 6 or not html_file.endswith(".html"):
14301430
raise Exception('Expecting a ".html" file!')
14311431
abs_path = os.path.abspath('.')
1432-
file_path = abs_path + "/%s" % html_file
1433-
f = open(file_path, 'r')
1434-
html_string = f.read().strip()
1435-
f.close()
1432+
file_path = None
1433+
if abs_path in html_file:
1434+
file_path = html_file
1435+
else:
1436+
file_path = abs_path + "/%s" % html_file
1437+
html_string = None
1438+
with open(file_path, 'r') as f:
1439+
html_string = f.read().strip()
14361440
self.load_html_string(html_string, new_page)
14371441

14381442
def open_html_file(self, html_file):
@@ -1768,9 +1772,9 @@ def load_cookies(self, name="cookies.txt"):
17681772
abs_path = os.path.abspath('.')
17691773
file_path = abs_path + "/%s" % folder
17701774
cookies_file_path = "%s/%s" % (file_path, name)
1771-
f = open(cookies_file_path, 'r')
1772-
json_cookies = f.read().strip()
1773-
f.close()
1775+
json_cookies = None
1776+
with open(cookies_file_path, 'r') as f:
1777+
json_cookies = f.read().strip()
17741778
cookies = json.loads(json_cookies)
17751779
for cookie in cookies:
17761780
if 'expiry' in cookie:

0 commit comments

Comments
 (0)