1. Sample script
from appium import webdriver
# After starting appium service, execute on appium service: start snowball app with caps parameter
driver = webdriver.Remote(command_executor="http://localhost:4723/wd/hub", # command_executor source code is the default local 4723 interface. If we run appium locally, it can be deleted in principle
desired_capabilities={
"platformName": "android", # Running on Android platform
"deviceName": "008640dd0804", # Run on 008xxx mobile device
"automationName": "uiautomator2", # Automation plug-ins used at the bottom
"appPackage": "com.xueqiu.android", # Which app is running
"appActivity": ".view.WelcomeActivityAlias", #
"autoGrantPermissions": "true" # app is allowed to obtain relevant permissions by default
})
# Click an element
el1 = driver.find_element_by_id("com.xueqiu.android:id/tv_agree")
el1.click()
# Add invisible wait
driver.implicitly_wait(60)
# Click an element
el2 = driver.find_element_by_xpath(
"/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.view.ViewGroup/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.RelativeLayout[1]/android.widget.RelativeLayout/android.widget.ViewFlipper/android.widget.LinearLayout/android.widget.TextView")
el2.click()
# Send text
el3 = driver.find_element_by_id("com.xueqiu.android:id/search_input_text")
el3.send_keys("alibaba")
# Exit app
driver.quit()
2,desired_ Analysis of capabilities parameters
2.1 global parameters:
- Platform name: which platform do you want to run on? You can set it to android
- automationName: must always be set to uiautomator2
- deviceName: the name of the device under test
- noReset: resets the device cleaning data. It is reset by default
- fullReset: full reset will uninstall the app under test. By default, it is not fully reset
- printPageSourceOnFindFailure: if an error is reported, dump the actual XML page source to the log
- Platform version: used for automatic device detection
- UDID: the UDID of the device to be tested. It can be retrieved from adb devices -l output. If not set, the driver will attempt to use the first connected device. If you run parallel tests, always set this feature.
2.2 driver and server parameters:
- Skippserverinstallation: skip the installation of UiAutomator2 server components and all related checks on the tested device. The default is false
- disableWindowAnimation: detect whether to disable window animation when starting the process. The default is false
- skipDeviceInitialization: set to true to cancel the device startup check during session creation, which can speed up session creation. The default is false
- systemPort: the port number on which the UiAutomator2 server is listening. By default, the first free port in the range of 8200... 8299 is selected. This value is recommended if you are running parallel tests on the same machine.
- uiautomator2ServerLaunchTimeout: the maximum number of milliseconds that UiAutomator2Server listens on the device. 30000 defaults to milliseconds
- uiautomator2ServerInstallTimeout: the maximum number of milliseconds to wait for UiAutomator2Server to be installed on the device. 20000 defaults to milliseconds
- Uiautomator2serverredtimeout: the maximum number of milliseconds to wait for an HTTP response from UiAutomator2Server.
2.3 App parameters:
- appActivity: the name of the main application activity
- appPackage: identifier of the application package
- autoLaunch: whether to automatically start the application under test after the test starts. The default is True
- autoGrantPermissions: automatically grant all requested application permissions at the beginning of the test. The default is False
- otherApps: set one or more comma separated Android package paths, which will be installed with the tested main application. If the application being tested has dependencies
- Uninstall other packages: allows you to set one or more comma separated package identifiers to uninstall from the device before the test starts
- enforceAppInstall: true, the application under test will always be reinstalled, even if a newer version of the application already exists on the device under test
- app: the full path of the application to be tested
- browserName: the name of the browser that ran the test
- appWaitActivity: wait for activity name
- appWaitPackage: wait for the package
- appWaitDuration: the maximum number of milliseconds to wait for the application under test to start
- Android installtimeout: the maximum number of milliseconds waiting to install the application under test
- appWaitForLaunch: whether to block until the application under test returns control to the caller after its activity is started by the activity manager (true, default), or continue the test without waiting (false).
- intentCategory: sets the optional intention category applied when starting a given appActivity through the Activity Manager
- intentAction: sets the optional intention action to be applied when starting a given appActivity through the Activity Manager
- intentFlags: sets the optional intention flag applied when starting a given appActivity through the Activity Manager
- Optional intent arguments: sets the optional intent parameters applied when the given appActivity is started by the Activity Manager
- dontStopAppOnReset: the application was restarted at runtime
- Allow test packages: packages built with the test flag are used for automated testing
- remoteAppsCacheLimit: sets the maximum number of application packages to be cached on the device under test
2.4 App localization parameters:
- Localscript: the specification name of the locale set for the application under test, such as zh Hans CN
- Language: the name of the language for which you want to extract the application string. The default is to extract the string for the current system language.
- Locale: set the locale of the application under test