stripe / stripe-ios

Stripe iOS SDK
https://stripe.com
MIT License
2.05k stars 956 forks source link

[Feature] UITesting bypass PaymentSheet #2626

Open jesus-mg-ios opened 1 year ago

jesus-mg-ios commented 1 year ago

Is your feature request related to a problem? Please describe.

Hi I'm coding UITests with simulator, and I'm wondering if there's a way to bypass the payment sheet, like apple does with store kit files or sessions. The purpose is to wait for payment sheet appearance and avoid filling the card fields with a test card, because, yes you can do it, but they are not tagged to be accessible by identifiers in UITests.

Describe the solution you'd like

Maybe could be a static variable with #!Release PRAGMA MARK sounding it where I can change to set "automatic testing" and when the sheet appears all the data is already filled, to only push the button and confirm the purchase, or close the sheet and test the failure/cancel flow.

Describe alternatives you've considered

Another possibility is to change the payment sheet code and with a static var boolean change it from normal use to automatic testing, also surrounded with pragma marks. But Maybe is something more complex though you clearly decouple code from release to not release.

Additional context

Obviously, if the automatic testing code is surrounded by a pragma mark it can defer to normal use flow to give us the option to manage it and take it the way we want in the case we want.

Thanks in advance.

davidme-stripe commented 1 year ago

Thanks for filing! This is a good idea, we'll consider it for a future update.

For now, feel free to copy code from our tests: We have some tests for our PaymentSheet Example app, along with some XCUITest functions to fill a card automatically. I think we have accessibility labels on most components, but let us know if you see any missing ones that would be useful for your tests.

jesus-mg-ios commented 1 year ago

Thanks @davidme-stripe I'll take a look into it.

jesus-mg-ios commented 1 year ago

The code only works if the app is in English.