Appium appium1.6.3 发布支持 toast 识别

思寒_seveniruby · December 13, 2016 · Last by yajunzheng replied at October 16, 2018 · 4528 hits

iOS

Fix issue where we might try and uninstall an ssl cert from a real device where this isn't sensible

Fix another issue with acceptSslCerts where it might potentially miss the correct sim UDID

iOS - XCUITest

主要是更新了wda的版本, 以及xpath的性能提升. 其实如果想用新版本绕过appium直接用wda也没啥.

Upgrade version of WebDriverAgent used. Includes following updates:

Improve xpath query performance

Verify predicates

Fix crash for some xpath selectors

Decorate proxied getSession response with Appium's capabilities (fixes issues with clients that call getSession to determine server capabilities and are confused by WDA's non-standard response) (#7480)

Fix issue with starting XCUITests on a real device, due to changes in WDA that invalidated our startup detection logic. (#7313)

Allow connecting to an already-running WebDriverAgent through the webDriverAgentUrl capability, rather than starting our own

Android

Fix bug where we would attempt to get target SDK version from manifests even when they might not include it. (#7353)

Actually pass the acceptSslCerts capability to the underlying automation so that it can have an effect (#7326)

Updated permission granting logic to speed up permission granting by doing it in bulk rather than one at a time (#7493)

Hide the new permission granting logic behind an autoGrantPermissions capability which doesn't attempt to grant permissions unless it's true (#7497)

Android - Uiautomator2

这个是之前很多人关注的功能, 大家可以测试下看看. selendroid早就知道了, 这算是uiautomator2第一次支持吧

Add ability to verify TOAST messages (these can't be interacted with, only text retrieval allowed)

Windows

支持windows的自动化, 比上版本增强了

Actually upgrade WinAppDriver to 0.7 (#7445). Includes following updates:

Click on arbitrary elements

Support for sendKeys modifiers

Various bugfixes

Added GET /orientation

Added support for WPF apps

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 55 条回复 时间 点赞

等下去试试😄

—— 来自TesterHome官方 安卓客户端

好消息😁 等下试试去

思寒 速度好快!

期待分享😀 😀

#4楼 @gz19891020 twitter上看到作者发推了 觉得新增的功能不错 就转过来了 对我的遍历也很有用。我还没测试哪

刚装了,运行就报错:
Unable to start WebDriverAgent: Error: Command 'idevicedate -u a58bdd10033efffd5261d606ec221744c973b6d9' exited with code 255
有没有遇到这种情况的

所以验证toast是用uiautomator2咯,印象中uiautomator2是编成APK执行的,和uiautomator的jar方式不一样的,所以在capabilities设置上会不一样了吗?

Great news !

#8楼 @carl

import { AndroidUiautomator2Driver } from `appium-uiautomator2-driver`

let defaultCaps = {
app: 'path/to/your.apk',
deviceName: 'Android',
platformName: 'Android',
automationName: 'uiautomator2'
};

let driver = new AndroidUiautomator2Driver();
await driver.createSession(defaultCaps);

怎么使用呢? 1.6.3的appium源码下载回来怎么使用呢,怎么获取toast呢? 求指导啊

#10楼 @zhangzhao_lenovo
感谢,这个javascript的demo 直是不错,顺便请教一下,这个例子中的await是必须加入的吗?是为了解决什么问题吗?我对javascript不太了解

Young Appium1.6.3 发布支持 获取 toast 内容实测 中提及了此贴 14 Dec 22:05

uiautomator和uiautomator2是不是不是一个东西

—— 来自TesterHome官方 安卓客户端

#7楼 @luobs 我也遇到了 你这个是怎么解决的

@luobs 顶, 解决了么

#7楼 @luobs

  1. Remove or rename your current Appium.
  2. Reinstall Appium
  3. Brew uninstall libimobiledevice
  4. Brew install libimobiledevice --HEAD
  5. Add team to your WebDriverAgent.xcodeproj and run it in Xcode
  6. Run your test It works for me.

python client没有对应更新吧

#8楼 @carl 您好,我也不知道如何在appium中使用uiautomator2.0,你现在会用了么,指导下😄

#19楼 @penghong2014
appium 1.6.3
java-client 5.0.0
jdk 8

capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.ANDROID_UIAUTOMATOR2);

#18楼 @oscar client不用更新的,可以拿到toast

#21楼 @neyo 直接通过元素定位到么,我用page_source获取不到

#22楼 @lazyman page_source没有的,

def _find_toast(self,message,timeout,poll_frequency,driver):
message = '//*[@text=\'{}\']'.format(message)
element = WebDriverWait(driver,timeout,poll_frequency).until(expected_conditions.presence_of_element_located((By.XPATH,message)))
print element

#23楼 @neyo 执行出错
File "C:\Python27\lib\site-packages\selenium-3.0.2-py2.7.egg\selenium\webdriver\support\wait.py", line 80, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:

这个是指在时间内没找到toast么?

#23楼 @neyo python 怎么实现的,望指教

@neyo python,appium1.6.3怎么实现toast的?

#25楼 @oscar
#26楼 @xiaoan_2131 是UIAutomator2的支持,我贴个我写selendroid testapp的demo好了

#coding=utf-8
from appium import webdriver
import time
import unittest
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions


class ToastTests(unittest.TestCase):
def setUp(self):
desired_caps = {}
desired_caps['automationName'] = 'Uiautomator2'
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '5.1.1'
desired_caps['deviceName'] = 'Android Emulator'
desired_caps['appPackage'] = 'io.selendroid.testapp'
desired_caps['appActivity'] = 'io.selendroid.testapp.HomeScreenActivity'
desired_caps['resetKeyboard'] = 'true'
desired_caps['unicodeKeyboard'] = 'true'
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

def tearDown(self):
self.driver.quit()

def _find_toast(self,message,timeout,poll_frequency,driver):
message = '//*[@text=\'{}\']'.format(message)
element = WebDriverWait(driver,timeout,poll_frequency).until(expected_conditions.presence_of_element_located((By.XPATH,message)))
print element

def test_toast(self):
print self.driver.get_window_size()
self.driver.find_element_by_id('showToastButton').click()
# time.sleep(2)
print self.driver.page_source
self._find_toast('Hello selendroid toast!',10,0.5,self.driver)
time.sleep(10)
self.driver.find_element_by_id('showToastButton').click()
self._find_toast('Hello selendroid toast!',10,0.5,self.driver)

if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(ToastTests)
unittest.TextTestRunner(verbosity=2).run(suite)

@neyo 我看你说selenriod testapp 不知道是啥意思,我就用公司的app获取toast消息成功,就是通过automationName 赋值为Uiautomator2,appium采用1.6.3 就可以了。。。多谢帮助!

#28楼 @xiaoan_2131 👏 不客气,那是我用来写demo的app啦

@neyo 但我用 Uiautomator view为什么看不到toast消息呢,而通过Uiautomator2可以捕获到呢?

@xiaoan_2131 appium1.6.3好多方法都变了,find_element_by_name用不了,

@xiaoan_2131 方便加微信么,请教一下😂

@si509429 关注你的qq邮箱

Appium1.6.3 版本是不是不支持By.name的方式查找元素了,findElement(By.name)全部失败,大神来确认下

#34楼 @tlllly 早就不支持了

@seveniruby 思寒 你知道删掉By.name的原因不,找了好久也没找到原因。By.name不能用的话,那只能用xpath来包@text了或者其他查找方式了

@xiaoan_2131 你selenium remote server用的什么版本?我用的3.0.1版本,加上capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.ANDROID_UIAUTOMATOR2);这行命令后,driver就初始化失败了。

#27楼 @neyo

def _find_toast(self,message,timeout,poll_frequency,driver):
message = '//*[@text=\'{}\']'.format(message)
element = WebDriverWait(driver,timeout,poll_frequency).until(expected_conditions.presence_of_element_located((By.XPATH,message)))
print element

这个是你自己写的?不一定非要By.XPATH吧

#28楼 @xiaoan_2131 你方法中是怎么调用的

#27楼 @neyo 发现一个问题,desired_caps['automationName'] = 'Uiautomator2' 设置这个后,输入中文就不支持了

#40楼 @oscar 😳 其它的定位方式我没试,之前用selendroid的时候是用的是By.PARTIAL_LINK_TEXT。uiautomator2下输入中文没试过。。目前没做这块了。。

#41楼 @neyo ok 感谢回答,这块的坑还真不少😀

@xiaoan_2131 能指教下python怎么获取的吗

yang 回复

除了automationName 赋值为Uiautomator2,还有其他的设置么,例如new driver的时候要new AndroidUiautomator2Driver ?
appium-Uiautomator2-driver也已经装了,但是发现还是有问题,方便沟通一下么?

yang 回复

请问你的appium1.6.3如何用python实现toast啊,我初学者,弄了好几天不对啊,能知道一下吗

huiyu Appium 1.6.3 python 3,怎么获取 toast 消息? 中提及了此贴 21 Apr 11:55

发现不能识别中文的toast,各位大神有解决办法吗

哈哈,识别中文的办法终于解决,头部加
import sys
reload(sys)
sys.setdefaultencoding('utf-8')

songz 回复

所以1.6.3版本以后,toast的定位方式就和其他元素没什么区别了,另外,使用UIautomator2后,driver就会初始化失败?

python+appium1.6.5还是搞不定,抓不到toast,有人指点下吗?
desired_caps['automationName'] = 'uiautomator2'
启动app也没问题,appium没有error,就是没找到

def test_find_toast(driver,message,timeout,poll_frequency):
message = '//*[@text=\'%s\']' %message
print message
element = WebDriverWait(driver,timeout,poll_frequency).until(expected_conditions.presence_of_element_located((By.XPATH,message)))
print element

def test_find_toast2(driver,message):
try:
driver.find_element_by_xpath('//*[@text=\'%s\']' %message)
print "find toast message %s" %message
except:
print "not find toast message %s" %message

1、安装appium-uiautomator2-driver: npm install appium-uiautomator2-driver
2、导包

3、设置automatinName

4、获取Toast,并通过print验证自己获取的内容是否正确

结果:验证通过

环境:
jdk版本:"1.8.0_131"
appium版本:1.6.5
selenium:3.3.1
测试设备:Android 5.1
Python:3.5.3

小雪 回复

厉害了我的姐

飞多多 回复

def test_find_toast2(driver,message):
try:
driver.find_element_by_xpath('//*[@text=\'%s\']' %message)
print "find toast message %s" %message
except:
print "not find toast message %s" %message
好用么

小雪 回复

你好,我用你的方法一直没成功

请问这个怎么解决啊?环境:python3+appium1.6.5。谢谢!

dickyxiao 回复

这个是由于你的toast内容为中文,由于字符编解码问题导致不能识别,需要在代码顶部写注释如下即可

# coding=utf-8
nihao 回复

你好 我也遇到了这个问题 求指导下,谢谢

Sutune 回复

我进行了注释 还是有这个问题呀,求指导下,谢谢您

需要 Sign In 后方可回复, 如果你还没有账号请点击这里 Sign Up