Search code examples
xcodestorekitios14xcode12

SKProductsRequest fails in Xcode 12 GM in UI Tests and SKTestSession


When I run SKProductsRequest from UI Tests session in Xcode 12 GM, it always fails with this error:

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}}}

I tried to use SKTestSession with valid .storekit configuration file, but it didn't help. Though in my Unit Tests this works fine with SKTestSession.

Is there a way to test store in UI tests in Xcode 12 GM? Or SKTestSession is usable only in Unit Tests?


Solution

  • So after few days of digging seems like I found out what to do to make it work. You just need to add some delay before running SKProductsRequest at app launch. I set 5 seconds delay just for UI tests — and that's it! Now my request works!

    That's the line needed for the request to run without errors:

    // Wait for StoreKitTest
    Thread.sleep(forTimeInterval: 5)
    // Start request
    request.start()