mobile-dev-inc / maestro

Painless Mobile UI Automation
https://maestro.mobile.dev/
Apache License 2.0
5.82k stars 272 forks source link

Support StoreKit Testing on iOS #945

Open ainame opened 1 year ago

ainame commented 1 year ago

I've been looking into maestro to migrate our UI testing layer from XCTest. It is essential for us and other iOS devs/teams to test IAP (in-app purchase) flows. I think it's currently missing in maestro.

In the normal XCTest world, since 2020, we can test IAP flows locally on iOS Simulator with StoreKit by StoreKit configuration file.

We can use SKTestSession from the StoreKitTest framework to load the .storekit file for UI testing.

It would be tough to support the capability to load the .storekit configuration file for maestro but I'm sure many maestro users would appreciate it if it's implemented.


According to this blog post, within StoreKitTest framework, it's using XPCto communicate between processes. maestro can perhaps re-implement SKTestSession by itself.

I wonder if we can just put SKTestSession code somewhere within this file to load the .storekit configuration file conditionally (sorry I haven't figured out the entire architecture of maestro for iOS platform). https://github.com/mobile-dev-inc/maestro/blob/main/maestro-driver-ios/maestro-driver-iosUITests/maestro_driver_iosUITests.swift

ainame commented 1 year ago

I got a small PoC code that works with our project at my work. I'll share ideas and the piece of code I used soon 🙏

ainame commented 1 year ago

I published two things for PoC. Nothing is done properly. It's a quick and dirty implementation.

To test it,

  1. Prepare iOS simulator and an iOS app that implemented IAP.
  2. Check out my forked repo and branch
  3. Update maestro_driver_iosUITests.swift to put your .storekit file path or even hardcode the file content
  4. Run ./maestro-driver-ios/build-maestro-ios-runner.sh to update the iOS-driver
  5. Run ./maestro test with your yaml file.

↓ You can see at least the IAP dialogue on your simulator hopefully

Screenshot 2023-03-31 at 18 24 57

This has proven maestro can incorporate StoreKit Testing support. For the proper implementation, I believe we can add new Handlers and Routes for operations around StoreKit Testing, just like other operations. We'll still need to work on further reverse engineering to figure out what to do for things available in SKTestSession; for example, SKTestSession.disableDialogs property is a great configuration for UI testing, but the XPC interfaces don't expose that API directly and instead uses setInteger method. We need to find out the key to it.

Let me know what you think. I can spend some time helping with implementation if needed.