U
    a                     @   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 s2|S |jr|jd }||_|jsT|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   /home/adriano.carvalho/ftp/files/BrinquedotecaVirtual/brinquedotecavirtual/venv/lib/python3.8/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attrsZ
test_classZfirst_browserr   moduler   Z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?   s    z%SeleniumTestCaseBase.import_webdriverc                 C   s   t d| S )Nz%selenium.webdriver.%s.options.Optionsr   r*   r   r   r   import_optionsC   s    z#SeleniumTestCaseBase.import_optionsc                 C   s   ddl m} t|| S )Nr   )DesiredCapabilities)Z.selenium.webdriver.common.desired_capabilitiesr-   getattrupper)r$   r   r-   r   r   r   get_capabilityG   s    z#SeleniumTestCaseBase.get_capabilityc                 C   s8   |  | j }| jr4z
d|_W n tk
r2   Y nX |S )NT)r,   r   headlessAttributeError)selfoptionsr   r   r   create_optionsL   s    
z#SeleniumTestCaseBase.create_optionsc                 C   s@   | j r*ddlm} |j| j | | jdS | | j|  dS )Nr   )	webdriver)Zcommand_executorZdesired_capabilities)r4   )r   seleniumr6   ZRemoter0   r   r+   r5   )r3   r6   r   r   r   create_webdriverU   s    
z%SeleniumTestCaseBase.create_webdriver)r!   r   __qualname__r   r   r   r   r1   r   classmethodr+   r,   r0   r5   r8   __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   Zserver_threadportr$   r   r   r   live_server_urld   s    z SeleniumTestCase.live_server_urlc                 C   s   | j p
| jS N)r   r   r?   r   r   r   allowed_hosth   s    zSeleniumTestCase.allowed_hostc                    s&   |   | _| j| j t   d S rA   )r8   r7   implicitly_waitimplicit_waitr   
setUpClassr?   r(   r   r   rE   l   s    
zSeleniumTestCase.setUpClassc                    s"   t | dr| j  t   d S )Nr7   )hasattrr7   quitr   _tearDownClassInternalr?   r(   r   r   rH   r   s    

z'SeleniumTestCase._tearDownClassInternalc              	   c   s,   | j d z
dV  W 5 | j | j X dS )z"Disable the default implicit wait.r   N)r7   rC   rD   )r3   r   r   r   disable_implicit_wait{   s    
z&SeleniumTestCase.disable_implicit_wait)r!   r   r9   rD   r   r   r@   rB   r:   rE   rH   r   rI   r;   r   r   r(   r   r<   _   s   

r<   )	metaclass)r   r"   
contextlibr   Zdjango.testr   r   Zdjango.utils.decoratorsr   Zdjango.utils.module_loadingr   Zdjango.utils.textr   typer	   r<   r   r   r   r   <module>   s   T