adb 实用命令
adb shell dumpsys 命令
demo 代码块:
demo() {
find_element ej_ | awk -F\" '{print $4}' | while read e; do
click "$e"
location=$(get_text b_3)
echo $e $location
find_element b_3 >/dev/null && back || back
done
}
appium 环境搭建
Android 环境配置:Appium 环境搭建( windows 版本 | Mac版本) 49
iOS 环境配置:IOS自动化配置 9
Appium Desktop内部下载地址:http://download.testing-studio.com/ 10
Appium 两种安装方式
1、Appium Desktop = Appium Server + Appium Inspector
2、命令行版本的Appium Server
安装 Appium
官方文档的安装方式(基本安装不上):
npm install -g appium
淘宝cnpm (最稳定的方法)
npm install -g cnpm --registry=https://registry.npm.taobao.org
cnpm install -g appium
搭建环境 注意
Appium 建议1.5
Java 1.8
SDK build-tools/ 下对应的版本,需要使用<=29的版本
appium 录制
配置:
{
"platformName": "Android",
"deviceName": "hogwarts",
"appPackage": "com.tencent.wework",
"appActivity": ".launch.LaunchSplashActivity",
"noReset": "true"
}
获取包名和activity名
Mac/Linux: adb logcat |grep -i activitymanager (-i忽略大小写)
Windows: adb logcat |findstr /i activitymanager
appium 录制用例优化
不建议使用录制出来的用例?
1、非常不便于维护,没有任何框架结构
2、生成的定位符通常是 xpath绝对定位,还需要优化
3、还需要在录制出来的用例中添加断言
课后练习
自己注册一个企业微信,实现添加联系人用例
Allure
安装:
1、allure
windows/mac通用安装方法
https://mvnrepository.com/artifact/io.qameta.allure/allure-commandline 4 下载最新版本(2.13)
解压->进入bin目录->运行allure.bat,
把bin目录加入PATH环境变量
Mac 可以使用brew安装:
brew install allure
官网: http://allure.qatools.ru/ 1
文档:https://docs.qameta.io/allure/#
2、 allure-pytest
安装allure-pytest插件
pip install allure-pytest
运行
1、生成中间结果
pytest 文件名 --alluredir /path/to/your/report
2、allure 命令生成最终的html 结果
allure serve /path/to/your/report
allure generate /path/to/your/report -o /path/to/finialreport
参考代码
@allure.title("{name}")
@pytest.mark.parametrize("name, gender,phonenum",get_data())
def test_addcontact(self,name, gender,phonenum):
# name = "霍格沃兹02"
# gender = '女'
# phonenum = '13800000002'
self.driver.find_element(MobileBy.XPATH, "//*[@text='通讯录']").click()
self.driver.find_element(MobileBy.XPATH, "//*[@text='添加成员']").click()
self.driver.find_element(MobileBy.XPATH, "//*[@text='手动输入添加']").click()
self.driver.find_element(MobileBy.XPATH,
"//*[contains(@text,'姓名')]/../*[@class='android.widget.EditText']").send_keys(name)
self.driver.find_element(MobileBy.XPATH, "//*[@text='男']").click()
self.driver.find_element(MobileBy.XPATH, f"//*[@text='{gender}']").click()
# if gender == '男':
# self.driver.find_element(MobileBy.XPATH, "//*[@text='男']")
# else:
# self.driver.find_element(MobileBy.XPATH, "//*[@text='女']")
self.driver.find_element(MobileBy.XPATH, "//*[contains(@text,'手机')]/..//android.widget.EditText").send_keys(
phonenum)
self.driver.find_element(MobileBy.XPATH, "//*[@text='保存']").click()
sleep(2)
# page_source 打印当前页面的xml布局结构
print(self.driver.page_source)
mytoast = self.driver.find_element(MobileBy.XPATH, "//*[@class='android.widget.Toast']").text
assert '添加成功' == mytoast
myphoto = "./img/photo.png"
self.driver.save_screenshot(myphoto)
allure.attach.file(myphoto,attachment_type=allure.attachment_type.PNG)
本文取自拉勾课程贴,防止删帖,故引用