参考连接
Android开发环境与SDK
- 设置sdk的ANDROID_HOME和PATH变量
- 创建模拟器或者使用真机
- 启动模拟器或者连接真机
测试设备
localhost:~ seveniruby$ $(which emulator) -list-avds
Nexus_5X_API_19
Nexus_5X_API_19_ARM
Nexus_5X_API_25
Nexus_5X_API_26
Nexus_5X_API_26_TesterHome
Nexus_5X_API_27
Pixel_2_API_23
Pixel_2_API_27
Pixel_XL_API_23
Pixel_XL_API_25
localhost:~ seveniruby$ $(which emulator) @Pixel_2_API_27
App文件
Appium Desktop
Android的capability
-
https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/caps.md
-
You must include a platformName capability
-
The desiredCapabilities object was not valid for the following reason(s): ‘deviceName’ can’t be blank
-
The desired capabilities must include either an app, appPackage or browserName
adb logcat | grep Displayed
08-15 20:48:51.779 1619 1640 I ActivityManager: Displayed com.xueqiu.android/.view.WelcomeActivityAlias: +2s893ms
08-15 20:49:05.180 1619 1640 I ActivityManager: Displayed com.xueqiu.android/.common.MainActivity: +8s275
用例录制
{
"platformName": "android",
"deviceName": "hogwarts",
"appPackage": "com.xueqiu.android",
"appActivity": ".view.WelcomeActivityAlias"
}
python录制代码
# 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"
driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
el1 = driver.find_element_by_id("com.xueqiu.android:id/tv_open")
el1.click()
el2 = driver.find_element_by_id("com.android.packageinstaller:id/permission_allow_button")
el2.click()
el3 = driver.find_element_by_id("com.android.packageinstaller:id/permission_allow_button")
el3.click()
el4 = driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.FrameLayout[1]/android.widget.FrameLayout/android.widget.ImageView")
el4.click()
driver.quit()
- selenium.common.exceptions.NoSuchElementException: Message: An element could not be located on the page using the given search parameters.
基本测试用例编写
- sdk//tools/bin/uiautomatorviewer
课后作业1
- test_wrong_phone 邮箱手机密码登陆,错误的手机号,断言弹框内容
- test_wrong_password 邮箱手机密码登陆,错误的手机号,断言弹框内容
- test_search 数据驱动 分别搜索 alibaba xiaomi google、
把测试用例与对应的setup方法贴到回复里