XCUIElement - 获取图像值 [英] XCUIElement - Obtain Image value

查看:112
本文介绍了XCUIElement - 获取图像值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类型 .Image 和类 XCUIElement 的变量。这样的事情:

I have an variable that's of type .Image and class XCUIElement. Something like this:

var image = app.descendantsMatchingType(.Image).elementAtIndex(0)

有没有办法可以提取实际图像,以便将其与其他图像进行比较?

Is there a way I can extract the actual image so I can compare it to another image?

我已尝试调用方法,但它返回一个字符串。将其转换为 UIImage 始终失败。

I've tried caling the value method, but it returns a string. Casting it to a UIImage always fails.

推荐答案

我最近与Apple Developer Tools福音传教士进行了一次对话。目前无法从图像视图,按钮等访问实际图像。同样,无法访问可能感兴趣的其他视图属性,如isHidden或attributedText等。我是他说,UI测试团队的工程师对人们想要访问这些属性的用例感兴趣,因此对于他们和其他想要此功能的人来说都非常有用 - 如果你愿意的话提交错误报告/功能请求,请求 https://bugreport.apple.com

I have had a conversation about this with the Apple Developer Tools evangelist recently. There is currently no way of accessing the actual image from an image view, button, etc. Similarly, there is no way to access other properties of views that might be of interest, like "isHidden" or "attributedText", etc. I was told that the engineers on the UI Testing team are interested in the use cases that people are wanting access to these properties for, so it would be very helpful -- both for them and for the other people who want this feature -- if you would file a bug report / feature request asking for it at https://bugreport.apple.com

作为关于XCUIElement上value属性的提示,至少目前这似乎映射到XCUIElement引用的任何视图的accessibilityValue属性。因此,如果您设置了您感兴趣的视图的accessibilityValue以包含您有兴趣验证的一些信息,那么这可能有助于测试。但有两点需要注意:

As a tip regarding the "value" property on an XCUIElement, at least for now this appears to map to the "accessibilityValue" property of whatever view the XCUIElement is referencing. So if you set that accessibilityValue of a view you are interested in to contain some information you are interested in verifying, then this can possibly help in testing. Two things to be aware of though:

1)即使XCUIElement的value属性类型为id,accessibilityValue属性的类型也是 NSString的。我不知道如果你试图强制一些非字符串值(如图像)到accessibilityValue然后尝试从XCUIElement的value属性中检索它会发生什么,但我怀疑它不会很好。部分原因是:

1) Even though the "value" property of an XCUIElement is of type "id", the type of the accessibilityValue property is "NSString". I don't know what would happen if you try to force some non-string value (like an image) into accessibilityValue and then try to retrieve it from the "value" property of XCUIElement, but I suspect it wouldn't work well. Partially because:

2)视频的accessibilityValue属性实际上由Apple的VoiceOver功能用于视障人士。当设置该值时,当用户点击该元素时,它将被大声读出(这就是为什么它应该是一个字符串)。

2) The accessibilityValue property of a view is actually used by Apple's VoiceOver feature for the vision impaired. When the value is set, it will be read out loud when the user taps on that element (which is why it's supposed to be a string).

我也覆盖了在这里更详细地通过XCUIElement无法访问视图属性的问题: http://www.danielhall.io/exploring-the-new-ui-testing-features-of-xcode-7

I also covered the issue with not being able to access properties of view via XCUIElement in more detail here: http://www.danielhall.io/exploring-the-new-ui-testing-features-of-xcode-7

这篇关于XCUIElement - 获取图像值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆