当前位置:网站首页>Appium automation test foundation - appium basic operation API (I)
Appium automation test foundation - appium basic operation API (I)
2022-07-05 15:29:00 【Test - Eight Precepts】
1、 Pre code
What must be written in a script :
# server Launch parameters
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '5.1'
desired_caps['deviceName'] = '192.168.56.101:5555'
desired_caps['appPackage'] = 'com.android.settings'
desired_caps['appActivity'] = '.Settings'
# Statement driver object
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)2、 load and unload APP
(1) Put the... In the computer APK Installation package , Install on your phone
Installation method :
driver.install_app(app_path)
Parameters :
app_path: In the script machine APK⽂ Piece path (2) Uninstall the installed on your phone APP
Uninstall method :
driver.remove_app(app_id)
Parameters :
app_id: Need to unload app Package name (3) Demonstration exercise
# 1. Import appium
import time
from appium import webdriver
# 2. establish Desired capabilities object , Add startup parameters
desired_caps = {
"platformName": "Android", # System name
"platformVersion": "7.1.2", # System version
"deviceName": "127.0.0.1:21503", # Equipment name
"appPackage": "com.microvirt.launcher2", # APP Package name
"appActivity": "com.microvirt.launcher.Launcher" # APP Start name
}
# 3. start-up APP
# Declare the mobile phone driver object ( Instantiation webdriver)
# The first parameter is zero appium Address of service , Need to start the appium service .
# The second parameter is Desired capabilities object
# Let's just pass in these two parameters first .
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)
# 4. operation APP
# In the script machine APK⽂ Piece path , Be careful to add a... In front r, Otherwise, an error may be reported when resolving the address .
app_path = r'C:\Users\L\Desktop\com.taobao.taobao_V9.15.0.apk'
# install apk
driver.install_app(app_path)
time.sleep(5)
# You know what you're about to uninstall app The package name
app_id = "com.taobao.taobao"
# uninstall app
driver.remove_app(app_id)
# 5. close APP
time.sleep(3)
driver.quit() explain :
In general, these two commands are rarely used , That is, use the command to install apk Software , Generally, we also recommend adb command . You don't have to install app Write your code into the script , Even if you write a script , The final execution is also adb command . If the company has enough testing machines , We will take app Put the installation package into the mobile phone , Installed directly and manually .
These two commands are usually used in a script to test multiple app When , These two commands will be used , Put these in the test app First install , After the test is completed, uninstall app. But this situation is basically not much , General situation app All tested separately .
3、 Judge APP Installed or not
The use of API:
driver.is_app_installed(bundle_id)
Parameters :
bundle_id: Pass on ⼊app Package name , The return result is True( already installed ) / False( Not installed )Example :
# 1. Import appium
import time
from appium import webdriver
# 2. establish Desired capabilities object , Add startup parameters
desired_caps = {
"platformName": "Android", # System name
"platformVersion": "7.1.2", # System version
"deviceName": "127.0.0.1:21503", # Equipment name
"appPackage": "com.microvirt.launcher2", # APP Package name
"appActivity": "com.microvirt.launcher.Launcher" # APP Start name
}
# 3. start-up APP
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)
# 4. operation APP
# In the script machine APK⽂ Piece path
app_path = r'C:\Users\L\Desktop\com.taobao.taobao_V9.15.0.apk'
# install apk
driver.install_app(app_path)
time.sleep(5)
# You know what you're about to uninstall app The package name
bundle_id = "com.taobao.taobao"
result = driver.is_app_installed(bundle_id)
# The result is result=true
print(result)
# 5. close APP
time.sleep(3)
driver.quit()Tips : Usually we see with our eyes app Whether to install it or not , When the script clearly needs to be written .
4、 close app Software and close driver objects
close app The difference between software and closing driver objects :
driver.close_app()
Close the current operation app, The drive object is not closed .driver.quit()
Turn off the drive object , Close all associated files at the same time app.
a key : Supporting learning materials and video teaching
So here I have carefully prepared the detailed information of the above outline in The link below is as follows


边栏推荐
- Leetcode: Shortest Word Distance II
- Common redis data types and application scenarios
- Value series solution report
- Transfer the idea of "Zhongtai" to the code
- Cartoon: what are the attributes of a good programmer?
- mapper.xml文件中的注释
- Severlet learning foundation
- Nine hours, nine people, nine doors problem solving Report
- I include of spring and Autumn
- OSI 七层模型
猜你喜欢

30岁汇源,要换新主人了

How to paste the contents copied by the computer into mobaxterm? How to copy and paste

Crud de MySQL

Super wow fast row, you are worth learning!

Stop B makes short videos, learns Tiktok to die, learns YouTube to live?

Ten billion massage machine blue ocean, difficult to be a giant

Interpretation of Apache linkage parameters in computing middleware

First PR notes

lvgl 显示图片示例

keep-alive
随机推荐
qt creater断点调试程序详解
Lesson 4 knowledge summary
MySQL----函数
First PR notes
I spring and autumn blasting-1
JMeter performance test: serveragent resource monitoring
Bugku's eyes are not real
[JVM] operation instruction
Detailed explanation of QT creator breakpoint debugger
JS topic - console log()
做研究无人咨询、与学生不交心,UNC助理教授两年教职挣扎史
Garbage collection mechanism of PHP (theoretical questions of PHP interview)
Appium自动化测试基础 — APPium基础操作API(一)
Talk about your understanding of microservices (PHP interview theory question)
PHP high concurrency and large traffic solution (PHP interview theory question)
Behind the ultra clear image quality of NBA Live Broadcast: an in-depth interpretation of Alibaba cloud video cloud "narrowband HD 2.0" technology
Bugku telnet
Cartoon: what are the attributes of a good programmer?
你童年的快乐,都是被它承包了
Install PHP extension spoole