File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change 77import warnings
88import percy
99import requests
10+ import tempfile
1011
1112from selenium import webdriver
1213from selenium .webdriver .support import expected_conditions as EC
@@ -500,6 +501,22 @@ def _get_chrome(self):
500501 options .add_argument ("--disable-gpu" )
501502 options .add_argument ("--remote-debugging-port=9222" )
502503
504+ if not self ._remote :
505+ try :
506+ # Create a TemporaryDirectory object.
507+ # It will be cleaned up when self._temp_user_data_dir_manager.cleanup() is called,
508+ # or when the object is garbage collected if not cleaned up explicitly.
509+ self ._temp_user_data_dir_manager = tempfile .TemporaryDirectory ()
510+ user_data_dir_path = self ._temp_user_data_dir_manager .name
511+ options .add_argument (f"--user-data-dir={ user_data_dir_path } " )
512+ logger .info (
513+ f"Chrome using temporary user data directory: { user_data_dir_path } "
514+ )
515+ except Exception as e :
516+ logger .error (
517+ f"Could not create temporary directory for user-data-dir: { e } "
518+ )
519+
503520 chrome = (
504521 webdriver .Remote (command_executor = self ._remote_url , options = options ) # type: ignore[reportAttributeAccessIssue]
505522 if self ._remote
You can’t perform that action at this time.
0 commit comments