android sdk
试了各种sdk tools下载、ADT bundle tools总有各种报错,最后直接官网android studio全套,记住下载页面的https改为http
没有试
brew install android-sdk
android模拟器
能适配mac M1芯片的模拟器好像只有夜神,但是安装后一直卡在99%,最后放弃改为真机
appium
启动前,在edit configuration里要配置android和java路径
appium inspector
Remote Path 要设置为 /wd/hub
desired capabilities:
{
"platformName": "Android",
"appium:platformVersion": "10",
"appium:deviceName": "ELS_AN00",
"appium:appPackage": "com.huawei.calculator",
"appium:appActivity": "com.huawei.calculator.Calculator"
}
获取appPackage,appActivity
adb shell dumpsys activity | grep "mResume"
获取deviceName
adb devices -l # model即是
错误:[INSTALL_FAILED_ABORTED: User rejected permissions] 表示用户权限不足
解决方法:在手机开发模式下把ADB安装应用需要用户确认关闭
一个简单的计算器自动化脚本
from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy
# For W3C actions
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.actions import interaction
from selenium.webdriver.common.actions.action_builder import ActionBuilder
from selenium.webdriver.common.actions.pointer_input import PointerInput
caps = {}
caps["platformName"] = "Android"
caps["appium:platformVersion"] = "10"
caps["appium:deviceName"] = "ELS_AN00"
caps["appium:appPackage"] = "com.huawei.calculator"
caps["appium:appActivity"] = "com.huawei.calculator.Calculator"
caps["appium:ensureWebviewsHavePages"] = True
caps["appium:nativeWebScreenshot"] = True
caps["appium:newCommandTimeout"] = 3600
caps["appium:connectHardwareKeyboard"] = True
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", caps)
el1 = driver.find_element(by=AppiumBy.ID, value="com.huawei.calculator:id/digit_8")
el1.click()
el2 = driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value="加")
el2.click()
el3 = driver.find_element(by=AppiumBy.ID, value="com.huawei.calculator:id/digit_7")
el3.click()
el4 = driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value="等于")
el4.click()
# 断言
el5 = driver.find_element(by=AppiumBy.ID,value='com.huawei.calculator:id/formula')
print(el5.text)
assert el5.text == '15'
driver.quit()