UI Testing Failure - Failure getting snapshot

UI Testing Failure - Failure getting snapshot Error Domain=XCTestManagerErrorDomain Code=9 "Error -25201 getting snapshot for element


I'm getting this error when first attempting to query a table view. The table view only has about 30 cells but they contain content that's loaded asynchronously. It's intermittent, and doesn't happen all the time, but frequent enough that it causes a serious problem with automated UI tests. Even with hard-coded sleeps that are definitely long enough to allow all content to finish loading, it doesn't seem to prevent this error from occuring.

Answered by krze in 131769022

The issue is caused by having a NSMutableAttributedString with custom attributes in the hierarchy when testing.


rdar://25623858

To specify this error occurs in Xcode 7.3 while testing on real device. I've seen it occur in simulator, but not as frequently.

Accepted Answer

The issue is caused by having a NSMutableAttributedString with custom attributes in the hierarchy when testing.


rdar://25623858

Hi,


I am also encountering this issue. Error getting snapshot Error -25201. How did you resolve your problem? Thanks!

FWIW, rdar://25623858 is marked resolved, but I'm still having this problem when an NSMutableAttributedString is in the hierarchy with Xcode 8.

The fix for that bug (r. 25623858) was actually made in the OS, not in Xcode. What OS release are you testing on?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

I'm getting this error too, i am testing on simulator iOS10.0, the bug is on which version of OS?

Thanks @Eskimo. Simulator 10.0..Xcode 8.0

Interesting. There’s clearly some other aspect of this that didn’t get fixed. Please file a bug about this, then post your bug number here just for the record. Also, it would really help if your bug included a small test project that illustrates the issue.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

I'll try to do both next week. Right now we're trying to get an app out for App Store review and this has blown up automating screenshots, so we're knee deep in manual screenshots for 4 screens, on 4 devices in 3 languages. :/

So...hand creating screenshots was so painful, I spent a few hours tracking the problem down with a clean Xcode project with the minimum code to reproduce the problem. It's not NSMutableAttributedString...the problem occurs when there's a UITableView in the hiearchy with 500 or more rows.


Could be 1 section with 500 rows, or 10 sections with 50 rows...number of sections doesn't matter. Doesn't matter that only a small subset of the rows are visible and cells have actually been generated.


The hang occurs when either accessing the app hierarchy:


app.tables["OuterTableView"]


Or creating an expectation that waits for a view element to appear:

expectation(for: NSPredicate(format: "exists == 1"),
                    evaluatedWith: app.tables["OuterTableView"],
                    handler: nil);
waitForExpectations(timeout: 5, handler: nil)


Created a radar bug report (# 28884023) and attached the Xcode project to it. I can send you the Xcode project separately as well if you'd like.

… the problem occurs when there's a UITableView in the hiearchy with 500 or more rows.

Well, that’s wacky. Alas, I don’t know enough about the internal machinations of UI testing to have any suggestions for how that might come about.

Created a radar bug report (# 28884023) and attached the Xcode project to it.

Excellent. Thanks!

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
Well, that’s wacky. Alas, I don’t know enough about the internal machinations of UI testing to have any suggestions for how that might come about.

No kidding. Its acting like its spending too much time parsing table cells...but since only 20 are visible (and there's been no scrolling) there aren't that many table cells in the hierarchy. Really wierd. Once we knew what the problem was, we added a launch argument to our app "AppStoreScreenshots" that arbitrarily limits the amount of data loaded from the web service to the last 24 hours to reduce the row count. Its hacky but it got automated screenshots rolling again. 😎

Share and Enjoy

I've posted it here for others: https://github.com/williamsjj/UITestingHangTables

I am using xcode8 and am seeing this issue when i run a test on real device(OS: 9.3.2). This test works fine on simulator with OS 10.0.


Can you please guide on how can i get this fixed?

This has wiped out the stability of all our tests. We have reverted to manual testing or baby sitting our automation locally. They are now all unstable as we use NSPredicate for most of wait methods.


here's an example of how we use it:

func waitForHittable (_ element: XCUIElement, waitSeconds: Double, file: String = #file, line: UInt = #line) {

let predicate = NSPredicate(format: "exists == true AND hittable == true")

testCase.expectation(for: predicate, evaluatedWith: element, handler: nil)

testCase.waitForExpectations(timeout: waitSeconds) { (error) -> Void in

if (error != nil) {

let message = "Failed to find \(element) after \(waitSeconds) seconds."

self.testCase.recordFailure(withDescription: message, inFile: file, atLine: line, expected: true)

}

}

}


UI Testing Failure - Failure getting snapshot Error Domain=XCTestManagerErrorDomain Code=9 "Error -25215 getting snapshot for element <AXUIElement 0x7f90f0614300> {pid=17044}" UserInfo={NSLocalizedDescription=Error -25215 getting snapshot for element <AXUIElement 0x7f90f0614300> {pid=17044}}


Any updates on a fix? Would moving to KIF be more of the same? Help please.


OSX 10.11.6

Xcode 8.1

iOS Sim 9.0

Any updates on a fix?

If you read back through the thread you’ll see that this symptom has had multiple underlying causes. Thus, it’s hard to know whether you’re hitting exactly the same problem as dtarcode. I recommend you file your own bug about this. Please post your bug number, just for the record.

Would moving to KIF be more of the same?

I’m sorry, I don’t know what KIF is.

Did you try the workaround suggested by dtarcode? Did it work in your case?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
UI Testing Failure - Failure getting snapshot
 
 
Q