a
    .c-9                     @   sV  d dl Z d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ dd	 Z	d
d Z
dd Zdd Zdd Zdd Zdd Zdd Zdd ZdIddZdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Z d9d: Z!d;d< Z"d=d> Z#d?d@ Z$dAdB Z%dCdD Z&dEdF Z'dGdH Z(dS )J    N)NoSuchElementException)NoSuchFrameException)StaleElementReferenceExceptionWebDriverException)NoAlertPresentException)
WebElementc                    s    fdd}|S )zAn expectation for checking the title of a page.
    title is the expected title, which must be an exact match
    returns True if the title matches, false otherwise.c                    s
   | j  kS Ntitledriverr
    h/var/www/brookimports/venv/lib/python3.9/site-packages/selenium/webdriver/support/expected_conditions.py
_predicate&   s    ztitle_is.<locals>._predicater   r   r   r   r
   r   title_is!   s    r   c                    s    fdd}|S )z An expectation for checking that the title contains a case-sensitive
    substring. title is the fragment of title expected
    returns True when the title matches, False otherwise
    c                    s
    | j v S r	   r
   r   r
   r   r   r   2   s    z"title_contains.<locals>._predicater   r   r   r
   r   title_contains,   s    r   c                    s    fdd}|S )z An expectation for checking that an element is present on the DOM
    of a page. This does not necessarily mean that the element is visible.
    locator - used to find the element
    returns the WebElement once it is located
    c                    s
   | j   S r	   )find_elementr   locatorr   r   r   ?   s    z/presence_of_element_located.<locals>._predicater   r   r   r   r   r   presence_of_element_located8   s    r   c                    s    fdd}|S )z An expectation for checking that the current url contains a
    case-sensitive substring.
    url is the fragment of url expected,
    returns True when the url matches, False otherwise
    c                    s
    | j v S r	   current_urlr   urlr   r   r   L   s    z url_contains.<locals>._predicater   r   r   r   r   r   url_containsE   s    r   c                    s    fdd}|S )zAn expectation for checking the current url.
    pattern is the expected pattern, which must be an exact match
    returns True if the url matches, false otherwise.c                    s   t t | jS r	   )boolresearchr   r   patternr   r   r   W   s    zurl_matches.<locals>._predicater   )r#   r   r   r"   r   url_matchesR   s    r$   c                    s    fdd}|S )zAn expectation for checking the current url.
    url is the expected url, which must be an exact match
    returns True if the url matches, false otherwise.c                    s
    | j kS r	   r   r   r   r   r   r   b   s    zurl_to_be.<locals>._predicater   r   r   r   r   	url_to_be]   s    r%   c                    s    fdd}|S )zAn expectation for checking the current url.
    url is the expected url, which must not be an exact match
    returns True if the url is different, false otherwise.c                    s
    | j kS r	   r   r   r   r   r   r   m   s    zurl_changes.<locals>._predicater   r   r   r   r   url_changesh   s    r&   c                    s    fdd}|S )a7   An expectation for checking that an element is present on the DOM of a
    page and visible. Visibility means that the element is not only displayed
    but also has a height and width that is greater than 0.
    locator - used to find the element
    returns the WebElement once it is located and visible
    c                    s*   zt | j  W S  ty$   Y dS 0 d S NF)_element_if_visibler   r   r   r   r   r   r   {   s    z1visibility_of_element_located.<locals>._predicater   r   r   r   r   visibility_of_element_locateds   s    r)   c                    s    fdd}|S )a3   An expectation for checking that an element, known to be present on the
    DOM of a page, is visible. Visibility means that the element is not only
    displayed but also has a height and width that is greater than 0.
    element is the WebElement
    returns the (same) WebElement once it is visible
    c                    s   t  S r	   r(   _elementr   r   r      s    z!visibility_of.<locals>._predicater   r.   r   r   r-   r   visibility_of   s    r0   Tc                 C   s   |   |kr| S dS r'   )Zis_displayed)r.   
visibilityr   r   r   r(      s    r(   c                    s    fdd}|S )z An expectation for checking that there is at least one element present
    on a web page.
    locator is used to find the element
    returns the list of WebElements once they are located
    c                    s
   | j   S r	   find_elementsr   r   r   r   r      s    z4presence_of_all_elements_located.<locals>._predicater   r   r   r   r    presence_of_all_elements_located   s    r4   c                    s    fdd}|S )z An expectation for checking that there is at least one element visible
    on a web page.
    locator is used to find the element
    returns the list of WebElements once they are located
    c                    s   dd | j   D S )Nc                 S   s   g | ]}t |r|qS r   r*   ).0r.   r   r   r   
<listcomp>       zJvisibility_of_any_elements_located.<locals>._predicate.<locals>.<listcomp>r2   r   r   r   r   r      s    z6visibility_of_any_elements_located.<locals>._predicater   r   r   r   r   "visibility_of_any_elements_located   s    r8   c                    s    fdd}|S )aI   An expectation for checking that all elements are present on the DOM of a
    page and visible. Visibility means that the elements are not only displayed
    but also has a height and width that is greater than 0.
    locator - used to find the elements
    returns the list of WebElements once they are located and visible
    c                    sH   z.| j   }|D ]}t|ddr W dS q|W S  tyB   Y dS 0 d S )NF)r1   )r3   r(   r   )r   elementsr.   r   r   r   r      s    

z6visibility_of_all_elements_located.<locals>._predicater   r   r   r   r   "visibility_of_all_elements_located   s    
r:   c                    s    fdd}|S )zn An expectation for checking if the given text is present in the
    specified element.
    locator, text
    c                    s0   z| j   j}|v W S  ty*   Y dS 0 d S r'   )r   textr   r   Zelement_textr   text_r   r   r      s
    
z1text_to_be_present_in_element.<locals>._predicater   r   r>   r   r   r=   r   text_to_be_present_in_element   s    r@   c                    s    fdd}|S )zl
    An expectation for checking if the given text is present in the element's value.
    locator, text
    c                    s4   z| j   d}|v W S  ty.   Y dS 0 d S )NvalueFr   get_attributer   r<   r=   r   r   r      s
    
z7text_to_be_present_in_element_value.<locals>._predicater   r?   r   r=   r   #text_to_be_present_in_element_value   s    rD   c                    s    fdd}|S )z{
    An expectation for checking if the given text is present in the element's attribute.
    locator, attribute, text
    c                    sH   z.t  | sW dS | j  }|v W S  tyB   Y dS 0 d S r'   )element_attribute_to_includer   rC   r   r<   
attribute_r   r>   r   r   r      s    
z;text_to_be_present_in_element_attribute.<locals>._predicater   )r   rG   r>   r   r   rF   r   'text_to_be_present_in_element_attribute   s    	rH   c                    s    fdd}|S )z An expectation for checking whether the given frame is available to
    switch to.  If the frame is available it switches the given driver to the
    specified frame.
    c                    sJ   z0t  dr | j| j   n| j  W dS  tyD   Y dS 0 d S )N__iter__TF)hasattr	switch_toframer   r   r   r   r   r   r      s    
z:frame_to_be_available_and_switch_to_it.<locals>._predicater   r   r   r   r   &frame_to_be_available_and_switch_to_it   s    
rM   c                    s    fdd}|S )z An Expectation for checking that an element is either invisible or not
    present on the DOM.

    locator used to find the element
    c              	      sB   z$ }t |ts| j| }t|dW S  ttfy<   Y dS 0 d S NFT)
isinstancer   r   r(   r   r   r   targetr   r   r   r     s    

z3invisibility_of_element_located.<locals>._predicater   r   r   r   r   invisibility_of_element_located
  s    rR   c                 C   s   t | S )z An Expectation for checking that an element is either invisible or not
    present on the DOM.

    element is either a locator (text) or an WebElement
    )rR   r-   r   r   r   invisibility_of_element"  s    rS   c                    s    fdd}|S )z
    An Expectation for checking an element is visible and enabled such that
    you can click it.

    element is either a locator (text) or an WebElement
    c                    s<    }t |ts| j| }t|| }|r4| r4|S dS d S r'   )rO   r   r   r0   
is_enabledrP   markr   r   r   5  s    

z+element_to_be_clickable.<locals>._predicater   )rV   r   r   rU   r   element_to_be_clickable+  s    

rW   c                    s    fdd}|S )z Wait until an element is no longer attached to the DOM.
    element is the element to wait for.
    returns False if the element is still attached to the DOM, true otherwise.
    c                    s(   z    W dS  ty"   Y dS 0 d S rN   )rT   r   r+   r-   r   r   r   H  s
    z staleness_of.<locals>._predicater   r/   r   r-   r   staleness_ofB  s    rX   c                    s    fdd}|S )z] An expectation for checking the selection is selected.
    element is WebElement object
    c                    s      S r	   is_selectedr+   r-   r   r   r   X  s    z*element_to_be_selected.<locals>._predicater   r/   r   r-   r   element_to_be_selectedS  s    r[   c                    s    fdd}|S )z^An expectation for the element to be located is selected.
    locator is a tuple of (by, path)c                    s   | j    S r	   )r   rZ   r   r   r   r   r   b  s    z2element_located_to_be_selected.<locals>._predicater   r   r   r   r   element_located_to_be_selected^  s    r\   c                    s    fdd}|S )z An expectation for checking if the given element is selected.
    element is WebElement object
    is_selected is a Boolean.
    c                    s      kS r	   rY   r+   r.   rZ   r   r   r   n  s    z1element_selection_state_to_be.<locals>._predicater   )r.   rZ   r   r   r]   r   element_selection_state_to_beh  s    r^   c                    s    fdd}|S )z An expectation to locate an element and check if the selection state
    specified is in that state.
    locator is a tuple of (by, path)
    is_selected is a boolean
    c                    s2   z| j  }|  kW S  ty,   Y dS 0 d S r'   )r   rZ   r   )r   r.   rZ   r   r   r   r   {  s
    
z9element_located_selection_state_to_be.<locals>._predicater   )r   rZ   r   r   r_   r   %element_located_selection_state_to_bet  s    r`   c                    s    fdd}|S )z@ An expectation for the number of windows to be a certain value.c                    s   t | j kS r	   lenZwindow_handlesr   num_windowsr   r   r     s    z+number_of_windows_to_be.<locals>._predicater   )rd   r   r   rc   r   number_of_windows_to_be  s    re   c                    s    fdd}|S )zd An expectation that a new window will be opened and have the number of
    windows handles increasec                    s   t | jt  kS r	   ra   r   current_handlesr   r   r     s    z(new_window_is_opened.<locals>._predicater   )rg   r   r   rf   r   new_window_is_opened  s    rh   c                  C   s   dd } | S )Nc                 S   s$   z
| j jW S  ty   Y dS 0 d S r'   )rK   alertr   r   r   r   r   r     s    
z$alert_is_present.<locals>._predicater   )r   r   r   r   alert_is_present  s    rj   c                    s    fdd}|S )zy An expectation for checking if the given attribute is included in the
    specified element.
    locator, attribute
    c                    s4   z| j   }|d uW S  ty.   Y dS 0 d S r'   rB   )r   Zelement_attributerG   r   r   r   r     s
    
z0element_attribute_to_include.<locals>._predicater   )r   rG   r   r   rk   r   rE     s    rE   c                     s    fdd}|S )z An expectation that any of multiple expected conditions is true.
    Equivalent to a logical 'OR'.
    Returns results of the first matching condition, or False if none do. c              	      s<    D ]2}z|| }|r |W   S W q t y4   Y q0 qdS r'   r   r   expected_conditionresultexpected_conditionsr   r   any_of_condition  s    z any_of.<locals>.any_of_conditionr   )rp   rq   r   ro   r   any_of  s    
rr   c                     s    fdd}|S )z An expectation that all of multiple expected conditions is true.
    Equivalent to a logical 'AND'.
    Returns: When any ExpectedCondition is not met: False.
    When all ExpectedConditions are met: A List with each ExpectedCondition's return value. c              	      sL   g } D ]>}z"|| }|s"W  dS | | W q tyD   Y  dS 0 q|S r'   )appendr   )r   resultsrm   rn   ro   r   r   all_of_condition  s    z all_of.<locals>.all_of_conditionr   )rp   ru   r   ro   r   all_of  s    rv   c                     s    fdd}|S )z An expectation that none of 1 or multiple expected conditions is true.
    Equivalent to a logical 'NOT-OR'.
    Returns a Boolean c              	      s:    D ]0}z|| }|rW  dS W q t y2   Y q0 qdS rN   r   rl   ro   r   r   none_of_condition  s    z"none_of.<locals>.none_of_conditionr   )rp   rw   r   ro   r   none_of  s    
rx   )T))r    Zselenium.common.exceptionsr   r   r   r   r   Z#selenium.webdriver.remote.webdriverr   r   r   r   r   r$   r%   r&   r)   r0   r(   r4   r8   r:   r@   rD   rH   rM   rR   rS   rW   rX   r[   r\   r^   r`   re   rh   rj   rE   rr   rv   rx   r   r   r   r   <module>   sL   
	
	

