UI测试失败,并显示错误“无法在15.0 s内获取快照”。 [英] UI testing fails with error "Failed to get snapshot within 15.0s"

查看:137
本文介绍了UI测试失败,并显示错误“无法在15.0 s内获取快照”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表格视图包含大量单元格。我试图从该表格视图中点击一个特定的单元格。但是测试以以下错误结束:

I am having a table view with a huge amount of cells. I tried to tap a particular cell from this table view. But the test ending with this error:


无法在15.0s内获取快照

Failed to get snapshot within 15.0s


<我假设系统将在访问其表元素之前对整个表视图进行快照。由于单元数量巨大,快照拍摄时间不够(15秒可能是系统默认时间)。

I assume that, the system will take snapshot of the whole table view before accessing its element. Because of the huge number of cells, the snapshot taken time was not enough (15 secs is may be the system default time).

我手动设置睡眠时间/ 等待时间(我花了60秒)。 60秒后仍然无法访问单元格!

I manually set the sleep time / wait time (I put 60 secs). Still I can not access the cells after 60 seconds!!

我发现一个奇怪的事情是,在访问单元格之前,我在调试器中打印对象是这样的:

A strange thing I found is, before accessing the cell, I print the object in Debugger like this:

po print XCUIApplication().cells.debugDescription

像这样的错误


无法在15.0s内获取快照

Failed to get snapshot within 15.0s

错误:执行被中断,原因:内部ObjC异常breakpoint(-3)..

error: Execution was interrupted, reason: internal ObjC exception breakpoint(-3)..

该过程已返回到表达式求值之前的状态。

The process has been returned to the state before expression evaluation.

再次如果我使用

po print XCUIApplication().cells.debugDescription

现在它将在调试器视图的表视图中打印所有单元格。

Now it will print all cells in the tableview in Debugger view.

不知道为什么会发生这种情况。有没有人遇到过类似的问题?

No idea about why this happens. Does anyone faced similar kind of issues? Help needed!!

推荐答案


我认为,系统将对整个表视图进行快照在访问其元素之前。

I assume that, the system will take snapshot of the whole table view before accessing its element.

您的假设是正确的,但故事还有很多。 UI测试从应用程序请求快照。应用程序将获取此快照,然后将快照发送到测试,测试最终将对该查询进行评估。对于非常大的快照(如您的表视图),这意味着:

Your assumption is correct but there is even more to the story. The UI test requests a snapshot from the application. The application takes this snapshot and then sends the snapshot to the test where the test finally evaluates the query. For really large snapshots (like your table view) that means that:


  1. 快照需要很长时间才能生成并生成应用程序

  2. 快照需要很长时间才能发送回测试以进行查询评估。

I'目前在WWDC 2017上,M有很多关于测试的好消息-特别是一些可以解决您的确切问题的事情。我将在此处进行概述,但是您应该去观看 WWDC 2017 Session 409 并跳到时间戳记17:10。

I'm at WWDC 2017 right now and there is a lot of good news about testing - specifically some things that address your exact problem. I'll outline it here but you should go watch WWDC 2017 Session 409 and skip to timestamp 17:10.

第一个改进是远程查询。这是测试将 query 传输到应用程序的地方,应用程序将从测试中远程评估该查询,然后仅传输回该查询的结果。预期此改进会带来约20%的速度和30%的内存减少。

The first improvement is remote queries. This is where the test will transmit the query to the application, the application will evaluate that query remotely from the test and then only transmit back the result of that query. Expect a marginal improvement from this enhancement ~20% faster and ~30% less memory.

第二个改进是查询分析。此增强功能将通过使用用于拍摄快照的最小属性集来减少拍摄的快照的大小。这意味着在评估查询时,默认情况下不会获取视图的完整快照。例如,如果您要查询点击一个按钮,则快照将仅限于视图中的按钮。这意味着编写较少歧义的查询更为重要。即如果要点击导航栏按钮,请在查询中指定它,例如 app.navigationBars.buttons [ A button] 。您会看到此增强功能带来了更大的性能提升,速度提高了约50%,内存减少了约35%

The second improvement is query analysis. This enhancement will reduce the size of snapshots taken by using a minimum attribute set for taking snapshots. This means that full snapshots of the view are not taken by default when evaluating a query. Example is if you're querying to tap a button, the snapshot is going to be limited to buttons within the view. This means writing less ambiguous queries are even more important. I.e. if you want to tap a navigation bar button, specify it in the query like app.navigationBars.buttons["A button"]. You'll see even more performance improvement from this enhancement ~50% faster and ~35% less memory

最后一个也是最明显的(也是最危险的)改进是它们重新调用First Match API。这会带来一些权衡/风险,但会带来最大的性能提升。它提供了一个新的 .firstMatch 属性,该属性返回XCUIElement查询的第一个匹配项。使用 .firstMatch 时,不会发生导致测试失败的歧义匹配,因此您冒着评估或对不希望的XCUIElement执行操作的风险。预计性能会提高约10倍,并且根本不会增加内存。

The last and most notable (and dangerous) improvement is what they're calling the First Match API. This comes with some trade offs/risks but offers the largest performance gain. It offers a new .firstMatch property that returns the first match for a XCUIElement query. Ambiguous matches that result in test failures will not occur when using .firstMatch, so you run the risk of evaluating or performing an action on an XCUIElement that you didn't intend to. Expect a performance increase of ~10x faster and no memory spiking at all.

因此,要回答您的问题-更新到Xcode 9,macOS High Sierra和iOS 11。 .firstMatch ,您可以在其中使用高度特定的查询,以及解决快照超时问题。实际上,您遇到的超时问题可能已经可以通过使用远程查询和查询分析获得的常规改进而得到解决,而无需使用 .firstMatch

So, to answer your question - update to Xcode 9, macOS High Sierra and iOS 11. Utilize .firstMatch where you can with highly specific queries and your issue of timing out snapshots should be solved. In fact the time out issue you're experiencing might already be solved with the general improvements you'll receive from remote queries and query analysis without you having to use .firstMatch!

这篇关于UI测试失败,并显示错误“无法在15.0 s内获取快照”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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