o
    uvXjä  ã                   @   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                       sL   e Zd Zg ZdZdZdZ‡ fdd„Zedd„ ƒZ	edd„ ƒZ
dd	„ Z‡  ZS )
ÚSeleniumTestCaseBaseNc           
         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   úQ/var/www/html/myproject/venv/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      s0   
üüzSeleniumTestCaseBase.__new__c                 C   s   t d| ƒS )Nz)selenium.webdriver.%s.webdriver.WebDriverr   )r$   r   r   r   r   Úimport_webdriver=   ó   z%SeleniumTestCaseBase.import_webdriverc                 C   s   ddl m} t|| ¡ ƒS )Nr   )ÚDesiredCapabilities)Ú.selenium.webdriver.common.desired_capabilitiesr/   ÚgetattrÚupper)r$   r   r/   r   r   r   Úget_capabilityA   s   z#SeleniumTestCaseBase.get_capabilityc                 C   s8   | j rddlm} |j| j |  | j¡d�S |  | j¡ƒ S )Nr   )Ú	webdriver)Úcommand_executorÚdesired_capabilities)r   Úseleniumr4   ÚRemoter3   r   r-   )Úselfr4   r   r   r   Úcreate_webdriverF   s   
þz%SeleniumTestCaseBase.create_webdriver)r!   r   Ú__qualname__r   r   r   r   r   Úclassmethodr-   r3   r:   Ú__classcell__r   r   r+   r   r	      s    (

r	   r7   c                       s\   e Zd ZdZdZedd„ ƒZedd„ ƒZe‡ fdd„ƒZ	e‡ f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_urlU   s   z SeleniumTestCase.live_server_urlc                 C   s   | j p| jS ©N)r   r   rB   r   r   r   Úallowed_hostY   r.   zSeleniumTestCase.allowed_hostc                    s&   |   ¡ | _| j | j¡ tƒ  ¡  d S rD   )r:   r7   Úimplicitly_waitÚimplicit_waitr   Ú
setUpClassrB   r+   r   r   rH   ]   s   
zSeleniumTestCase.setUpClassc                    s"   t | dƒr
| j ¡  tƒ  ¡  d S )Nr7   )Úhasattrr7   Úquitr   Ú_tearDownClassInternalrB   r+   r   r   rK   c   s   

z'SeleniumTestCase._tearDownClassInternalc              	   c   s:   � | j  d¡ zdV  W | j  | j¡ dS | j  | j¡ w )z"Disable the default implicit wait.r   N)r7   rF   rG   )r9   r   r   r   Údisable_implicit_waitl   s
   €"z&SeleniumTestCase.disable_implicit_wait)r!   r   r;   rG   r   r   rC   rE   r<   rH   rK   r   rL   r=   r   r   r+   r   r>   P   s    

r>   )Ú	metaclass)r   r"   Ú
contextlibr   Údjango.testr   r   Údjango.utils.decoratorsr   Údjango.utils.module_loadingr   Údjango.utils.textr   Útyper	   r>   r   r   r   r   Ú<module>   s    E