
    Fth                         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j        e          Z G d d          ZdS )    N)Path)List)WebDriverException)BaseOptionsc                   j    e Zd ZdZedefd            ZdedefdZ	ede
e         defd            ZdS )	SeleniumManagerzWrapper for getting information from the Selenium Manager binaries.

    This implementation is still in beta, and may change.
    returnc                     t          j        d          x} 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files        ~/var/www/html/mycamper/aliexpress-site/backend/venv/lib/python3.11/site-packages/selenium/webdriver/common/selenium_manager.py
get_binaryzSeleniumManager.get_binary%   s     I/000D=::|H ""# D /3hhx.@.@N***hI-6)-C-C))I[D>>(11)TBBD||~~ 	b$%`Z^%`%`aaa;TBBB    optionsc                    |j         d         }t          |                                           d|g}|j        r<|                    d           |                    t          |j                             t          |dd          }|r7|                    d           |                    t          |                     |j        }|rM|j        s|j        r?|                    d           |j        r|j        n|j        }|                    |           | 	                    |          }|d         }|d	         }	t                              d
|	           t          |j        d          r|r||_        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(   s
             r    driver_locationzSeleniumManager.driver_locationC   sw    &}5DOO%%&&W=" 	6KK+,,,KKG344555!'+<dCC 	.KK()))KKO,,--- 	e& 	%/ 	KK	"""',LEOOE<LEKK$n-]+*K8887$&788 	+\ 	+&2G#&*G#r"   r6   c                    t                                           t          j        k    r|                     d           |                     d           |                     d           d                    |           }t                               d|           	 t          j        dk    r"t          j
        | dt          j                  }nt          j
        | d	          }|j                            d
                              d          }|j                            d
                              d          }t!          j        |          }|d         }n%# t$          $ r}t'          d|           |d}~ww xY w|d         D ]f}|d         dk    r t                               |d                    |d         dk    s|d         dk    r t                               |d                    g|j        rt'          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)r=   zutf-8
resultzUnsuccessful command executed: NlogslevelWARNmessageDEBUGINFOz.
)r   getEffectiveLevelloggingrE   r,   joinr   r   r   
subprocessr1   CREATE_NO_WINDOWstdoutdecoderstripstderrr;   loads	Exceptionr   warning
returncode)	r6   commandcompleted_procrL   rO   r8   r@   erritems	            r    r1   zSeleniumManager.runj   s    ##%%66KK	"""JF((4..,g666
	[|w&&!+TYcYt!u!u!u!+T!J!J!J#*11'::AA$GGF#*11'::AA$GGFZ''FH%FF 	[ 	[ 	[$%Pw%P%PQQWZZ	[ 6N 	. 	.DG}&&tI///G}''4=F+B+BT)_---$ 	e$%cw%c%cSY%c[a%c%cddds   B>E 
E9!E44E9N)__name__
__module____qualname____doc__staticmethodr   r!   r   r*   r9   r   dictr1    r"   r    r   r      s         
     \:%{ %s % % % %N "$s) " " " " \" " "r"   r   )r;   rH   r   rJ   r   pathlibr   typingr   selenium.commonr   !selenium.webdriver.common.optionsr   	getLoggerrX   r   r   r^   r"   r    <module>rd      s   "   				     



             . . . . . . 9 9 9 9 9 9		8	$	$n n n n n n n n n nr"   