o
    fi                     @  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	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_buzIhttps://office.aroflo.com/ims/Site/Users/index.cfm?view=1&tid=IMS.MNG.USR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$   U/var/www/html/flask_server/apps/aroflo_connector_app/ui_automation/flows/users_nav.py_click_manage   s0   




r&   c              	   C  s   |  dj| jddd| jddd|  dj|  djg}|D ]}z| dkr*W q|jjd	d
d W  d
S  ty>   Y qw dS )Nz&a[data-aroflo-menuitem="manage-users"]r   Usersr   r   za:has-text('Users')z
text=Usersr   i  Tr   F)r   r   r   r   r   r   )r   r!   r"   r$   r$   r%   _click_users_option)   s    


r(   run_dirr   Nonec                 C  s  | j ddd t| | t| |d td|  t|d t|ddp#d }|rgtj| |||d t| | z	| j	d	d
d W n	 t
yH   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 td|  d S )Nz%() => location.href.includes('/ims/')i0u  r   zusers-step1-ims-readyzUsers: IMS readytimesheet_bu )	target_budomcontentloadedi:  i,  zusers-step1b-bu-applied-zUsers: BU applied: zusers-step2-manage-attemptzUsers: attempted to open Managezusers-step2b-users-not-found)
wait_untiliX  zusers-step3-users-direct-gotoz%Users: fallback direct goto Users URLa=  () => {
                const urlOk = location.href.toLowerCase().includes('/users/');
                const txt = document.body && document.body.innerText ? document.body.innerText : '';
                const txtOk = txt.includes('Users') || txt.includes('User');
                return urlOk || txtOk;
            }iȯ  zusers-step3-users-landingzUsers: landing reachednetworkidlei N  zusers-step4-users-stable)wait_for_functionr	   r   r   r   getattrstripr
   runwait_for_load_stater   r    r&   r(   goto	USERS_URL)r   cfgr)   r-   clickedr$   r$   r%   r4   >   sZ   









	

r4   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
   r7   r&   r(   r4   r$   r$   r$   r%   <module>   s   

