o
    ҷh                     @   st   d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlmZ d dl	m
Z
 d dlmZ eeZG dd dZdS )    N)Path)List)WebDriverException)BaseOptionsc                   @   sN   e Zd ZdZedefddZdedefddZ	ede
e defd	d
ZdS )SeleniumManagerzWrapper for getting information from the Selenium Manager binaries.

    This implementation is still in beta, and may change.
    returnc                  C   s   t d } durt| S tj}dddd}||r ||n|}|dkr(dnd}ttj||} | 	 s>t
d|  td	|  | S )
zDetermines the path of the correct Selenium Manager binary.

        :Returns: The Selenium Manager executable location
        SE_MANAGER_PATHNmacoswindows)darwinwin32cygwinzselenium-manager.exezselenium-managerz2Unable to obtain working Selenium Manager binary; z$Selenium Manager binary found at: %s)osgetenvr   sysplatformget__file__parentjoinpathis_filer   loggerdebug)pathr   dirs	directoryfile r   ]/var/www/html/venv/lib/python3.10/site-packages/selenium/webdriver/common/selenium_manager.py
get_binary%   s   zSeleniumManager.get_binaryoptionsc           
      C   s   |j d }t|  d|g}|jr|d |t|j t|dd}|r2|d |t| |j}|rP|js=|jrP|d |jrH|jn|j}|| | 	|}|d }|d	 }	t
d
|	 t|jdrq|rq||_d|_|	S )zDetermines the path of the correct driver.

        :Args:
         - browser: which browser to get the driver path for.
        :Returns: The driver path to use
        browserNamez	--browserz--browser-versionbinary_locationNz--browser-pathz--proxybrowser_pathdriver_pathzUsing driver at: %s)capabilitiesstrr   browser_versionappendgetattrproxy
http_proxy	ssl_proxyrunr   r   hasattr	__class__r"   )
selfr    browserargsr"   r*   valueoutputr#   r$   r   r   r   driver_locationC   s,   





zSeleniumManager.driver_locationr2   c           	   
   C   sB  t  tjkr| d | d | d d| }t d| z3tjdkr1t	j
| dt	jd}nt	j
| dd	}|jd
d}|jd
d}t|}|d }W n tyh } ztd| |d}~ww |d D ]"}|d dkr|t |d  |d dks|d dkrt |d  qm|jrtd| d| | |S )zExecutes the Selenium Manager Binary.

        :Args:
         - args: the components of the command being executed.
        :Returns: The log string containing the driver location.
        z--debugz--outputjson zExecuting process: %sr   T)capture_outputcreationflags)r8   zutf-8
resultzUnsuccessful command executed: NlogslevelWARNmessageDEBUGINFOz.
)r   getEffectiveLevelloggingr@   r(   joinr   r   r   
subprocessr-   CREATE_NO_WINDOWstdoutdecoderstripstderrr6   loads	Exceptionr   warning
returncode)	r2   commandcompleted_procrG   rJ   r4   r;   erritemr   r   r   r-   j   s6   





zSeleniumManager.runN)__name__
__module____qualname____doc__staticmethodr   r   r   r&   r5   r   dictr-   r   r   r   r   r      s    'r   )r6   rC   r   rE   r   pathlibr   typingr   selenium.commonr   !selenium.webdriver.common.optionsr   	getLoggerrS   r   r   r   r   r   r   <module>   s   
