a
    7ñ»j;  ã                   @   s®   d Z ddlZddlZ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	lmZ dd
lmZ dZejdkrŽdZd Zej_G dd„ deƒZdS )zCBase Plugin for SeleniumBase tests that run with pynose / nosetestsé    N)Úsuppress)ÚPlugin)Úconfig)Úsettings)Údownload_helper)Ú
log_helper)Úreport_helper)Ú	constantsF)é   é   Tc                       sn   e Zd ZdZdZ‡ fdd„Z‡ fdd„Zdd„ Zd	d
„ Zdd„ Z	dd„ Z
ddd„Zddd„Zddd„Z‡  ZS )ÚBasea´  This plugin adds the following command-line options to pynose:
    --env=ENV  (Set the test env. Access with "self.env" in tests.)
    --account=STR  (Set account. Access with "self.account" in tests.)
    --data=STRING  (Extra test data. Access with "self.data" in tests.)
    --var1=STRING  (Extra test data. Access with "self.var1" in tests.)
    --var2=STRING  (Extra test data. Access with "self.var2" in tests.)
    --var3=STRING  (Extra test data. Access with "self.var3" in tests.)
    --variables=DICT  (Extra test data. Access with "self.variables".)
    --settings-file=FILE  (Override default SeleniumBase settings.)
    --ftrace | --final-trace  (Enter Debug Mode after any test ends.)
    --archive-logs  (Archive old log files instead of deleting them.)
    --archive-downloads  (Archive old downloads instead of deleting.)
    --report  (Create a fancy nosetests report after tests complete.)
    --show-report   If self.report is turned on, then the report will
                    display immediately after tests complete their run.
                    Only use this when running tests locally, as this will
                    pause the test run until the report window is closed.
    Ztesting_basec                    s   t ƒ j||d� |j|_|jdddtjjtjjtjjtjj	tjj
tjjtjjtjjtjjtjjtjjtjjtjjtjjtjjtjjtjjtjjtjjtjjtjjtjjtjjtjjftjjdd� |jddd d	d
� |jddd dd
� |jddd dd
� |jddd dd
� |jddd dd
� |jddd dd
� |jdddddd dd� |jdddd d!d"d#d$d� |jd%d&d'tjjd( d)d
� |jd*d+d!d,d#d-d� |jd.d/d!d0d#d1d� |jd2d!d3d#d4d� |jd5d6d!d7d#d8d� d#}t j!D ]}d9|v �sôd:|v �rÜd;}�qÜ|�rt"d<ƒ |jd:d=d>d?d
� d S )@N)Úenvz--envÚstoreÚenvironmentzvThis option sets a test env from a list of choices.
                    Access using "self.env" or "self.environment".)ÚactionÚdestÚchoicesÚdefaultÚhelpz	--accountÚaccountzjThis option sets a test account string.
                    In tests, use "self.account" to get the value.)r   r   r   z--dataÚdataz2Extra data to pass to tests from the command line.z--var1Úvar1z--var2Úvar2z--var3Úvar3z--variablesÚ	variablesa7  A var dict to pass to tests from the command line.
                    Example usage:
                    ----------------------------------------------
                    Option: --variables='{"special":123}'
                    Access: self.variables["special"]
                    ----------------------------------------------
                    Option: --variables='{"color":"red","num":42}'
                    Access: self.variables["color"]
                    Access: self.variables["num"]
                    ----------------------------------------------z--settings_filez--settings-filez
--settingsÚsettings_fileztThe file that stores key/value pairs for overriding
                    values in the SeleniumBase settings.py file.)r   r   r   r   z--final-debugz--final-tracez--fdebugz--ftraceÚ
store_trueÚfinal_debugFzýEnter Debug Mode at the end of each test.
                    To enter Debug Mode only on failures, use "--pdb".
                    If using both "--final-debug" and "--pdb" together,
                    then Debug Mode will activate twice on failures.z
--log_pathz
--log-pathÚlog_pathú/zx(DEPRECATED) - This field is NOT EDITABLE anymore.
                    Log files are saved to the "latest_logs/" folder.z--archive_logsz--archive-logsÚarchive_logsz/Archive old log files instead of deleting them.z--archive_downloadsz--archive-downloadsÚarchive_downloadsz/Archive old downloads instead of deleting them.z--reportÚreportz3Create a fancy report at the end of the test suite.z--show_reportz--show-reportÚshow_reportz;If true when using report, will display it after tests run.z--processes=z--processesTz6* WARNING: Don't use multi-threading with nosetests! *Z	processesr   z2WARNING: Don't use multi-threading with nosetests!)#ÚsuperÚoptionsÚ
add_optionZ	addoptionr	   ÚEnvironmentZQAÚRCZSTAGINGZDEVELOPZ
PRODUCTIONZPERFORMANCEZREPLICAZFEDRAMPZOFFLINEZONLINEZMASTERZREMOTEZLEGACYZLOCALZALPHAZBETAZDEMOZGDPRZMAINÚTESTZGOVZNEWZOLDZUATÚLogsÚLATESTÚsysÚargvÚprint)ÚselfÚparserr   Zfound_processes_argÚarg©Ú	__class__© úFE:\soccer\ml_env\Lib\site-packages\seleniumbase/plugins/base_plugin.pyr%   )   s   èá"üüüüüüù
ø
ûúúûú
üzBase.optionsc                    s˜   t ƒ  ||¡ d| _|| _|j| _|j| _g | _g | _t	dƒ| _
t	dƒ| _g | _d| _tjjd }|j}t ||¡ t ¡  dt_| jr”tjdd� d S )NTr   r   F)Zarchive_past_runs)r$   Ú	configureÚenabledr%   r"   Ú	report_onr#   Ú	successesÚfailuresÚfloatÚ
start_timeÚdurationÚpage_results_listÚ
test_countr	   r*   r+   r    r   Zlog_folder_setupr   Zreset_downloads_folderÚ	sb_configÚis_nosetestr   Zclear_out_old_report_logs)r/   r%   Zconfr   r    r2   r4   r5   r6   Ç   s$    

zBase.configurec                 C   s°  dt _| jj}|rˆt|tƒrˆt|ƒdkrˆd}| d¡r@| d¡sFd}n4zt	 
|¡}t|tƒs`d}W n tyx   d}Y n0 |rŒtdƒ‚ni }| ¡ |j_d|j_| jj|j_| jjt _| jj|j_| jj|j_| jjt _| jj|j_| jjt _| jj|j_| jjt _| jj|j_| jjt _| jj|j_| jjt _||j_|t _| jj|j_| jjt _| jj|j_| jj|j_| jj�r|dt_| j|j_| j |j_ |  j!d7  _!t"t# #¡ ƒ| _$d S )NFr   Ú{Ú}Tz^
Expecting a Python dictionary for "variables"!
Eg. --variables="{'KEY1':'VALUE', 'KEY2':123}"é   )%r@   Z_context_of_runnerr%   r   Ú
isinstanceÚstrÚlenÚ
startswithÚendswithÚastÚliteral_evalÚdictÚ	ExceptionÚidÚtestZtest_idrA   r   r   r   r   r   r   r   r   r   Z_final_debugr   r!   r   ZARCHIVE_EXISTING_DOWNLOADSÚargsr8   r?   r;   Útimer<   )r/   rO   r   Z	bad_inputr4   r4   r5   Ú
beforeTestÛ   sX    


ÿ









zBase.beforeTestc                 C   sZ   t  | jj| jj¡ t  ¡  | jrVt | j	¡ t 
¡ }t || j	| j| j| jj| j¡ d S ©N)r   Zarchive_logs_if_setr%   r   r    Zclear_empty_logsr8   r   Zadd_bad_page_log_filer>   Zarchive_new_report_logsZbuild_reportr9   r:   Zbrowserr#   )r/   ÚresultZreport_log_pathr4   r4   r5   Úfinalize  s    ÿúzBase.finalizec                 C   sT   | j rPtdtt ¡ ƒt| jƒ  ƒ| _| j | ¡ ¡ | j	 t
 || j| j¡¡ d S )Nú%.2fs)r8   rF   r;   rQ   r<   r=   r9   ÚappendrN   r>   r   Zprocess_successesr?   )r/   rO   Úcaptr4   r4   r5   Ú
addSuccess  s    ÿ
ÿÿzBase.addSuccessc                 C   s@  | j r`tdtt ¡ ƒt| jƒ  ƒ| _| ¡ dkr6d S | j | ¡ ¡ | j	 t
 || j| j¡¡ t�r<t�r<d t_ttƒ�: | ¡  | ¡  | ¡  | ¡ t_| ¡  W d   ƒ n1 sº0    Y  |t_d }d }ttdƒrâtj}ttdƒròtj}|�r|�rt |d |¡ d }ttdƒ�r"tj}|�r<|�r<t |d |¡ d S )NrV   znose.failure.Failure.runTestÚ_test_logpathÚ_last_page_sourceÚ_last_page_screenshot_png) r8   rF   r;   rQ   r<   r=   rN   r:   rW   r>   r   Zprocess_failuresr?   Úpython3_11_or_newerÚpy311_patch2r@   Z_browser_versionr   rM   Z#_BaseCase__set_last_page_screenshotZ_BaseCase__set_last_page_urlZ_BaseCase__set_last_page_sourceZ_get_browser_versionZ_log_fail_dataZ_excinfo_tbÚhasattrrZ   r[   r   Zlog_page_sourcer\   Zlog_screenshot)r/   rO   Úerrr   ÚsourceZlast_page_screenshot_pngr4   r4   r5   Úadd_fails_or_errors)  sH    ÿ
ÿÿ

&

ÿzBase.add_fails_or_errorsNc                 C   s   |   ||¡ d S rS   )rb   )r/   rO   r`   rX   Ztbinfor4   r4   r5   Ú
addFailureP  s    zBase.addFailurec                 C   sd   ddl m} |d |jks6|d |jks6|d |jkrTt|d  ¡  dd¡d ƒ n |  ||¡ dS )z°Since Skip, Blocked, and Deprecated are all technically errors,
        but not error states, we want to make sure that they
        don't show up in the nose output as errors.r   ©ÚerrorsrD   zF-------------------- >> begin captured logging << --------------------N)	Úseleniumbase.fixturesre   ÚBlockedTestÚSkipTestÚDeprecatedTestr.   Ú__str__Úsplitrb   )r/   rO   r`   rX   re   r4   r4   r5   ÚaddErrorS  s     ÿþýúùÿzBase.addErrorc                 C   sz   ddl m} ddlm} t|jdƒsv|d |jkr@||d ƒ‚n6|d |jkr\||d ƒ‚n|d |jkrv||d ƒ‚dS )z|After each test error, record testcase run information.
        "Error" also encompasses any states other than Pass or Fail.r   )rh   rd   Ztestcase_guidrD   N)Znose.excrh   rf   re   r_   rO   rg   ri   )r/   rO   r`   rX   rh   re   r4   r4   r5   ÚhandleErrorl  s    zBase.handleError)NN)N)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Únamer%   r6   rR   rU   rY   rb   rc   rl   rm   Ú__classcell__r4   r4   r2   r5   r      s    1'

r   )rq   rJ   r,   rQ   Ú
contextlibr   Znose.pluginsr   Zseleniumbaser   r@   Zseleniumbase.configr   Zseleniumbase.corer   r   r   rf   r	   r]   Úversion_infor^   Z
PatchPy311ÚPATCHr   r4   r4   r4   r5   Ú<module>   s    
