o
    ÕèFhr  ã                   @   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/loop/nvenv/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