22from abc import ABC , abstractmethod
33
44from selenium import webdriver
5- from selenium .common import WebDriverException
65from selenium .webdriver .chrome .service import Service as ChromeService
76from selenium .webdriver .remote .remote_connection import RemoteConnection
87from webdriver_manager .chrome import ChromeDriverManager
98
10- from driver .driver_options import _init_driver_options
9+ from core .driver_options import _init_driver_options
10+ from utils .error_handler import ErrorHandler , ErrorType
1111from utils .logger import Logger , LogLevel
1212from properties import Properties
1313from utils .yaml_reader import YamlReader
1616
1717
1818def _get_driver_path (driver_type = None ):
19- # Check if driver_type is provided
2019 if driver_type is None :
21- raise ValueError ( "Driver type must be specified." )
20+ ErrorHandler . raise_error ( ErrorType . UNSUPPORTED_DRIVER_TYPE )
2221
2322 project_dir = os .path .dirname (
24- os .path .dirname (os .path .dirname (os .path .abspath (__file__ )))
25- )
23+ os .path .dirname (os .path .dirname (os .path .abspath (__file__ ))))
2624 driver_path = os .path .join (project_dir , "resources" , driver_type )
2725
28- # Check if the driver file exists
2926 if not os .path .exists (driver_path ):
30- raise WebDriverException (
31- f"WebDriver binary not found at { driver_path } . "
32- f"Please ensure it exists the driver { driver_type } in directory."
33- )
27+ ErrorHandler .raise_error (ErrorType .DRIVER_NOT_FOUND , driver_type )
3428
3529 return driver_path
3630
@@ -57,11 +51,13 @@ def create_driver(self, environment=None, dr_type=None):
5751 """Tries to use ChromeDriverManager to install the latest driver,
5852 and if it fails, it falls back to a locally stored driver in resources."""
5953 try :
60- driver_path = ChromeDriverManager ().install () # No need for ChromeType
54+ log .info (f"Run local chrome driver" )
55+ driver_path = ChromeDriverManager ().install ()
6156 driver = webdriver .Chrome (
62- service = ChromeService (executable_path = driver_path ))
57+ service = ChromeService (executable_path = driver_path ),
58+ options = _init_driver_options (dr_type = dr_type ))
6359 except Exception as e :
64- log .error (f"Run local driver: { e } " )
60+ log .info (f"Run local driver: { e } " )
6561 driver = webdriver .Chrome (
6662 service = ChromeService (_get_driver_path (dr_type )),
6763 options = _init_driver_options (dr_type = dr_type ),
0 commit comments