当前位置:网站首页>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
边栏推荐
- Bugku easy_ nbt
- keep-alive
- First PR notes
- Coding devsecops helps financial enterprises run out of digital acceleration
- 华为哈勃化身硬科技IPO收割机
- 1330:【例8.3】最少步数
- Ecotone technology has passed ISO27001 and iso21434 safety management system certification
- I include of spring and Autumn
- 美团优选管理层变动:老将刘薇调岗,前阿里高管加盟
- F. Min cost string problem solving Report
猜你喜欢
Huawei Hubble incarnation hard technology IPO harvester
Redis' transaction mechanism
Example of lvgl display picture
Ctfshow web entry explosion
SQL Server learning notes
DVWA range clearance tutorial
Anti shake and throttling
Common redis data types and application scenarios
【 note 】 résoudre l'erreur de code IDE golang
Reasons and solutions for redis cache penetration and cache avalanche
随机推荐
Appium自动化测试基础 — APPium基础操作API(一)
华为哈勃化身硬科技IPO收割机
Common MySQL interview questions
爱可可AI前沿推介(7.5)
12 MySQL interview questions that you must chew through to enter Alibaba
Detailed explanation of C language branch statements
How to introduce devsecops into enterprises?
P1451 求细胞数量/1329:【例8.2】细胞
Common PHP interview questions (1) (written PHP interview questions)
Bugku telnet
keep-alive
Fr exercise topic --- comprehensive question
Lesson 4 knowledge summary
数学建模之层次分析法(含MATLAB代码)
Detailed explanation of QT creator breakpoint debugger
Visual task scheduling & drag and drop | scalph data integration based on Apache seatunnel
episodic和batch的定义
lv_ font_ Conv offline conversion
Anti shake and throttling
The elimination strategy of redis