-
测试软件:appium api demos # 可在github appium 项目内下载
-
使用设备:安卓模拟器
-
准备工作:
-
下载 appium-uiautomator2-driver
cnpm install appium-uiautomator2-driver
-
capability内新增:automationName
-
简介:使用哪种自动化引擎
Appium(默认)或Selendroid或UiAutomator2或Espresson用于Android或XCUITestiOS或YouiEngine用于使用You.i Engine构建的应用程序
-
-
-
appium 版本:1.13.0
-
目标toast
- 路径:Api Demos → Views → Popup Menu → MAKE A POPUP!

-
代码如下
import time from appium import webdriver desired_caps = {} desired_caps['platformName'] = 'Android' desired_caps['platformVersion'] = '5.1.1' desired_caps['deviceName'] = '127.0.0.1:62001' desired_caps['appPackage'] = 'io.appium.android.apis' desired_caps['appActivity'] = 'io.appium.android.apis.ApiDemos' desired_caps['noReset'] = "False" desired_caps['automationName'] = "uiautomator2" driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps) driver.find_element_by_android_uiautomator( 'new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text' f'("Views").instance(0));').click() driver.find_element_by_android_uiautomator( 'new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text' f'("Popup Menu").instance(0));').click() driver.find_element_by_xpath('//android.widget.Button[@content-desc="Make a Popup!"]').click() time.sleep(1) driver.find_element_by_xpath("//*[@text= 'Search']").click() time.sleep(1) print(driver.find_element_by_xpath("//*[@class='android.widget.Toast']").text)
-
测试结果
测试结果
-
运行过程
测试过程.gif
Words
Appium、appium + android、toast识别、获取toast信息、uiautomator2、appium-uiautomator2-driver
Blog:
- 简书:https://www.jianshu.com/u/ec81abf35751
- CSDN:https://blog.csdn.net/qq_21238607
- 微信公众号:rzbbzr
网友评论