1.What is Appium
appium is an open source test automation framework that can be used with native, hybrid and mobile web applications all the time. It uses the WebDriver protocol to drive IOS (built-in test engine xcuitest), Android (uiautomator2, Espresso) and Windows applications
Native applications: Android programs are developed using JAVA or kotlin, this kind of program is a native application, native applications are more fluent, good call, the disadvantage is that different ends of the need for different development languages
web application: on the web application can be put directly into the cell phone to run, web is written in html + css + js
Hybrid apps: a combination of native and web apps, some pages use native and some pages use web apps
The more famous framework in China:
- appium
- airtest is now maintained by Ali, and was first used in game testing, similar to the function of appium
- uiautomator2 (simple usage, very python, only native support, nothing else)
Design Philosophy:
- You don't need to recompile your app or modify it in any way for automation (Android/IOS comes with its own framework)
- You shouldn't be limited to writing runtime tests (API calls, interfaces) in a specific language or framework
- Mobile automation frameworks should not reinvent the wheel when it comes to automation interfaces (WebDriver, appium is based on selenium)
- Mobile automation frameworks should be open-sourced, not only in name but also in spirit and in practice
2. Steps to start an app automation program
Open the emulator, or connect to the phone (note that the developer mode as well as the USB debugging mode has been turned on, and the phone authorization should be confirmed, otherwise it will not connect)
Type adb devices in the command window (to see the device name)
Enabling the appium service appium client code to connect to the service
Service Introduction
Chinese Settings
In addition to the simple settings, there are some advanced settings that we can look at
Saved to view presets for later use
Editing the configuration is into modifying environment variables
The host and port numbers do not need to be set and the server can be turned on directly
Once turned on, you can see the server running. The three buttons on the right have the functions of starting the inspector session, getting the raw logs, and stopping the server from running.
After clicking on it, it will be opened automatically by Notepad. If you have other editing software installed, you can choose how to open it.
Once the service is turned on, you can use python to do a client to connect to the service
4. appium client use
Make sure you have it installed before you use it, pip install appium-python-client, and after you install it, import it directly to use it.
Take a look at Remote's source code
Also the appium server displays a 500 error
Hesitation appium1.20.2 version, unlike the previous version of the must be passed into the parameter more, now only need to pass platformName can be, so you can look at their own installation of what version, but plus more parameters are not affected!
Commonly used caps parameter:
- platformName Platform name (Android, IOS)
- Required deviceName Device name (optional)
- udid (same as deviceName, this parameter works better in different versions, so use udid instead of deviceName in the future)
- Path where the app apk is stored (optional)
- appActivity (page name, equivalent to title in web pages) and appPackage (package name)
- platformVersion system version number (optional, version mismatch will report error)
- noReset Select True not to restart (meaning that the app's boot page, cached data, etc. are not cleared, if you select False, the app is equivalent to a reinstallation, which clears out all previous data)
- automationName Driver name
- browserName Chrome for direct web testing
- autoWebview boot into webview mode (boot directly into web mode without going to the native page)
- chromedriverExecutable Path where the web browser driver is placed (must be full path)
- chromedriverExecutableDir The directory where the web browser driver is placed.
- unicodekeyboard Enables unicode keyboards.
- resetKeyboard restart keyboard (and the last piece of configuration, both set to True, you can open the Chinese input, equivalent to our computer to install input method)
- autoGrantPermissions Enable cell phone permissions (equivalent to the alert pop-up box in the web, can not locate the element, set True, it is convenient to locate the element)
There are many more uses on the official website for those interested:/docs/en/writing-running-appium/caps/
Get the appPackage and appActivity via adb:
Method 1: adb shell am monitor monitor operation (after executing this command in cmd, then operate the corresponding app on the phone or emulator, the corresponding package name will be displayed)
Method 2: adb logcat | findStr -i displayed Query package name and page name from logs
Get the appPackage and appActivity via aapt:
aapt dump badging full path.apk
After getting the appPackage and appActivity, you can access the app using the package name in the following code:
from import Remote # Initiate a request # 1. Specify the address and port number of the service to be connected to # must include a platformName capability caps = {"platformName": "Android", "udid": "emulator-5554", "appPackage": "", "appActivity": "."} driver = Remote(command_executor='http://127.0.0.1:4723/wd/hub', desired_capabilities=caps)
Run results:
Summary:
- platformName Mandatory, others optional
- deviceName is important
- app install apk package, automatically open (already installed will not be reinstalled), apk package path is best not to have Chinese, I do not know why my computer with this way to run has been reporting errors, and finally failed to solve, so I use the package name to run!
- When copying the appActivity, note that it must be the name of the app's home page, so don't copy it wrong!
utilization
adb (Android Debug Bridge) Android debugging bridge: the role is to operate the app in the Android phone
Related Commands:
adb devices to see if the device is connected (you can connect manually adb connect 127.0.0.1:5554, you can search online for port numbers for different emulators)
adb shell login device (to get inside the phone system)
adb shell dumpsys activity | find "mFocusedActivity" View the foreground application activity application name (note that you must have opened the app, and then go to the command, dumpsys under a lot of commands, you can view the help file for more understanding)
adb install computer/package name.apk Install software
adb uninstall computer/package name.apk sanction software
adb pull cell phone file path computer file path download/pull file computer from cell phone
adb push computer file path cell phone file path push/upload from computer to cell phone
adb shell pm list packages Displays the names of all installed packages
Startup process analysis
The client sends a request via wd/hub/session to create a session session
The provided parameter is cpas
After the server receives the caps message, it checks whether the caps parameter is legal or not
adb install
Determine if there is a package name
Launch app
Get the version of the operating system:
-P 5037 -s emulator-5554 shell getprop
Determines if the package name has been installed on the phone:
-P 5037 -s emulator-5554 shell dumpsys package
Enable the app:
-P 5037 -s emulator-5554 shell am start -W -n /. -S
to this article on python appium automation testing sample code is introduced to this article, more related python appium automation testing content, please search for my previous articles or continue to browse the following related articles I hope you will support me in the future more!