Manage Apps 1. Put the current app in the background
Once executed, the app will be placed in the background at a specific time. For example, this is 5 seconds, and after 5 seconds, the app will be back in the foreground.
Driver.background_app (5)
Official Website Example:
Driver.background_app (1) sleep (2= Driver.find_element_by_name ('Animation ') assertisnotnone (EL)
2. Check if the app is installed
Check that the device is currently installed with an app, which is checked by the app.
The parameters required here are the package name of the application, and the following is the name of the package that is known. The method returns TRUE or False.
driver.is_app_installed ('com.zhihu.android')
3. Install the App
Install an app on your device. parameter is the path to the app apk file.
Driver.install_app ('zhihu_521.apk')
In fact, the implementation is: adb install zhihu_521.apk
Official Website Example:
Assertfalse (driver.is_app_installed ('io.selendroid.testapp')) Driver.install_app ('/users/isaac/code/python-client/test/apps/selendroid-test-app.apk') Asserttrue (driver.is_app_installed ('io.selendroid.testapp'))
4. Uninstall the App
Uninstall an app on your device. parameter is the package name of the app.
Driver.remove_app ('com.zhihu.android')
In fact, the implementation is: ADB uninstall com.zhihu.android
Official Website Example:
Asserttrue (driver.is_app_installed ('com.example.android.apis')) driver.remove_ App ('com.example.android.apis') assertfalse (driver.is_app_installed ( ' Com.example.android.apis '))
5. Close the app
Close the app defined by Desired_caps.
Driver.close_app ()
6. Launch the App
Launches the app defined by the Desired_caps.
Driver.launch_app ()
Official Website Example:
el = driver.find_element_by_name ( " Animation " ) Assertisnotnone (EL) Driver.close_app (); try : Driver.find_element_by_name ( " animation " ) except Exception as E: pass # should not exist driver.launch_app () el = Driver.find_element_by_name (" animation " ) Assertisnotnone (EL)
7. Get the applied string
In practice, the session ID of the conversation is returned.
Driver.app_strings
Printed out, similar to the following results:
<bound method Webdriver.app_strings of <appium.webdriver.webdriver.webdriver (session=" Xxxxxxxxxxxxxxxxxxxxxxxxxxx") >>
8. Reset
Driver.reset ()
Official Website Example:
el = Driver.find_element_by_name ('App') El.click () Driver.reset () Sleep (5 = Driver.find_element_by_name ('App') assertisnotnone (EL)
Activity1. Get Current Activity
Driver.current_activity
For example, the following program:
fromAppiumImportWebdriverdesired_caps={}desired_caps['PlatformName'] ='Android'desired_caps['platformversion'] ='4.2.2'desired_caps['devicename'] ='Android Emulator'desired_caps['Apppackage'] ='com.zhihu.android'desired_caps['appactivity'] ='com.zhihu.android.app.ui.activity.MainActivity'Driver= Webdriver. Remote ('Http://localhost:4723/wd/hub', desired_caps) b=driver.current_activityPrint(b)
The results of the operation are as follows:
. app.ui.activity.MainActivity
2. Activate activity
Open an activity in the current app, or launch a new app and open an activity.
The first parameter here is the package name of the activity to start, and the second parameter is the activity name to start.
Driver.start_activity ('com.example.android.apis'. Foo')
For example, the following program:
#Coding=utf-8 fromAppiumImportWebdriverdesired_caps={}desired_caps['PlatformName'] ='Android'desired_caps['platformversion'] ='4.2.2'desired_caps['devicename'] ='Android Emulator'desired_caps['Apppackage'] ='com.zhihu.android'desired_caps['appactivity'] ='com.zhihu.android.app.ui.activity.MainActivity'Driver= Webdriver. Remote ('Http://localhost:4723/wd/hub', Desired_caps)Print(driver.current_activity) driver.start_activity ('Com.android.calculator2','. Calculator')Print(driver.current_activity)
The printing results are as follows:
. app.ui.activity.MainActivity.Calculator
You can see the activity at the beginning of the active or the known activity, after initiating the activity of the calculator, the current activity becomes the activity of the calculator.
Appium Python VI: Managing Apps and activity