How to use SKTestSession in UI Tests?

Is there a way to use .storekit file and SKTestSession in UI tests?

It works fine in Unit Tests, but when it comes to UI tests SKTestSession initializes OK, but StoreKit doesn't work. SKProductsRequest fails with this error:

Code Block
Error Domain=SKErrorDomain Code=0 "UNKNOWN_ERROR" UserInfo={NSLocalizedDescription=UNKNOWN_ERROR, NSUnderlyingError=0x600003d30f30 {Error Domain=ASDErrorDomain Code=507 "Error decoding object" UserInfo={NSLocalizedDescription=Error decoding object, NSLocalizedFailureReason=Attempted to decode store response}}}

When I use the same .storekit in regular simulator launch it works just fine.
Answered by vgorshkov in 633198022
Here what I found: adding a 5 seconds delay before starting SKProductsRequest does the trick: now everything works just fine.
Accepted Answer
Here what I found: adding a 5 seconds delay before starting SKProductsRequest does the trick: now everything works just fine.
Are you experiencing this with the GM Xcode 12.0 + the GM OS of whatever platform you're targeting with your test? If so, would you please file a radar and attach a small sample project with a test that fails and one that you're seeing succeed?
Xcode Version 12.1 problem still exists

Code Block
Error Domain=SKErrorDomain Code=0 "UNKNOWN_ERROR" UserInfo={NSLocalizedDescription=UNKNOWN_ERROR, NSUnderlyingError=0x7f9b514849e0 {Error Domain=ASDErrorDomain Code=950 "Unhandled exception" UserInfo={NSLocalizedDescription=Unhandled exception, NSLocalizedFailureReason=An unknown error occurred}}}

I have a fascinating observation. StoreKit testing works when unit and UI tests are built with Debug configuration and refuses to work if they are built with Release or Profile configurations. I didn't find any mentions about it in the documentation, so I'd like to ask Apple Frameworks Engineers to tell us more details about the specifics and what configuration is required for SKTestSession to work.

Thank you!
I've been encountering this problem as well. It seems like the SKTestSession just isn't being applied to the application when it's being run as part of a UI test.

In Xcode 12.2, adding a 5 second delay before starting the SKProductsRequest no longer solves the problem. I know the delay worked at some point, but I'm not sure if this was on 12.1 or 12.0.

Should I file a radar with a sample project?
How to use SKTestSession in UI Tests?
 
 
Q