o
    )ifr                     @   s   d dl Z d dlZd dlmZ d dlmZmZ d dlmZ d dl	m
Z
 d dlmZ G dd deeZed	G d
d deedZdS )    N)contextmanager)LiveServerTestCasetag)classpropertyimport_string)capfirstc                       sd   e Zd Zg ZdZdZdZdZ fddZe	dd Z
e	dd Ze	d	d
 Zdd Zdd Z  ZS )SeleniumTestCaseBaseNFc           
         s   t  | |||}|jstdd | D s|S |jrb|jd }||_|js*|jnd}||_| j|_t	j
|j }|jdd D ]}| | dt||f |f||| j|jd}	t||	j|	 q@|S td	|S )
z
        Dynamically create new classes and add them to the test module when
        multiple browsers specs are provided (e.g. --selenium=firefox,chrome).
        c                 s   s&    | ]\}}| d ot|V  qdS )testN)
startswithcallable).0namevalue r   M/var/www/html/corbot_env/lib/python3.10/site-packages/django/test/selenium.py	<genexpr>   s    
z/SeleniumTestCaseBase.__new__.<locals>.<genexpr>r   z0.0.0.0   Nz%s%s)browserhostexternal_host
__module__zNo browsers specified.)super__new__r   anyitemsbrowsersselenium_hubr   r   sysmodulesr   r   setattr__name__unittestskip)
clsr   basesattrs
test_classfirst_browserr   moduler   browser_test_class	__class__r   r   r      s4   
zSeleniumTestCaseBase.__new__c                 C      t d| S )Nz)selenium.webdriver.%s.webdriver.WebDriverr   r$   r   r   r   r   import_webdriverA      z%SeleniumTestCaseBase.import_webdriverc                 C   r-   )Nz%selenium.webdriver.%s.options.Optionsr   r.   r   r   r   import_optionsE   r0   z#SeleniumTestCaseBase.import_optionsc                 C   s   ddl m} t|| S )Nr   )DesiredCapabilities).selenium.webdriver.common.desired_capabilitiesr2   getattrupper)r$   r   r2   r   r   r   get_capabilityI   s   z#SeleniumTestCaseBase.get_capabilityc                 C   sH   |  | j }| jr"| j dkr |d |S dkr"|d |S |S )Nchromez--headless=newfirefoxz	-headless)r1   r   headlessadd_argument)selfoptionsr   r   r   create_optionsO   s   


z#SeleniumTestCaseBase.create_optionsc                 C   sb   |   }| jr(ddlm} | | j D ]
\}}||| q|j| j|dS | 	| j|dS )Nr   )	webdriver)command_executorr<   )r<   )
r=   r   seleniumr>   r6   r   r   set_capabilityRemoter/   )r;   r<   r>   keyr   r   r   r   create_webdriverY   s   z%SeleniumTestCaseBase.create_webdriver)r!   r   __qualname__r   r   r   r   r9   r   classmethodr/   r1   r6   r=   rD   __classcell__r   r   r+   r   r	      s    *



r	   r@   c                       sX   e Zd ZdZdZedd Zedd Ze fddZ	ed	d
 Z
edd Z  ZS )SeleniumTestCase
   Nc                 C   s   d| j p| j| jjf S )Nzhttp://%s:%s)r   r   server_threadportr$   r   r   r   live_server_urlj   s   z SeleniumTestCase.live_server_urlc                 C   s   | j p| jS N)r   r   rL   r   r   r   allowed_hostn   r0   zSeleniumTestCase.allowed_hostc                    s2   |   | _| j| j t   | | j d S rN   )rD   r@   implicitly_waitimplicit_waitr   
setUpClassaddClassCleanup_quit_seleniumrL   r+   r   r   rR   r   s   

zSeleniumTestCase.setUpClassc                 C   s   t | dr| j  d S d S )Nr@   )hasattrr@   quitrL   r   r   r   rT   y   s   
zSeleniumTestCase._quit_seleniumc              	   c   s:    | j d zdV  W | j | j dS | j | j w )z"Disable the default implicit wait.r   N)r@   rP   rQ   )r;   r   r   r   disable_implicit_wait   s
   "z&SeleniumTestCase.disable_implicit_wait)r!   r   rE   rQ   r   r   rM   rO   rF   rR   rT   r   rW   rG   r   r   r+   r   rH   e   s    


rH   )	metaclass)r   r"   
contextlibr   django.testr   r   django.utils.functionalr   django.utils.module_loadingr   django.utils.textr   typer	   rH   r   r   r   r   <module>   s    Z