@@ -708,27 +708,49 @@ def is_app_installed(self, bundle_id):
708708 }
709709 return self .execute (Command .IS_APP_INSTALLED , data )['value' ]
710710
711- def install_app (self , app_path ):
711+ def install_app (self , app_path , ** options ):
712712 """Install the application found at `app_path` on the device.
713713
714714 :Args:
715715 - app_path - the local or remote path to the application to install
716+ - options - the possible installation options.
717+ The following options are available for Android:
718+ `replace`: whether to reinstall/upgrade the package if it is
719+ already present on the device under test. True by default
720+ `timeout`: how much time to wait for the installation to complete.
721+ 60000ms by default.
722+ `allowTestPackages`: whether to allow installation of packages marked
723+ as test in the manifest. False by default
724+ `useSdcard`: whether to use the SD card to install the app. False
725+ by default
726+ `grantPermissions`: whether to automatically grant application permissions
727+ on Android 6+ after the installation completes. False by default
716728 """
717729 data = {
718730 'appPath' : app_path ,
719731 }
732+ if options :
733+ data .update ({'options' : options })
720734 self .execute (Command .INSTALL_APP , data )
721735 return self
722736
723- def remove_app (self , app_id ):
737+ def remove_app (self , app_id , ** options ):
724738 """Remove the specified application from the device.
725739
726740 :Args:
727741 - app_id - the application id to be removed
742+ - options - the possible removal options.
743+ The following options are available for Android:
744+ `keepData`: whether to keep application data and caches after it is uninstalled.
745+ False by default
746+ `timeout`: how much time to wait for the uninstall to complete.
747+ 20000ms by default.
728748 """
729749 data = {
730750 'appId' : app_id ,
731751 }
752+ if options :
753+ data .update ({'options' : options })
732754 self .execute (Command .REMOVE_APP , data )
733755 return self
734756
@@ -745,6 +767,54 @@ def close_app(self):
745767 self .execute (Command .CLOSE_APP )
746768 return self
747769
770+ def terminate_app (self , app_id , ** options ):
771+ """Terminates the application if it is running.
772+
773+ :Args:
774+ - app_id - the application id to be terminates
775+ - options - the possible termination options.
776+ The following options are available for Android:
777+ `timeout`: how much time to wait for the uninstall to complete.
778+ 500ms by default.
779+
780+ :return: True if the app has been successfully terminated
781+ """
782+ data = {
783+ 'appId' : app_id ,
784+ }
785+ if options :
786+ data .update ({'options' : options })
787+ return self .execute (Command .TERMINATE_APP , data )['value' ]
788+
789+ def activate_app (self , app_id ):
790+ """Activates the application if it is not running
791+ or is running in the background.
792+
793+ :Args:
794+ - app_id - the application id to be activated
795+
796+ :return: self instance for chaining
797+ """
798+ data = {
799+ 'appId' : app_id ,
800+ }
801+ self .execute (Command .ACTIVATE_APP , data )
802+ return self
803+
804+ def query_app_state (self , app_id ):
805+ """Queries the state of the application.
806+
807+ :Args:
808+ - app_id - the application id to be queried
809+
810+ :return: One of possible application state constants. See ApplicationState
811+ class for more details.
812+ """
813+ data = {
814+ 'appId' : app_id ,
815+ }
816+ return self .execute (Command .QUERY_APP_STATE , data )['value' ]
817+
748818 def start_activity (self , app_package , app_activity , ** opts ):
749819 """Opens an arbitrary activity during a test. If the activity belongs to
750820 another application, that application is started and the activity is opened.
@@ -1094,6 +1164,12 @@ def _addCommands(self):
10941164 ('POST' , '/session/$sessionId/appium/device/install_app' )
10951165 self .command_executor ._commands [Command .REMOVE_APP ] = \
10961166 ('POST' , '/session/$sessionId/appium/device/remove_app' )
1167+ self .command_executor ._commands [Command .TERMINATE_APP ] = \
1168+ ('POST' , '/session/$sessionId/appium/device/terminate_app' )
1169+ self .command_executor ._commands [Command .ACTIVATE_APP ] = \
1170+ ('POST' , '/session/$sessionId/appium/device/activate_app' )
1171+ self .command_executor ._commands [Command .QUERY_APP_STATE ] = \
1172+ ('GET' , '/session/$sessionId/appium/device/app_state' )
10971173 self .command_executor ._commands [Command .START_ACTIVITY ] = \
10981174 ('POST' , '/session/$sessionId/appium/device/start_activity' )
10991175 self .command_executor ._commands [Command .LAUNCH_APP ] = \
0 commit comments