appium desktop录制和隐式等待的用法
首先安装Android开发环境和sdk 环境
android studio 下载地址https://developer.android.com/studio#downloads
设置sdk的ANDROID_HOME和PATH变量
appium生态工具
adb:adroid的控制工具,用户获取android的各种数据和控制
appium desktop:内嵌了appium server和inspector的综合工具
appium Server:appium的核心工具,命令行工具
appium client:各种语言的客户端封装库,用于连接appium server
python java ruby robotframework-appium
appcrawler自动遍历工具
appium desktop工具包
下载地址:
https://github.com/appium/appium-desktop/releases
点右上角搜索inspect
capabilities解释地址:
https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/caps.md
点save as可以保存这台设备的信息,下次可以直接用
录制用例
点start session
点击小眼睛录制,选中一个控件,点击tap,recorder里面就记录了每个元素的动作,默认是Python,也可以选择别的语言
如果在操作过程中界面没有刷新,可以点刷新按钮,刷新过程不会被录制的,点击show/hide Boilerplate Code 叫样板代码,会生成所有的文件生成出来,再点击copy
python录制的代码
from appium import webdriver
caps = {}
caps[“appPackage”] = “com.snda.wifilocating”
caps[“appActivity”] = “com.lantern.launcher.ui.MainActivity”
caps[“noReset”] = “true”
caps[“platformName”] = “ANDROID”
caps[“deviceName”] = “3JU4C17C18000087”
driver = webdriver.Remote(“http://localhost:4723/wd/hub”, caps)
el6 = driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout[1]/android.widget.LinearLayout/android.widget.ImageButton[3]")
el6.click()
el7 = driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout[3]/android.widget.TextView")
el7.click()
el8 = driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.ImageButton")
el8.click()
driver.quit()
录制功能可以完成安卓自动化小用例,但是它不标准,它生成的只是一个脚本,放在pycharm里跑
发现报了以下错误:
E selenium.common.exceptions.NoSuchElementException: Message: An element could not be located on the page using the given search parameters.
因为其他干扰元素没有定位这些元素可以加上隐式等待来解决
driver.implicitly_wait(8)