往期参考
参考资料
- appium desktop https://github.com/appium/appium-desktop/releases
- sdk与android studio https://developer.android.com/studio/?hl=zh-cn#downloads
- scrcpy https://github.com/Genymobile/scrcpy
- capability https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/caps.md
- appium官方提供的示例代码 https://github.com/appium/appium/blob/master/sample-code/
- 演练apk http://xqfile.imedao.com/event/xueqiu_wxdialog.apk
上课节奏
- ppt回顾与答疑
- appium介绍与安装
- appium用例录制与执行
自动化测试价值
Android自动化测试框架
安装Appium Desktop
安装Appium Server
- nodejs
- java
- python2
- 代理
使用淘宝的cnpm安装appium是最稳定快速的方法
npm install -g cnpm --registry=https://registry.npm.taobao.org
cnpm install -g appium
多版本管理
#全局安装并执行
cnpm install -g appium
appium
#只安装到当前目录并执行
cnpm install appium@1.11
./node_modules/appium/build/lib/main.js
运行依赖
- Android Studio开发环境
- android sdk
- 真机、模拟器
使用Appium Desktop
- capability介绍
- Android入口分析
获取雪球的app信息
localhost:~ seveniruby$ adb logcat | grep -i displayed.*xueqiu
05-08 21:16:22.088 1215 1544 V WindowManager: Check opening app=AppWindowToken{c46c455 token=Token{20a230c ActivityRecord{44f7e3f u0 com.xueqiu.android/.view.WelcomeActivityAlias t15270}}}: allDrawn=false startingDisplayed=true startingMoved=false isRelaunching()=false startingWindow=Window{31cbed3 u0 Splash Screen com.xueqiu.android}
05-08 21:16:22.608 1215 1305 D ActivityManager: EVENT_APP_ACTIVITY_DISPLAYED_FINISH reportData: com.xueqiu.android/.view.WelcomeActivityAlias 25060 544
05-08 21:16:25.394 1215 1305 D ActivityManager: EVENT_APP_ACTIVITY_DISPLAYED_FINISH reportData: com.xueqiu.android/.common.MainActivity 25060 86
雪球app
{
"platformName": "android",
"deviceName": "hogwarts",
"appPackage": "com.xueqiu.android",
"appActivity": ".view.WelcomeActivityAlias"
}
自动处理权限弹框
{
"platformName": "android",
"deviceName": "hogwarts",
"appPackage": "com.xueqiu.android",
"appActivity": ".view.WelcomeActivityAlias",
"autoGrantPermissions": "true"
}
录制用例
# This sample code uses the Appium python client
# pip install Appium-Python-Client
# Then you can paste this into a file and simply run with Python
from appium import webdriver
caps = {}
caps["platformName"] = "android"
caps["deviceName"] = "hogwarts"
caps["appPackage"] = "com.xueqiu.android"
caps["appActivity"] = ".view.WelcomeActivityAlias"
caps["autoGrantPermissions"] = "true"
driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
#追加一句
driver.implicitly_wait(10)
el1 = driver.find_element_by_id("com.xueqiu.android:id/user_profile_icon")
el1.click()
el2 = driver.find_element_by_id("com.xueqiu.android:id/tv_login")
el2.click()
el3 = driver.find_element_by_id("com.xueqiu.android:id/tv_login_by_phone_or_others")
el3.click()
driver.quit()
运行用例demo
记得在代码里追加隐式等待
driver.implicitly_wait(10)
作业
- 打开雪球 添加自选股 输入alibaba 添加到自选股,把测试用例代码贴到回复里