Appium appium1.6.3 发布支持 toast 识别

思寒_seveniruby · 2016年12月13日 · 最后由 yajunzheng 回复于 2018年10月16日 · 3554 次阅读

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 条回复 时间 点赞
Sutune 回复

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

nihao 回复

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

dickyxiao 回复

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

# coding=utf-8
小雪 回复

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

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

飞多多 回复

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

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

songz 回复

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

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

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

huiyu Appium 1.6.3 python 3,怎么获取 toast 消息? 中提及了此贴 04月21日 11:55
yang 回复

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

yang 回复

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

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

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

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

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

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

#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 吧

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

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

#34 楼 @tlllly 早就不支持了

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

@si509429 关注你的 qq 邮箱

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

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

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

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

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

#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 python,appium1.6.3 怎么实现 toast 的?

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

#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 么?

#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

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

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

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

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

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

python client 没有对应更新吧

#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.

@luobs 顶, 解决了么

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

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

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

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

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

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

#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);

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

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

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

期待分享😀 😀

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册