U
    /ez                     @  s   d Z ddlmZ ddlZeeZddlmZm	Z	m
Z
mZmZmZ ddlmZ ddlZer~ddlZddlmZmZ ddlmZ dZd	d
dddddZejddd	ddddZejddd	ddddZdS )z0 Define a Pytest plugin for a log file fixture

    )annotationsN)TYPE_CHECKINGCallableIteratorListNoReturnSequence)warn)confignodes	WebDriver)driverhas_no_console_errorspytest_report_collectionfinishzconfig.Configzpy.path.localzSequence[nodes.Item]z	List[str])r
   startdiritemsreturnc                 C  s6   |  dd }|dkrdnd}dd|d| dgS )	z

    r   chromeONZOFF zBokeh selenium tests using z& driver (no-console-error assertions: )	getoptionlower)r
   r   r   driver_nameZasserts r   C/tmp/pip-unpacked-wheel-f5fndrjf/bokeh/_testing/plugins/selenium.pyr   8   s    r   session)ZscopezIterator[WebDriver])pytestconfigr   c                 c  s   |  dd }dddd}dddd}ddd	d
}|dkrJ| }n(|dkrZ| }n|dkrj| }ntd|d |V  |  dS )zG Select and configure a Selenium webdriver for integration tests.

    r   r   r   )r   c                  S  sF   ddl m}  ddlm} |  }|d |d |d ||dS )Nr   Optionsr   
--headlessz--no-sandbox--window-size=1920x1080options)Z!selenium.webdriver.chrome.optionsr!   Z#selenium.webdriver.chrome.webdriverr   add_argument)r!   ZChromer%   r   r   r   r   G   s    


zdriver.<locals>.chromec                  S  s<   ddl m}  ddlm} |  }|d |d ||dS )Nr   r    r   r"   r#   r$   )Z"selenium.webdriver.firefox.optionsr!   Z$selenium.webdriver.firefox.webdriverr   r&   )r!   ZFirefoxr%   r   r   r   firefoxP   s    

zdriver.<locals>.firefoxc                  S  s   ddl m}  |  S )Nr   r   )Z#selenium.webdriver.safari.webdriverr   )ZSafarir   r   r   safariX   s    zdriver.<locals>.safarir'   r(   z(expected 'chrome', 'firefox' or 'safari'
   N)r   r   
ValueErrorZimplicitly_waitquit)r   r   r   r'   r(   r   r   r   r   r   @   s    	
r   z&Callable[[WebDriver], bool | NoReturn]c                 C  s<   |  d }|dkr(ddddd}nddddd}|S )	a   Provide a function to assert no browser console errors are present.

    Unfortunately logs are only accessibly with Chrome web driver, see e.g.

        https://github.com/mozilla/geckodriver/issues/284

    For non-Chrome webdrivers this check always returns True.

    r   r   r   zbool | NoReturn)r   r   c                 S  s`   |  d}dd |D }dd |D }t|dkrPt|dkrLtd|  dS td| S )	NZbrowserc                 S  s   g | ]}| d dkr|qS )levelZSEVEREget).0xr   r   r   
<listcomp>{   s      z7has_no_console_errors.<locals>.func.<locals>.<listcomp>c                 S  s   g | ]}| d dkr|qS )typenetworkr-   )r/   lr   r   r   r1   |   s      r   zPThere were severe network errors (this may or may not have affected your test): TzConsole errors: )Zget_loglenr	   pytestZfail)r   ZlogsZsevere_errorsZnon_network_errorsr   r   r   funcy   s    
z#has_no_console_errors.<locals>.funcc                 S  s   dS )NTr   )r   r   r   r   r7      s    r   )r   r   r7   r   r   r   r   j   s
    r   )__doc__
__future__r   logging	getLogger__name__logtypingr   r   r   r   r   r   warningsr	   r6   pyZ_pytestr
   r   Z#selenium.webdriver.remote.webdriverr   __all__r   Zfixturer   r   r   r   r   r   <module>   s    
 

)
