o
    ei                     @  s   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	m
Z
 ddlmZ ddlmZ dd	lmZ d
ZdddZdddZdddZdS )    )annotations)Path)Page   )shot)log_steppause)handle_terminate_sessions)timesheet_select_bu)timesheet_select_userzVhttps://office.aroflo.com/ims/Site/Resource/Timesheet/Index.cfm?view=1&tid=IMS.MNG.TSTpager   returnboolc              	   C  s   | j ddd| j ddd| dj| dj| dj| djg}|D ]?}z4| d	kr/W q$t|d
r7|jn|}z|jdd W n	 tyJ   Y nw |jddd | d W  dS  tyc   Y q$w dS )NlinkManagenamebuttonztext=Managezspan:has-text('Manage')zdiv:has-text('Manage')zli:has-text('Manage')r   firsti  timeouti  Tr   force   F)	get_by_rolelocatorr   counthasattrhover	Exceptionclickwait_for_timeout)r   
candidatesloctarget r%   Y/var/www/html/flask_server/apps/aroflo_connector_app/ui_automation/flows/timesheet_nav.py_click_manage   s0   



	
r'   c              
   C  s   | j ddd| j ddd| j ddd| j ddd| dj| dj| dj| d	jg}|D ]}z| d
kr;W q0|jjddd W  dS  tyO   Y q0w dS )Nr   
Timesheetsr   	Timesheetr   za:has-text('Timesheets')za:has-text('Timesheet')ztext=Timesheetsztext=Timesheetr   i  Tr   F)r   r   r   r   r    r   )r   r"   r#   r%   r%   r&   _click_timesheets_option+   s&   



r*   run_dirr   Nonec                 C  s<  | j ddd t| | t| |d td|  t|d zt|dd }td||  W n	 ty5   Y nw t|ddp=d }|rtj	| |||d	 t| | z	| j
d
dd W n	 tyb   Y nw | d t| |d|  td| |  t|d|  t|  t| |d td|  t|d t| }|st| |d td|  | jtd
d | d t| |d td|  t|d n| j ddd t| |d td|  t|d z	| j
ddd W n	 ty   Y nw t|ddpd }t|ddpd }|s|rtj	| ||||d t| |d td|  d S ) Nz%() => location.href.includes('/ims/')i0u  r   zstep1-ims-readyz"Step 1: IMS ready (pre-navigation)timesheet_buzdebug-timesheet_bu= )	target_budomcontentloadedi:  i,  zstep1b-bu-applied-zStep 1B: BU applied: zstep2-manage-attemptz Step 2: attempted to open Managezstep2b-timesheets-not-found)
wait_untiliX  zstep3-timesheets-direct-gotoz)Fallback: went directly to Timesheets URLaI  () => {
                const urlOk = location.href.toLowerCase().includes('timesheet');
                const txt = document.body && document.body.innerText ? document.body.innerText : '';
                const txtOk = txt.includes('Timesheet') || txt.includes('Timesheets');
                return urlOk || txtOk;
            }iȯ  zstep3-timesheets-landingz"Step 3: Timesheets landing reachednetworkidlei N  timesheet_user_idtimesheet_user_name)user_id	user_namezstep4-timesheets-stable)wait_for_functionr	   r   r   r   getattrr   stripr
   runwait_for_load_stater!   r'   r*   gotoTIMESHEETS_URLr   )r   cfgr+   vr/   clickeduidunamer%   r%   r&   r:   B   sz   









	

	r:   N)r   r   r   r   )r   r   r+   r   r   r,   )
__future__r   pathlibr   playwright.sync_apir   core.artifactsr   core.logr   r   auth.post_loginr	   flowsr
   r   r=   r'   r*   r:   r%   r%   r%   r&   <module>   s   

