@@ -14,19 +14,93 @@ class EmbeddedUITests: PaymentSheetUITestCase {
14
14
settings. mode = . payment
15
15
settings. integrationType = . deferred_csc
16
16
settings. uiStyle = . embedded
17
+ settings. formSheetAction = . continue
17
18
loadPlayground ( app, settings)
18
19
app. buttons [ " Present embedded payment element " ] . waitForExistenceAndTap ( )
19
- // TODO: Test card form (see PaymentSheetVerticalUITests testUpdate)
20
-
21
- // Selecting Alipay w/ deferred PaymentIntent...
20
+
21
+ // Entering a card w/ deferred PaymentIntent...
22
+ app. buttons [ " Card " ] . waitForExistenceAndTap ( )
23
+ XCTAssertTrue ( app. staticTexts [ " Add card " ] . waitForExistence ( timeout: 10 ) )
24
+ try ! fillCardData ( app, postalEnabled: true )
25
+ app. toolbars. buttons [ " Done " ] . waitForExistenceAndTap ( )
26
+ XCTAssertTrue ( app. buttons [ " Continue " ] . isEnabled)
27
+ app. buttons [ " Continue " ] . waitForExistenceAndTap ( )
28
+ XCTAssertTrue ( app. staticTexts [ " Payment method " ] . waitForExistence ( timeout: 10 ) )
29
+ XCTAssertEqual ( app. staticTexts [ " Payment method " ] . label, " •••• 4242 " )
30
+
31
+ // ...and *updating* to a SetupIntent...
32
+ app. buttons. matching ( identifier: " Setup " ) . element ( boundBy: 1 ) . waitForExistenceAndTap ( )
33
+ // ...(wait for it to finish updating)...
34
+ XCTAssertTrue ( app. buttons [ " Reload " ] . waitForExistence ( timeout: 10 ) )
35
+ // ...should cause Card to no longer be the selected payment method.
36
+ XCTAssertFalse ( app. staticTexts [ " Payment method " ] . exists)
37
+
38
+ // ....Tapping card should show the card form with details preserved
39
+ app. buttons [ " Card " ] . waitForExistenceAndTap ( )
40
+ // ...thus the Continue button should be enabled
41
+ app. buttons [ " Continue " ] . waitForExistenceAndTap ( )
42
+ // ...should cause the card ending in 4242 that was previously entered to be the selected payment method
43
+ XCTAssertTrue ( app. staticTexts [ " Payment method " ] . waitForExistence ( timeout: 10 ) )
44
+ XCTAssertEqual ( app. staticTexts [ " Payment method " ] . label, " •••• 4242 " )
45
+ // ...switching from setup to payment should preserve this card as the selected payment method
46
+ app. buttons. matching ( identifier: " Payment " ) . element ( boundBy: 1 ) . waitForExistenceAndTap ( )
47
+ // ...(wait for it to finish updating)...
48
+ XCTAssertTrue ( app. buttons [ " Reload " ] . waitForExistence ( timeout: 10 ) )
49
+ // ...card entered for setup should be preserved after update
50
+ XCTAssertTrue ( app. staticTexts [ " Payment method " ] . waitForExistence ( timeout: 10 ) )
51
+ XCTAssertEqual ( app. staticTexts [ " Payment method " ] . label, " •••• 4242 " )
52
+
53
+ // ...selecting Alipay w/ deferred PaymentIntent...
22
54
app. buttons [ " Alipay " ] . waitForExistenceAndTap ( )
23
55
XCTAssertEqual ( app. staticTexts [ " Payment method " ] . label, " Alipay " )
24
56
// ...and *updating* to a SetupIntent...
25
- app. buttons. matching ( identifier: " Setup " ) . element ( boundBy: 1 ) . tap ( )
57
+ app. buttons. matching ( identifier: " Setup " ) . element ( boundBy: 1 ) . waitForExistenceAndTap ( )
26
58
// ...(wait for it to finish updating)...
27
- _ = app. buttons [ " Reload " ] . waitForExistence ( timeout: 10 )
59
+ XCTAssertTrue ( app. buttons [ " Reload " ] . waitForExistence ( timeout: 10 ) )
28
60
// ...should cause Alipay to no longer be the selected payment method, since it is not valid for setup.
29
61
XCTAssertFalse ( app. staticTexts [ " Payment method " ] . exists)
62
+
63
+ // ...go back into deferred PaymentIntent mode
64
+ app. buttons. matching ( identifier: " Payment " ) . element ( boundBy: 1 ) . waitForExistenceAndTap ( )
65
+ // ...(wait for it to finish updating)...
66
+ XCTAssertTrue ( app. buttons [ " Reload " ] . waitForExistence ( timeout: 10 ) )
67
+ //...selecting Cash App Pay w/ deferred PaymentIntent...
68
+ app. buttons [ " Cash App Pay " ] . waitForExistenceAndTap ( )
69
+ XCTAssertEqual ( app. staticTexts [ " Payment method " ] . label, " Cash App Pay " )
70
+ // ...and *updating* to a SetupIntent...
71
+ app. buttons. matching ( identifier: " Setup " ) . element ( boundBy: 1 ) . waitForExistenceAndTap ( )
72
+ // ...(wait for it to finish updating)...
73
+ XCTAssertTrue ( app. buttons [ " Reload " ] . waitForExistence ( timeout: 10 ) )
74
+ // ...should cause Cash App Pay to be the selected payment method, since it is valid for setup.
75
+ XCTAssertEqual ( app. staticTexts [ " Payment method " ] . label, " Cash App Pay " )
76
+
77
+ // ...go back into deferred PaymentIntent mode
78
+ app. buttons. matching ( identifier: " Payment " ) . element ( boundBy: 1 ) . waitForExistenceAndTap ( )
79
+ // ...(wait for it to finish updating)...
80
+ XCTAssertTrue ( app. buttons [ " Reload " ] . waitForExistence ( timeout: 10 ) )
81
+ //...selecting Klarna w/ deferred PaymentIntent...
82
+ app. buttons [ " Klarna " ] . waitForExistenceAndTap ( )
83
+ // ...fill out the form for Klarna
84
+ let emailField = app. textFields [ " Email " ]
85
+ emailField. waitForExistenceAndTap ( )
86
+ emailField. typeText ( " mobile-payments-sdk-ci+ \( UUID ( ) ) @stripe.com " )
87
+ app. buttons [ " Continue " ] . waitForExistenceAndTap ( )
88
+ XCTAssertEqual ( app. staticTexts [ " Payment method " ] . label, " Klarna " )
89
+ // ...and *updating* to a SetupIntent...
90
+ app. buttons. matching ( identifier: " Setup " ) . element ( boundBy: 1 ) . waitForExistenceAndTap ( )
91
+ // ...(wait for it to finish updating)...
92
+ XCTAssertTrue ( app. buttons [ " Reload " ] . waitForExistence ( timeout: 10 ) )
93
+ // ...should cause Klarna to no longer be the selected payment method.
94
+ XCTAssertFalse ( app. staticTexts [ " Payment method " ] . exists)
95
+ // ...selecting Klarna should present a Klarna form with the previously entered email
96
+ app. buttons [ " Klarna " ] . waitForExistenceAndTap ( )
97
+ app. buttons [ " Continue " ] . waitForExistenceAndTap ( )
98
+ // ...switching back to payment should keep Klarna selected
99
+ app. buttons. matching ( identifier: " Payment " ) . element ( boundBy: 1 ) . waitForExistenceAndTap ( )
100
+ // ...(wait for it to finish updating)...
101
+ XCTAssertTrue ( app. buttons [ " Reload " ] . waitForExistence ( timeout: 10 ) )
102
+ // ... Klarna should still be selected
103
+ XCTAssertEqual ( app. staticTexts [ " Payment method " ] . label, " Klarna " )
30
104
}
31
105
32
106
func testSingleCardCBC_update_and_remove_selectStateApplePay( ) {
@@ -293,6 +367,110 @@ class EmbeddedUITests: PaymentSheetUITestCase {
293
367
XCTAssertTrue ( applePayButton. waitForExistence ( timeout: 3.0 ) )
294
368
XCTAssertTrue ( applePayButton. isSelected)
295
369
}
370
+
371
+ func testSelection( ) {
372
+ var settings = PaymentSheetTestPlaygroundSettings . defaultValues ( )
373
+ settings. mode = . paymentWithSetup
374
+ settings. uiStyle = . paymentSheet
375
+ settings. customerKeyType = . legacy
376
+ settings. formSheetAction = . continue
377
+ settings. customerMode = . new
378
+ loadPlayground ( app, settings)
379
+
380
+ // Start by saving a new card
381
+ app. buttons [ " Present PaymentSheet " ] . waitForExistenceAndTap ( )
382
+ try ! fillCardData ( app, postalEnabled: true )
383
+
384
+ // Complete payment
385
+ app. buttons [ " Pay $50.99 " ] . tap ( )
386
+ XCTAssertTrue ( app. staticTexts [ " Success! " ] . waitForExistence ( timeout: 10 ) )
387
+
388
+ // Switch to embedded mode kicks off a reload
389
+ app. buttons [ " embedded " ] . waitForExistenceAndTap ( timeout: 5 )
390
+ app. buttons [ " Payment " ] . waitForExistenceAndTap ( timeout: 5 )
391
+ app. buttons [ " Present embedded payment element " ] . waitForExistenceAndTap ( )
392
+
393
+ // Should auto select a saved payment method
394
+ XCTAssertEqual ( app. staticTexts [ " Payment method " ] . label, " •••• 4242 " )
395
+
396
+ // Open card and cancel, should reset selection to saved card
397
+ app. buttons [ " New card " ] . waitForExistenceAndTap ( )
398
+ app. buttons [ " Close " ] . waitForExistenceAndTap ( )
399
+ XCTAssertTrue ( app. buttons [ " Checkout " ] . isEnabled)
400
+ XCTAssertEqual ( app. staticTexts [ " Payment method " ] . label, " •••• 4242 " )
401
+
402
+ // Select Cash App Pay
403
+ app. buttons [ " Cash App Pay " ] . waitForExistenceAndTap ( )
404
+ XCTAssertTrue ( app. staticTexts [ " Cash App Pay " ] . waitForExistence ( timeout: 10 ) )
405
+ XCTAssertTrue ( app. buttons [ " Checkout " ] . isEnabled)
406
+
407
+ // Open card and cancel, should reset back to Cash App Pay
408
+ app. buttons [ " New card " ] . waitForExistenceAndTap ( )
409
+ app. buttons [ " Close " ] . waitForExistenceAndTap ( )
410
+ XCTAssertTrue ( app. staticTexts [ " Cash App Pay " ] . waitForExistence ( timeout: 10 ) )
411
+ XCTAssertTrue ( app. buttons [ " Checkout " ] . isEnabled)
412
+
413
+ // Try to fill a card
414
+ app. buttons [ " New card " ] . waitForExistenceAndTap ( )
415
+ XCTAssertTrue ( app. staticTexts [ " Add new card " ] . waitForExistence ( timeout: 10 ) )
416
+ try ! fillCardData ( app, cardNumber: " 5555555555554444 " , postalEnabled: true )
417
+ app. toolbars. buttons [ " Done " ] . waitForExistenceAndTap ( )
418
+ app. buttons [ " Continue " ] . waitForExistenceAndTap ( )
419
+ XCTAssertTrue ( app. staticTexts [ " Payment method " ] . waitForExistence ( timeout: 10 ) )
420
+ XCTAssertEqual ( app. staticTexts [ " Payment method " ] . label, " •••• 4444 " )
421
+ XCTAssertTrue ( app. buttons [ " Checkout " ] . isEnabled)
422
+
423
+ // Tapping on card again should present the form filled out
424
+ app. buttons [ " New card " ] . waitForExistenceAndTap ( )
425
+ XCTAssertTrue ( app. staticTexts [ " Add new card " ] . waitForExistence ( timeout: 10 ) )
426
+ let cardNumberField = app. textFields [ " Card number " ]
427
+ XCTAssertEqual ( cardNumberField. value as? String , " 5555555555554444 " , " Card number field should contain the entered card number. " )
428
+ app. buttons [ " Close " ] . waitForExistenceAndTap ( )
429
+ XCTAssertTrue ( app. staticTexts [ " Payment method " ] . waitForExistence ( timeout: 10 ) )
430
+ XCTAssertEqual ( app. staticTexts [ " Payment method " ] . label, " •••• 4444 " )
431
+ XCTAssertTrue ( app. buttons [ " Checkout " ] . isEnabled)
432
+
433
+ // Select and cancel out a form PM to ensure that the 4242 card is still selected
434
+ app. buttons [ " Klarna " ] . waitForExistenceAndTap ( )
435
+ app. buttons [ " Close " ] . waitForExistenceAndTap ( )
436
+ XCTAssertTrue ( app. staticTexts [ " Payment method " ] . waitForExistence ( timeout: 10 ) )
437
+ XCTAssertEqual ( app. staticTexts [ " Payment method " ] . label, " •••• 4444 " )
438
+ XCTAssertTrue ( app. buttons [ " Checkout " ] . isEnabled)
439
+
440
+ // Select a no-form PM such as Cash App Pay
441
+ app. buttons [ " Cash App Pay " ] . waitForExistenceAndTap ( )
442
+ XCTAssertTrue ( app. staticTexts [ " Cash App Pay " ] . waitForExistence ( timeout: 10 ) )
443
+ XCTAssertTrue ( app. buttons [ " Checkout " ] . isEnabled)
444
+
445
+ // Fill out US Bank Acct.
446
+ app. buttons [ " US bank account " ] . waitForExistenceAndTap ( )
447
+ // Fill out name and email fields
448
+ let continueButton = app. buttons [ " Continue " ]
449
+ XCTAssertFalse ( continueButton. isEnabled)
450
+ app. textFields [ " Full name " ] . tap ( )
451
+ app. typeText ( " John Doe " + XCUIKeyboardKey. return. rawValue)
452
+ app. typeText ( " test- \( UUID ( ) . uuidString) @example.com " + XCUIKeyboardKey. return. rawValue)
453
+ XCTAssertTrue ( continueButton. isEnabled)
454
+ continueButton. tap ( )
455
+
456
+ // Go through connections flow
457
+ app. buttons [ " Agree and continue " ] . waitForExistenceAndTap ( )
458
+ app. staticTexts [ " Test Institution " ] . forceTapElement ( )
459
+ // "Success" institution is automatically selected because its the first
460
+ app. buttons [ " connect_accounts_button " ] . waitForExistenceAndTap ( timeout: 10 )
461
+
462
+ let notNowButton = app. buttons [ " Not now " ]
463
+ if notNowButton. waitForExistence ( timeout: 10 ) {
464
+ app. typeText ( XCUIKeyboardKey . return. rawValue) // dismiss keyboard
465
+ notNowButton. tap ( )
466
+ }
467
+
468
+ app. buttons [ " Continue " ] . waitForExistenceAndTap ( )
469
+ app. buttons [ " Continue " ] . waitForExistenceAndTap ( )
470
+ XCTAssertTrue ( app. staticTexts [ " Payment method " ] . waitForExistence ( timeout: 10 ) )
471
+ XCTAssertEqual ( app. staticTexts [ " Payment method " ] . label, " ••••6789 " )
472
+ XCTAssertTrue ( app. buttons [ " Checkout " ] . isEnabled)
473
+ }
296
474
297
475
func dismissAlertView( alertBody: String , alertTitle: String , buttonToTap: String ) {
298
476
let alertText = app. staticTexts [ alertBody]
0 commit comments