

_V@                 @   sf   d  d l  Z  d  d l m Z d  d l m Z d  d l m Z d  d l m Z	 Gd d   d e  Z
 d S)    N)SkipTest)StaticLiveServerTestCase)import_string)ugettextc                   s  e  Z d  Z d d d d d g Z d Z e   f d d    Z e   f d	 d
    Z d d d  Z d d d d  Z	 d d d  Z
 d d d  Z d d d  Z d d d  Z d d   Z d d d  Z d d   Z d  d!   Z d" d#   Z d$ d%   Z   S)&AdminSeleniumWebDriverTestCasezdjango.contrib.adminzdjango.contrib.authzdjango.contrib.contenttypeszdjango.contrib.sessionszdjango.contrib.sitesz.selenium.webdriver.firefox.webdriver.WebDriverc                s   t  j j d d  s$ t d   n  y t |  j    |  _ WnD t k
 r } z$ t d |  j t |  f   WYd  d  } ~ Xn Xt	 t
 |   j   d  S)NZDJANGO_SELENIUM_TESTSFzSelenium tests not requestedz<Selenium webdriver "%s" not installed or not operational: %s)osenvirongetr   r   webdriver_classselenium	Exceptionstrsuperr   
setUpClass)clse)	__class__ </tmp/pip-build-ghmbqnp_/Django/django/contrib/admin/tests.pyr      s    ,z)AdminSeleniumWebDriverTestCase.setUpClassc                s6   t  |  d  r |  j j   n  t t |   j   d  S)Nr   )hasattrr   quitr   r   _tearDownClassInternal)r   )r   r   r   r       s    z5AdminSeleniumWebDriverTestCase._tearDownClassInternal
   c             C   s-   d d l  m } | |  j |  j |  d S)a=  
        Helper function that blocks the execution of the tests until the
        specified callback returns a value that is not falsy. This function can
        be called, for example, after clicking a link or submitting a form.
        See the other public methods that call this function for more details.
        r   )WebDriverWaitN)Zselenium.webdriver.support.waitr   r   Zuntil)selfcallbacktimeoutr   r   r   r   
wait_until&   s    z)AdminSeleniumWebDriverTestCase.wait_until   c                s    |  j    f d d   |  d S)z
        Block until `num_windows` are present (usually 2, but can be
        overridden in the case of pop-ups opening other pop-ups).
        c                s   t  |  j    k S)N)lenZwindow_handles)d)num_windowsr   r   <lambda>5   s    z?AdminSeleniumWebDriverTestCase.wait_for_popup.<locals>.<lambda>N)r   )r   r!   r   r   )r!   r   wait_for_popup0   s    z-AdminSeleniumWebDriverTestCase.wait_for_popupc             C   s   |  j  | |  d S)zu
        Helper function that blocks until the element with the given tag name
        is found on the page.
        N)wait_for)r   Ztag_namer   r   r   r   wait_loaded_tag7   s    z.AdminSeleniumWebDriverTestCase.wait_loaded_tagc             C   sF   d d l  m } d d l m } |  j | j | j | f  |  d S)zX
        Helper function that blocks until a CSS selector is found on the page.
        r   )By)expected_conditionsN)selenium.webdriver.common.byr&   selenium.webdriver.supportr'   r   Zpresence_of_element_locatedCSS_SELECTOR)r   css_selectorr   r&   ecr   r   r   r$   >   s
    z'AdminSeleniumWebDriverTestCase.wait_forc             C   sI   d d l  m } d d l m } |  j | j | j | f |  |  d S)zZ
        Helper function that blocks until the text is found in the CSS selector.
        r   )r&   )r'   N)r(   r&   r)   r'   r   Ztext_to_be_present_in_elementr*   )r   r+   textr   r&   r,   r   r   r   wait_for_textI   s    z,AdminSeleniumWebDriverTestCase.wait_for_textc             C   sI   d d l  m } d d l m } |  j | j | j | f |  |  d S)z[
        Helper function that blocks until the value is found in the CSS selector.
        r   )r&   )r'   N)r(   r&   r)   r'   r   Z#text_to_be_present_in_element_valuer*   )r   r+   r-   r   r&   r,   r   r   r   wait_for_valueU   s    z-AdminSeleniumWebDriverTestCase.wait_for_valuec             C   s:   d d l  m } y |  j d  Wn | k
 r5 Yn Xd S)z7
        Block until page has started to load.
        r   )TimeoutExceptionbodyN)selenium.common.exceptionsr0   r%   )r   r0   r   r   r   wait_page_loadeda   s
    z/AdminSeleniumWebDriverTestCase.wait_page_loadedz/admin/c             C   s   |  j  j d |  j | f  |  j  j d  } | j |  |  j  j d  } | j |  t d  } |  j  j d |  j   |  j   d S)z8
        Helper function to log into the admin.
        z%s%susernamepasswordzLog inz//input[@value="%s"]N)	r   r	   Zlive_server_urlZfind_element_by_nameZ	send_keys_Zfind_element_by_xpathZclickr3   )r   r4   r5   Z	login_urlZusername_inputZpassword_inputZ
login_textr   r   r   admin_logino   s    	z*AdminSeleniumWebDriverTestCase.admin_loginc             C   s   |  j  j d | | f  S)z
        Helper function that returns the value for the CSS attribute of an
        DOM element specified by the given selector. Uses the jQuery that ships
        with Django.
        z$return django.jQuery("%s").css("%s"))r   Zexecute_script)r   selector	attributer   r   r   get_css_value}   s    	z,AdminSeleniumWebDriverTestCase.get_css_valuec             C   sj   d d l  m } |  j j d |  } x' | D] } | j d  | k r- | Sq- W| d | | f   d S)z
        Returns the <OPTION> with the value `value` inside the <SELECT> widget
        identified by the CSS selector `selector`.
        r   )NoSuchElementExceptionz%s > optionvaluezOption "%s" not found in "%s"N)r2   r;   r   find_elements_by_css_selectorget_attribute)r   r8   r<   r;   optionsoptionr   r   r   get_select_option   s    z0AdminSeleniumWebDriverTestCase.get_select_optionc             C   sW   |  j  j d |  } g  } x$ | D] } | j | j d   q# W|  j | |  d S)z|
        Asserts that the <SELECT> widget identified by `selector` has the
        options with the given `values`.
        z%s > optionr<   N)r   r=   appendr>   ZassertEqual)r   r8   valuesr?   Zactual_valuesr@   r   r   r   assertSelectOptions   s
    z2AdminSeleniumWebDriverTestCase.assertSelectOptionsc             C   s(   |  j  j |  j d  j |  d k S)zi
        Returns True if the element identified by `selector` has the CSS class
        `klass`.
        class   )r   Zfind_element_by_css_selectorr>   find)r   r8   klassr   r   r   has_css_class   s    z,AdminSeleniumWebDriverTestCase.has_css_class)__name__
__module____qualname__Zavailable_appsr
   classmethodr   r   r   r#   r%   r$   r.   r/   r3   r7   r:   rA   rD   rJ   r   r   )r   r   r   	   s(   	
	r   )r   Zunittestr   Z"django.contrib.staticfiles.testingr   Zdjango.utils.module_loadingr   Zdjango.utils.translationr   r6   r   r   r   r   r   <module>   s
   