
    ^jK*                     ~    d dl mZmZ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 dlmZ ddlmZ  G d	 d
e
ee      Zy)    )AnyDictUnion)InvalidArgumentExceptionUnknownMethodException)Self)CanExecuteCommands)CanExecuteScripts)CanRememberExtensionPresence   )MobileCommandc            	           e Zd ZdedefdZdedefdZdede	defdZ
d	ede	defd
Zd	ede	defdZd	edefdZd	edefdZddeedf   deedf   deeef   fdZddZy)Applicationssecondsreturnc                     d}d|i}	 | j                  |      j                  ||       | S # t        $ r3 | j                  |      j	                  t
        j                  |       Y | S w xY w)a  Puts the application in the background on the device for a certain duration.

        Args:
            seconds: the duration for the application to remain in the background.
            Providing a negative value will continue immediately after putting the app
            under test to the background.

        Returns:
            Union['WebDriver', 'Applications']: Self instance
        zmobile: backgroundAppr   )assert_extension_existsexecute_scriptr   mark_extension_absenceexecuteCommand
BACKGROUND)selfr   ext_nameargss       \/home/ubuntu/.local/lib/python3.12/site-packages/appium/webdriver/extensions/applications.pybackground_appzApplications.background_app   st     +7#	T((2AA(DQ  & 	T''199':L:LdS	Ts   !+ 8A'&A'	bundle_idc                     d}	 | j                  |      j                  |||d      S # t        t        f$ r7 | j	                  |      j                  t        j                  d|i      d   cY S w xY w)zChecks whether the application specified by `bundle_id` is installed on the device.

        Args:
            bundle_id: the id of the application to query

        Returns:
            `True` if app is installed
        zmobile: isAppInstalled)bundleIdappIdr    value)r   r   r   r   r   r   r   IS_APP_INSTALLED)r   r   r   s      r   is_app_installedzApplications.is_app_installed/   s     ,	//9HH )&  '(@A 	..x8@@((	
  	   #( AA.-A.app_pathoptionsc                    d}	 | j                  |      j                  d||d|xs i        | S # t        t        f$ rL d|i}|r|j	                  d|i       | j                  |      j                  t        j                  |       Y | S w xY w)a  Install the application found at `app_path` on the device.

        Args:
            app_path: the local or remote path to the application to install

        Keyword Args:
            replace (bool): [Android only] whether to reinstall/upgrade the package if it is
                already present on the device under test. True by default
            timeout (int): [Android only] how much time to wait for the installation to complete.
                60000ms by default.
            allowTestPackages (bool): [Android only] whether to allow installation of packages marked
                as test in the manifest. False by default
            useSdcard (bool): [Android only] whether to use the SD card to install the app. False by default
            grantPermissions (bool): [Android only] whether to automatically grant application permissions
                on Android 6+ after the installation completes. False by default

        Returns:
            Union['WebDriver', 'Applications']: Self instance
        zmobile: installApp)appappPathr*   r'   )	r   r   r   r   updater   r   r   INSTALL_APP)r   r&   r'   r   datas        r   install_appzApplications.install_appJ   s    ( (	U((2AA$#' }"  '(@A 	U$-x#8DY01''199':M:MtT	U   *0 AB
Bapp_idc                    d}	 | j                  |      j                  |||d|xs i        | S # t        t        f$ rL d|i}|r|j	                  d|i       | j                  |      j                  t        j                  |       Y | S w xY w)a  Remove the specified application from the device.

        Args:
            app_id: the application id to be removed

        Keyword Args:
            keepData (bool): [Android only] whether to keep application data and caches after it is uninstalled.
                False by default
            timeout (int): [Android only] how much time to wait for the uninstall to complete.
                20000ms by default.

        Returns:
            Union['WebDriver', 'Applications']: Self instance
        zmobile: removeAppr!   r    r!   r'   )	r   r   r   r   r+   r   r   r   
REMOVE_APPr   r0   r'   r   r-   s        r   
remove_appzApplications.remove_appp   s     '	T((2AA# & }"  '(@A 	T$+V#4DY01''199':L:LdS	Tr/   c                    d}	 | j                  |      j                  |||d|xs i       S # t        t        f$ rN d|i}|r|j	                  d|i       | j                  |      j                  t        j                  |      d   cY S w xY w)ae  Terminates the application if it is running.

        Args:
            app_id: the application id to be terminates

        Keyword Args:
            `timeout` (int): [Android only] how much time to wait for the uninstall to complete.
                500ms by default.

        Returns:
            True if the app has been successfully terminated
        zmobile: terminateAppr2   r!   r'   r"   )	r   r   r   r   r+   r   r   r   TERMINATE_APPr4   s        r   terminate_appzApplications.terminate_app   s     *	g//9HH# & }"  '(@A 	g$+V#4DY01..x8@@AVAVX\]^eff	gs   ). AB
Bc                     d}	 | j                  |      j                  |||d       | S # t        t        f$ r5 | j	                  |      j                  t        j                  d|i       Y | S w xY w)zActivates the application if it is not running
        or is running in the background.

        Args:
            app_id: the application id to be activated

        Returns:
            Union['WebDriver', 'Applications']: Self instance
        zmobile: activateAppr2   r!   )r   r   r   r   r   r   r   ACTIVATE_APPr   r0   r   s      r   activate_appzApplications.activate_app   s     )
	c((2AA# &  '(@A 	c''199':N:NQXZ`Pab	cs   $* A A.-A.c                     d}	 | j                  |      j                  |||d      S # t        t        f$ r7 | j	                  |      j                  t        j                  d|i      d   cY S w xY w)zQueries the state of the application.

        Args:
            app_id: the application id to be queried

        Returns:
            One of possible application state constants. See ApplicationState
            class for more details.
        zmobile: queryAppStater2   r!   r"   )r   r   r   r   r   r   r   QUERY_APP_STATEr;   s      r   query_app_statezApplications.query_app_state   s     +	//9HH# &  '(@A 	..x8@@''V
  	r%   Nlanguagestring_filec                     d}i }|||d<   |||d<   	 | j                  |      j                  ||      S # t        $ r5 | j                  |      j	                  t
        j                  |      d   cY S w xY w)aI  Returns the application strings from the device for the specified
        language.

        Args:
            language: strings language code
            string_file: the name of the string file to query. Only relevant for XCUITest driver

        Returns:
            The key is string id and the value is the content.
        zmobile: getAppStringsr@   
stringFiler"   )r   r   r   r   r   r   GET_APP_STRINGS)r   r@   rA   r   r-   s        r   app_stringszApplications.app_strings   s     +'D"!,D	i//9HHSWXX% 	i..x8@@AXAXZ^_`ghh	is    5 ;A32A3c                    | j                   j                  t        j                  dd       | j                   j                  t        j                  dd       | j                   j                  t        j
                  dd       | j                   j                  t        j                  dd       | j                   j                  t        j                  dd       | j                   j                  t        j                  dd       | j                   j                  t        j                  dd       | j                   j                  t        j                  dd	       y )
NPOSTz)/session/$sessionId/appium/app/backgroundz//session/$sessionId/appium/device/app_installedz-/session/$sessionId/appium/device/install_appz,/session/$sessionId/appium/device/remove_appz//session/$sessionId/appium/device/terminate_appz./session/$sessionId/appium/device/activate_appz+/session/$sessionId/appium/device/app_statez&/session/$sessionId/appium/app/strings)command_executoradd_commandr   r   r#   r,   r3   r7   r:   r>   rD   )r   s    r   _add_commandszApplications._add_commands   s   ))'*<*<fFqr))$$=	

 	))'*=*=vGvw))'*<*<fFtu))!!=	

 	))  <	

 	))##9	

 	))'*A*A6Kst    )NN)r   N)__name__
__module____qualname__intr   r   strboolr$   r   r.   r5   r8   r<   r?   r   r   rE   rJ    rK   r   r   r      s    c d (# $ 6$C $C $D $L   BgC gC gD g<3 4 0c c 8iE#t)$4 i%PSUYPYJZ ifjknpsksft i.urK   r   N)typingr   r   r   selenium.common.exceptionsr   r   typing_extensionsr   /appium.protocols.webdriver.can_execute_commandsr	   .appium.protocols.webdriver.can_execute_scriptsr
   :appium.protocols.webdriver.can_remember_extension_presencer   mobilecommandr   r   r   rR   rK   r   <module>rZ      s6    $ # W " N L c 4xu%'8:V xurK   