当前位置:网站首页>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()
边栏推荐
- Steam教育在新时代中综合学习论
- 兆骑科创创业赛事活动发布平台,创业赛事,项目路演
- 1W字详解线程本地存储 ThreadLocal
- 2022年网络安全培训火了,缺口达95%,揭开网络安全岗位神秘面纱
- MySQL advanced (thirty-three) MySQL data table adding fields
- DB2查询2个时间段之间的所有月份,DB2查询2个时间段之间的所有日期
- 2022-08-10日报: Swin Transformer作者曹越加入智源,开展视觉基础模型研究
- ES5和SE6来实现一个Promise效果
- 缺少比较器,运放来救场!(运放当做比较器电路记录)
- mysql进阶(三十三)MySQL数据表添加字段
猜你喜欢
【有限元分析】异型密封圈计算泄漏量与参数化优化过程(带分析源文件)
王学岗—————————哔哩哔哩直播-手写哔哩哔哩硬编码录屏推流(硬编)(26节课)
IT小白怎么系统的php学习
学习MySQL 临时表
发送post请求前台无法获取数据
产品使用说明书小程序开发制作说明
PyTorch 多机多卡训练:DDP 实战与技巧
微信小程序,自定义输入框与导航胶囊对其
How does IT Xiaobai learn PHP systematically
Error: Rule can only have one resource source (provided resource and test + include + exclude)
随机推荐
AWS Security Fundamentals
【MinIO】工具类使用
awk的简单使用
data product manager
Summary of tensorflow installation stepping on the pit
【剑指offer】---数组中的重复数字
Using data intelligence, Amazon cloud technology helps companies build endogenous brand growth
Analysys and the Alliance of Small and Medium Banks jointly released the Hainan Digital Economy Index, so stay tuned!
1004(树状数组+离线操作+离散化)
Send a post request at the front desk can't get the data
Do not access Object.prototype method ‘hasOwnProperty‘ from target object....
Lack of comparators, op amps come to the rescue!(Op amp is recorded as a comparator circuit)
PAT甲级 1014 排队等候(队列大模拟+格式化时间)
IT小白怎么系统的php学习
串口服务器调试助手使用教程,串口调试助手使用教程【操作方式】
【219】慕课三千多的那个go工程师的培训课笔记 02 go语言的编程思想
NAACL 2022 | 简单且高效!随机中间层映射指导的知识蒸馏方法
[219] The training course notes of the go engineer with more than 3,000 MOOCs 02 Programming ideas in the go language
锂电池技术
2011年下半年 系统架构设计师 下午试卷 II