o
    ˜¨Êh	  ã                   @   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   úF/var/www/html/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   s:   |   | j¡ƒ }| jrzd|_W |S  ty   Y |S w |S )NT)r1   r   ÚheadlessÚAttributeError)ÚselfÚoptionsr   r   r   Úcreate_optionsO   s   þþz#SeleniumTestCaseBase.create_optionsc                 C   s@   | j rddlm} |j| j |  | j¡d�S |  | j¡|  ¡ d�S )Nr   )Ú	webdriver)Úcommand_executorÚdesired_capabilities)r:   )r   Úseleniumr<   ÚRemoter6   r   r/   r;   )r9   r<   r   r   r   Úcreate_webdriverX   s   
þz%SeleniumTestCaseBase.create_webdriver)r!   r   Ú__qualname__r   r   r   r   r7   r   Úclassmethodr/   r1   r6   r;   rA   Ú__classcell__r   r   r+   r   r	      s    *


	r	   r?   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_urlh   s   z SeleniumTestCase.live_server_urlc                 C   s   | j p| jS ©N)r   r   rI   r   r   r   Úallowed_hostl   r0   zSeleniumTestCase.allowed_hostc                    s&   |   ¡ | _| j | j¡ tƒ  ¡  d S rK   )rA   r?   Úimplicitly_waitÚimplicit_waitr   Ú
setUpClassrI   r+   r   r   rO   p   s   
zSeleniumTestCase.setUpClassc                    s"   t | dƒr
| j ¡  tƒ  ¡  d S )Nr?   )Úhasattrr?   Úquitr   Ú_tearDownClassInternalrI   r+   r   r   rR   v   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)r?   rM   rN   )r9   r   r   r   Údisable_implicit_wait   s
   €"z&SeleniumTestCase.disable_implicit_wait)r!   r   rB   rN   r   r   rJ   rL   rC   rO   rR   r   rS   rD   r   r   r+   r   rE   c   s    

rE   )Ú	metaclass)r   r"   Ú
contextlibr   Údjango.testr   r   Údjango.utils.functionalr   Údjango.utils.module_loadingr   Údjango.utils.textr   Útyper	   rE   r   r   r   r   Ú<module>   s    X