@@ -4308,25 +4308,8 @@ def save_cookies(self, name="cookies.txt"):
4308
4308
4309
4309
def load_cookies(self, name="cookies.txt"):
4310
4310
"""Loads the page cookies from the "saved_cookies" folder."""
4311
+ cookies = self.get_saved_cookies(name)
4311
4312
self.wait_for_ready_state_complete()
4312
- if name.endswith("/"):
4313
- raise Exception("Invalid filename for Cookies!")
4314
- if "/" in name:
4315
- name = name.split("/")[-1]
4316
- if "\\" in name:
4317
- name = name.split("\\")[-1]
4318
- if len(name) < 1:
4319
- raise Exception("Filename for Cookies is too short!")
4320
- if not name.endswith(".txt"):
4321
- name = name + ".txt"
4322
- folder = constants.SavedCookies.STORAGE_FOLDER
4323
- abs_path = os.path.abspath(".")
4324
- file_path = os.path.join(abs_path, folder)
4325
- cookies_file_path = os.path.join(file_path, name)
4326
- json_cookies = None
4327
- with open(cookies_file_path, "r") as f:
4328
- json_cookies = f.read().strip()
4329
- cookies = json.loads(json_cookies)
4330
4313
for cookie in cookies:
4331
4314
if "expiry" in cookie:
4332
4315
del cookie["expiry"]
@@ -4363,6 +4346,46 @@ def delete_saved_cookies(self, name="cookies.txt"):
4363
4346
if cookies_file_path.endswith(".txt"):
4364
4347
os.remove(cookies_file_path)
4365
4348
4349
+ def get_saved_cookies(self, name="cookies.txt"):
4350
+ """Gets the page cookies from the "saved_cookies" folder."""
4351
+ if name.endswith("/"):
4352
+ raise Exception("Invalid filename for Cookies!")
4353
+ if "/" in name:
4354
+ name = name.split("/")[-1]
4355
+ if "\\" in name:
4356
+ name = name.split("\\")[-1]
4357
+ if len(name) < 1:
4358
+ raise Exception("Filename for Cookies is too short!")
4359
+ if not name.endswith(".txt"):
4360
+ name = name + ".txt"
4361
+ folder = constants.SavedCookies.STORAGE_FOLDER
4362
+ abs_path = os.path.abspath(".")
4363
+ file_path = os.path.join(abs_path, folder)
4364
+ cookies_file_path = os.path.join(file_path, name)
4365
+ json_cookies = None
4366
+ with open(cookies_file_path, "r") as f:
4367
+ json_cookies = f.read().strip()
4368
+ return json.loads(json_cookies)
4369
+
4370
+ def get_cookie(self, name):
4371
+ return self.driver.get_cookie(name)
4372
+
4373
+ def get_cookies(self):
4374
+ return self.driver.get_cookies()
4375
+
4376
+ def add_cookie(self, cookie_dict):
4377
+ """Usage examples:
4378
+ self.add_cookie({'name': 'foo', 'value': 'bar'})
4379
+ self.add_cookie({'name': 'foo', 'value': 'bar', 'path': '/'})
4380
+ self.add_cookie({'name': 'foo', 'value': 'bar', 'secure': True})
4381
+ self.add_cookie({'name': 'foo', 'value': 'bar', 'sameSite': 'Strict'})
4382
+ """
4383
+ self.driver.add_cookie(cookie_dict)
4384
+
4385
+ def add_cookies(self, cookies):
4386
+ for cookie_dict in cookies:
4387
+ self.driver.add_cookie(cookie_dict)
4388
+
4366
4389
def wait_for_ready_state_complete(self, timeout=None):
4367
4390
"""Waits for the "readyState" of the page to be "complete".
4368
4391
Returns True when the method completes."""
@@ -8718,6 +8741,14 @@ def clear_all_cookies(self):
8718
8741
"""Same as self.delete_all_cookies()"""
8719
8742
self.delete_all_cookies()
8720
8743
8744
+ def delete_local_storage(self):
8745
+ """Same as self.clear_local_storage()"""
8746
+ self.clear_local_storage()
8747
+
8748
+ def delete_session_storage(self):
8749
+ """Same as clear_session_storage()"""
8750
+ self.clear_session_storage()
8751
+
8721
8752
def assert_no_broken_links(self, multithreaded=True):
8722
8753
"""Same as self.assert_no_404_errors()"""
8723
8754
self.assert_no_404_errors(multithreaded=multithreaded)
0 commit comments