a
    xd                     @   sl   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)SeleniumManagerException)BaseOptionsc                   @   sX   e Zd ZdZddddZeedddZee	dd	d
Z
eee	 e	dddZdS )SeleniumManagerzWrapper for getting information from the Selenium Manager binaries.

    This implementation is still in beta, and may change.
    N)returnc                 C   s   d S )N )selfr   r   b/var/www/html/Ranjet/env/lib/python3.9/site-packages/selenium/webdriver/common/selenium_manager.py__init__$   s    zSeleniumManager.__init__c                  C   sn   t j} dddd}|| r&|| n| }|dkr6dnd}ttj||}| sjd}t| d| |S )zDetermines the path of the correct Selenium Manager binary.

        :Returns: The Selenium Manager executable location
        ZmacosZwindows)darwinwin32cygwinzselenium-manager.exezselenium-managerz-https://github.com/SeleniumHQ/selenium/issuesz& is missing.  Please open an issue on )	sysplatformgetr   __file__parentjoinpathis_filer   )r   dirs	directoryfilepathtrackerr   r   r
   
get_binary'   s    zSeleniumManager.get_binary)optionsr   c                 C   s   t d |jd }t|  d|ddg}|jrJ|d |t|j t|dd}|rr|d	 |t| t  t	j
kr|d
 | |}|dd  }t d|  |S )z
        Determines the path of the correct driver.
        :Args:
         - browser: which browser to get the driver path for.
        :Returns: The driver path to use
        zOApplicable driver not found; attempting to install with Selenium Manager (Beta)ZbrowserNamez	--browserz--outputjsonz--browser-versionbinary_locationNz--browser-pathz--debug	zUsing driver at: )loggerinfoZcapabilitiesstrr   Zbrowser_versionappendgetattrgetEffectiveLevelloggingDEBUGrunsplitstripdebug)r	   r   Zbrowserargsr   result
executabler   r   r
   driver_locationA   s     





zSeleniumManager.driver_location)r-   r   c                 C   s   d | }td|  tj| tjtjd}|jdd}|j	dd}t
|}|d d }|jrtd| d	| | nF|d
 D ]8}|d dkrt|d  |d dkrt|d  q|S dS )z
        Executes the Selenium Manager Binary.
        :Args:
         - args: the components of the command being executed.
        :Returns: The log string containing the driver location.
         zExecuting process: )stdoutstderrzutf-8
r.   messagezSelenium Manager failed for: z.
ZlogslevelWARNr(   N)joinr!   r,   
subprocessr)   PIPEr2   decoderstripr3   r   loads
returncoder   warning)r-   commandZcompleted_procr2   r3   outputr.   itemr   r   r
   r)   `   s    

zSeleniumManager.run)__name__
__module____qualname____doc__r   staticmethodr   r   r   r#   r0   r   r)   r   r   r   r
   r      s   r   )r   r'   r9   r   pathlibr   typingr   Zselenium.common.exceptionsr   Z!selenium.webdriver.common.optionsr   	getLoggerrC   r!   r   r   r   r   r
   <module>   s   
