In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you "how to use python+appium to achieve automated testing", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "how to use python+appium to achieve automated testing" this article.
1. What is Appium?
Appium is an open source test automation framework that can always be used with native, hybrid, and mobile web applications. It uses the WebDriver protocol to drive IOS (the built-in test engine xcuitest), Android (uiautomator2,Espresso), and Windows applications
Native applications: Android programs are developed with JAVA or kotlin. These programs are native applications. Native applications are fluent and easy to call, but the disadvantage is that different sides need different development languages.
Web applications: web applications can be run directly on the mobile phone. Web is written in html+css+js.
Hybrid applications: a combination of native and web applications, some pages using native, some pages using web applications
The more famous framework in China:
Appium
Airtest is now maintained by Ali and was initially used in game testing, similar to the function of appium.
Uiautomator2 (easy to use, very python, only native, no other)
Design philosophy:
You don't have to recompile your application or modify it in any way in order to automate (Android/IOS comes with a framework)
You should not be limited to a specific language or framework to write and run tests (API calls, interfaces)
The mobile automation framework should not recreate wheels in terms of automation interfaces (WebDriver,appium was developed on the basis of selenium)
The mobile automation framework should be open source, not only nominally but also spiritually and practically.
two。 To start an app automation program
Open the simulator, or connect to the phone (note that developer mode and USB debug mode have been enabled, mobile phone authorization should be confirmed, otherwise it will not be connected)
Enter adb devices in the command window (view device name)
Enable the appium service appium client code connection service
Introduction to 3.appium Service
Chinese setting
In addition to simple settings, there are some advanced settings that we can take a look at
If you save it, you can view the preset for later use.
To edit the configuration is to enter and modify the environment variable
The host and port number do not need to be set, and the server can be started directly
When the server is running, you can see that the functions of the three buttons on the right are to start the inspector session, get the original log, and stop running the server.
Click to open it automatically through notepad. If other editing software is installed, you can choose to open it.
Once the service is turned on, you can use python as a client to connect to the service
4. Appium client use
Make sure that it has been installed before use, pip install appium-python-client, and import it directly after installation.
Take a look at the source code of Remote
At the same time, the appium server will also display 500 errors.
Hesitate to appium1.20.2 version, unlike the previous version need to pass in many parameters, now only need to pass platformName, so you can see what version you installed, but adding more parameters will not be affected
Common caps parameters:
PlatformName platform name (Android,IOS)
Required deviceName device name (optional)
Udid (just like deviceName, this parameter is easy to use in different versions, so use udid instead of deviceName later)
Storage path of app apk (optional)
AppActivity (page name, equivalent to title in web page) and appPackage (package name)
PlatformVersion system version number (optional, version mismatch will cause an error)
NoReset chooses True not to restart (it means that the boot page of app, cached data, etc., cannot be cleared. If you choose False,app, it is tantamount to reinstalling, emptying all the previous data).
AutomationName driver name
Chrome for direct determination of web by browserName
AutoWebview boots into webview mode (boot directly into web mode, no need to enter native page)
Path placed by chromedriverExecutable web browser driver (must be full path)
Directory placed by chromedriverExecutableDir web browser driver
Unicodekeyboard opens the keyboard in unicode encoding.
ResetKeyboard restart keyboard (with the previous configuration, both of them are set to True, you can enable Chinese input, which is equivalent to our computer installation input method)
AutoGrantPermissions enables mobile phone permissions (equivalent to the alert pop-up box on the web, which cannot locate the element. If True is set, it is convenient to locate the element)
There are many usages on the official website. If you are interested, please refer to: https://appium.io/docs/en/writing-running-appium/caps/.
Obtain appPackage and appActivity through adb:
Method 1: adb shell am monitor monitoring operation (after executing this command in cmd, and then operating the corresponding app on the mobile phone or simulator, the corresponding package name will be displayed)
Method 2: adb logcat | findStr-I displayed queries the package name and page name from the log
Obtain appPackage and appActivity through aapt:
Aapt dump badging full path .apk
After getting the appPackage and appActivity, you can use the package name to access the app as follows:
From appium.webdriver import Remote # initiates a request # 1. Indicate the service address and port number to be connected: # 2.You must include a platformName capabilitycaps = {"platformName": "Android", "udid": "emulator-5554", "appPackage": "com.lemon.lemonban", "appActivity": ".activity.WelcomeActivity"} driver = Remote (command_executor=' http://127.0.0.1:4723/wd/hub', desired_capabilities=caps)
Running result:
Summary:
Required for platformName, other optional
DeviceName is important
App installs the apk package and opens it automatically (those that have already been installed will not be reinstalled). The path of the apk package had better not be in Chinese. I don't know why my computer keeps reporting errors in this way, but it can't be solved in the end, so I use the package name to run.
When copying appActivity, note that it must be the name of the home page of app. Don't copy it wrong.
The use of 5.adb
Adb (Android Debug Bridge) Android debug bridge: the function is to operate app in Android phones.
Related commands:
Adb devices to see if the device is connected (you can manually connect to adb connect 127.0.0.1 5554, and you can search the port numbers of different simulators on the Internet)
Adb shell login device (enter the mobile phone system)
Adb shell dumpsys activity | find "mFocusedActivity" to check the name of the foreground application activity application (be sure to open app, and then execute commands. There are many commands under dumpsys, you can check the help documentation for more information)
Adb install computer / package name. Apk installation software
Adb uninstall computer / package name. Apk sanctions software
Adb pull mobile phone file path computer file path download / pull files from mobile phone computer side
Adb push computer file path mobile file path push / upload from the computer to the mobile end
Adb shell pm list packages displays all installation package names
Analysis of 6.Appium startup process
The client sends a request to create a session session through wd/hub/session
The parameter provided is cpas
After receiving the caps information, the server verifies whether the caps parameter is legal.
Adb install io.setting.appium
Judge whether there is a bag name or not
Start app
Get the version of the operating system:
Adb.exe-P 5037-s emulator-5554 shell getprop ro.build.version.release
Determine if the package name has been installed on the phone:
Adb.exe-P 5037-s emulator-5554 shell dumpsys package com.lemon.lemon
Enable app:
Adb.exe-P 5037-s emulator-5554 shell am start-W-n com.lemon.lemonban/.activity.WelcomeActivity-S
These are all the contents of the article "how to use python+appium to automate testing". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.