File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77from webdriver_manager .chrome import ChromeDriverManager
88from webdriver_manager .firefox import GeckoDriverManager
99
10+
1011class DriverFactory :
1112 @staticmethod
1213 def get_driver (browser_name ):
1314 if browser_name .lower () == "chrome" :
1415 options = webdriver .ChromeOptions ()
15- options .add_argument ("--start-maximized " ) # Open in maximized mode
16+ options .add_argument ("--headless=new " ) # Run in headless mode
1617 options .add_argument ("--disable-gpu" ) # Disable GPU (fixes some rendering issues)
1718 options .add_argument ("--no-sandbox" ) # Bypass OS security model (for Docker/Linux)
1819 options .add_argument ("--disable-dev-shm-usage" ) # Prevent crashes in Docker/Linux
20+ options .add_argument ("--remote-debugging-port=9222" ) # Avoid session issues
21+ options .add_argument ("--user-data-dir=/tmp/chrome-user-data" ) # Unique session directory
1922 options .add_experimental_option ("excludeSwitches" , ["enable-automation" ]) # Avoid detection
2023 options .add_experimental_option ("useAutomationExtension" , False ) # Disable automation extension
2124
2225 return webdriver .Chrome (
2326 service = Service (ChromeDriverManager ().install ()), options = options
2427 )
28+
2529 elif browser_name .lower () == "firefox" :
2630 return webdriver .Firefox (service = Service (GeckoDriverManager ().install ()))
2731 else :
28- raise ValueError (f"Browser { browser_name } is not supported" )
32+ raise ValueError (f"Browser { browser_name } is not supported" )
You can’t perform that action at this time.
0 commit comments