Test Apple Pay on XCUITest
Test Apple Pay on remote BrowserStack iOS devices using App Automate.
- This feature is currently a Private Beta service and available only under Device Cloud Pro, Device Cloud Pro + Visual Cloud, and Enterprise Pro plans. Contact our Support team or Sales team to enable this feature. For more details check out our pricing page.
- Enabling this feature increases the session start time by 100-180 seconds. BrowserStack recommends using this feature only when needed.
Apple Pay enables one-click payments and purchases on iOS devices while providing additional security. Using BrowserStack App Automate, you can integrate Apple Pay into your mobile apps on selected remote iOS devices.
Supported apps
App Automate supports testing of Apple Pay with mobile apps that are signed using Apple’s Developer Enterprise Program. Also, ensure that your app has Apple Pay entitlement added as a dependency.
Supported devices and OS versions
Supported Devices | iOS Version |
---|---|
iPhone 15 | 17 |
iPhone 14 | 16 |
iPhone 14 Pro | 16 |
iPhone 13 Pro Max | 15 |
iPhone 13 Pro | 15 |
iPhone 13 Mini | 15 |
iPhone 13 | 15 |
iPhone 11 Pro | 15 |
iPhone 11 | 15 |
iPhone XR | 15 |
Enable Apple Pay
Use BrowserStack parameter enableApplePay
and set it to true
in the REST API request to enable the Apple pay functionality for your XCUITest test session.
curl -u "username:accesskey" \
-X POST "https://api-cloud.browserstack.com/app-automate/xcuitest/v2/build" \
-d '{
"app": "bs://j3c874f21852ba57957a3fdc33f47514288c4ba4",
"testSuite": "bs://f7c874f21852ba57957a3fdc33f47514288c4ba4",
"devices": ["iPhone 13-15"], "resignApp": "false", "enableApplePay": "true"}' \
-H "Content-Type: application/json"
Upon passing this parameter, the following actions are completed on the device before starting your XCUITest session:
- A passcode is set on the device.
- A sample card for testing payments is added to the Wallet app.
- Assistive Touch is enabled.
- Apple Pay is added to the Assistive Touch menu.
Add Apple Pay details, such as shipping, billing, or contact information, by including the applePayDetails
parameter.
For the Apple Pay details, ensure the details meet the following conditions:
- In your shipping and billing addresses, include only the parameters that apply to the addresses and remove the parameters that are not applicable. For example, if your test address doesn’t have a value for the province parameter, remove the parameter from the script.
- For the geographical codes in your shipping and billing addresses, use only one of these parameters based on what your address requires and the device accepts: postalCode, postCode, zip. In the following code snippet, we have used postalCode.
- The phone number must have the country code prefix with the + character. For example, use this +1-212-456-7890 or +12124567890.
Here is an example to include the applePayDetails
parameter:
curl -u "username:accesskey" \
-X POST "https://api-cloud.browserstack.com/app-automate/xcuitest/v2/build" \
-d '{"app": "bs://35aff36f491562013a0ebfe5b70bdfc4db0b185d", "testSuite": "bs://b79b6c49722802a42d9fba7601cde8dcd75ab8fd", "devices": ["iPhone 15-17"], "enableApplePay": "true", "resignApp": "false",
"applePayDetails": {
"billingDetails": {
"firstName": "FirstName",
"lastName": "LastName",
"state": "California",
"city": "Mountain View",
"street": "160 Amphitheatre",
"zip": "94043",
"country": "United States",
"addressLine2", "Address",
"postalCode": "90043",
"postCode": "90043",
"zip": "90043",
"province": "Province",
"islandName": "Island"
},
"contact": {
"email": "email@mail.com",
"phone": "123-456-7890" }} }' \
-H "Content-Type: application/json"
You need to set the resignApp
parameter to false
when testing Apple Pay to disable re-signing of Enterprise signed app uploaded on BrowserStack. Checkout Disable re-signing iOS apps documentation for more information.
Test Apple Pay payment
Trigger the payment workflow that uses Apple Pay as the payment method using your framework-specific commands.
After you trigger the Apple pay payment from your app, confirm it using assistive touch and enter your device passcode to complete the payment.
To confirm the Apple pay payment, use the following XCUITest code:
func tapButton(element: XCUIElement, app: XCUIApplication) {
let xCoordinate = element.frame.origin.x
let yCoordinate = element.frame.origin.y
let width = element.frame.size.width
let height = element.frame.size.height
let xCenter = xCoordinate + (width / 2)
let yCenter = yCoordinate + (height / 2)
let coordinate = app.coordinate(withNormalizedOffset: CGVector(dx: 0, dy: 0))
let touchCordinate = coordinate.withOffset(CGVector(dx: xCenter, dy: yCenter))
touchCordinate.tap()
}
func confirmApplePayPayment(app: XCUIApplication) {
// Accessibility App
let accessbility = XCUIApplication(bundleIdentifier: "com.apple.assistivetouchd")
// Define a predicate to find the Assistive Touch
let existsPredicate = NSPredicate(format: "exists == true")
let assistiveTouchButton = accessbility.otherElements["AssistiveTouchNubbit"]
let expectation = XCTNSPredicateExpectation(predicate: existsPredicate, object: assistiveTouchButton)
let result = XCTWaiter().wait(for: [expectation], timeout: 2.0)
print("Tapping assistive touch")
tapButton(element: assistiveTouchButton, app: app)
print("Tapping Apple pay button")
let applePayButton = accessbility.otherElements["Pay"]
tapButton(element: applePayButton, app: app)
print("Tapping confirm apple pay button")
let confirmApplePayButton = accessbility.otherElements["Confirm Pay"]
tapButton(element: confirmApplePayButton, app: app)
// Enter device Passcode
let springApp = XCUIApplication(bundleIdentifier: "com.apple.springboard")
sleep(2)
let secureField = springApp.secureTextFields.firstMatch
XCTAssert(secureField.exists, "Passcode field not found")
secureField.tap()
secureField.typeText("123456")
}
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
Thank you for your valuable feedback!