当前位置:网站首页>Appium进行APP自动化测试
Appium进行APP自动化测试
2022-08-10 14:29:00 【zljun8210】
之前用过uiautomator2对安卓App进行自动化测试,本次简单介绍Appium进行App自动化测试。
Appium具体功能不再介绍,可自行百度。
1、 安装Appium
首先官网下载对应版本:
Release v1.22.3-4 · appium/appium-desktop · GitHub
注意:其他Node.js\JDK\Andoird SDK\Python\Selenium自行安装
2、 元素识别
元素识别可用Android自带的uiautomatorview,也可用第三方工具weditor,也可用appium的Inspector。随着Appium Desktop升级到1.22.0版本,服务和元素查看器已经分开了,查看元素信息就需要下载Appium Inspector。下载地址:Releases · appium/appium-inspector · GitHub
2.1 首先运行Appium,配置相关信息

2.2 启动appium inspector,配置相关信息
2.3 点击 Start Session打开界面,可实时刷新。
3、 编写代码实现
import time
import unittest
from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy as By
class InspectTest(unittest.TestCase):
caps = {}
caps["platformName"] = "Android"
caps["appium:platformVers"] = "12"
caps["appium:deviceName"] = "7d9p45zhytuson6l"
caps["appium:ensureWebviewsHavePages"] = True
caps["appium:nativeWebScreenshot"] = True
caps["appium:newCommandTimeout"] = 3600
caps["appium:connectHardwareKeyboard"] = True
caps["appium:appPackage"] = "com.xxxxx.xxxxx"
caps["appium:appActivity"] = "crc64ad4cc14999bdba0b.MainActivity"
# 当前Python为3.10,其find_element方法有所改变
def start_app(self):
d = webdriver.Remote("http://127.0.0.1:4723/wd/hub", self.caps)
acc = d.find_element(By.XPATH, '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.widget.ScrollView/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup[1]/android.widget.EditText')
acc.send_keys('username')
time.sleep(1)
pw = d.find_element(By.XPATH, '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.widget.ScrollView/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup[2]/android.widget.EditText')
pw.send_keys('password')
time.sleep(1)
loginBtn = d.find_element(by=By.CLASS_NAME, value='android.widget.Button')
loginBtn.click()
time.sleep(5)
backB = d.find_element(By.CLASS_NAME, 'android.widget.Button')
backB.click()
time.sleep(1)
report = d.find_element(By.ANDROID_UIAUTOMATOR, 'new UiSelector().text("Inspection Reports")')
report.click()
time.sleep(5)
d.quit()
def test01_starts(self):
self.start_app()
if __name__ == '__main__':
unittest.main()
边栏推荐
- leetcode 739. Daily Temperatures 每日温度(中等)
- 【POI 2008, BLO】割点
- MySQL advanced (thirty-three) MySQL data table adding fields
- [219] The training course notes of the go engineer with more than 3,000 MOOCs 02 Programming ideas in the go language
- 《论文阅读》PLATO: Pre-trained Dialogue Generation Model with Discrete Latent Variable
- How to code like a pro in 2022 and avoid If-Else
- Using data intelligence, Amazon cloud technology helps companies build endogenous brand growth
- 微信小程序,自定义输入框与导航胶囊对其
- BFT机器人带你走进智慧生活 ——探索遨博机器人i系列的多种应用
- 线上线下课程教学培训小程序开发制作功能介绍
猜你喜欢
随机推荐
1W字详解线程本地存储 ThreadLocal
力扣解法汇总640-求解方程
这一次,话筒给你:向自由软件之父斯托曼 提问啦!
如何完成新媒体产品策划?
【POI 2008, BLO】割点
The a-modal in the antd component is set to a fixed height, and the content is scrolled and displayed
MySQL - 数据库的存储引擎
《论文阅读》PLATO: Pre-trained Dialogue Generation Model with Discrete Latent Variable
Second half of 2011 System Architect Afternoon Paper II
Send a post request at the front desk can't get the data
d为何用模板参数
快速了解大端模式和小端模式
中学数学建模书籍及相关的视频等(2022.08.09)
黑客入门,从HTB开始
mysql进阶(三十三)MySQL数据表添加字段
[Gazebo Introductory Tutorial] Lecture 3 Static/Dynamic Programming Modeling of SDF Files
关于已拦截跨源请求CORS 头缺少 ‘Access-Control-Allow-Origin‘问题解决
Lithium battery technology
leetcode 739. Daily Temperatures 每日温度(中等)
指针(C语言初解)









