I personally donโt have exp with it but I might be a weird suggestion but have you tried asking chatGPT? It often comes up with good stuff for me:
It is true that Apple has made changes to their XCUITest framework that may impact the ability to interact with Apple Pay screens and home button via automation. However, it is still possible to automate Apple Pay on iOS devices with ecommerce web pages using Appium and Selenium.
Some Appium and Selenium users have reported success in automating Apple Pay on iOS devices with ecommerce web pages. However, the specific implementation may vary depending on the website being tested and the iOS device being used. It is possible that the ability to interact with Apple Pay screens and home button via automation may be limited on some devices or with certain versions of iOS.
If you are having trouble automating Apple Pay on iOS devices with ecommerce web pages, it may be helpful to reach out to the Appium or Selenium community for guidance or to consider exploring other testing tools or frameworks that may better support this functionality.
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.net.URL;
public class ApplePayTest {
public static void main(String[] args) throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS");
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "14.5");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone 12 Pro Max");
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "Safari");
capabilities.setCapability("automationName", "XCUITest");
capabilities.setCapability("useNewWDA", true);
capabilities.setCapability("wdaLaunchTimeout", 240000);
capabilities.setCapability("xcodeSigningId", "iPhone Developer");
capabilities.setCapability("xcodeOrgId", "YOUR_ORG_ID");
capabilities.setCapability("updatedWDABundleId", "YOUR_BUNDLE_ID");
capabilities.setCapability("startIWDP", true);
IOSDriver driver = new IOSDriver(new URL("http://localhost:4723/wd/hub"), capabilities);
driver.get("https://example.com/checkout");
// Check if the user's device supports Apple Pay
boolean isApplePaySupported = driver.executeScript("return window.ApplePaySession !== undefined");
if (isApplePaySupported) {
// Create a payment request
String merchantIdentifier = "YOUR_MERCHANT_IDENTIFIER";
String countryCode = "US";
String currencyCode = "USD";
String totalLabel = "Total";
String totalAmount = "10.00";
String paymentRequestScript = "var paymentRequest = {\n" +
" countryCode: '" + countryCode + "',\n" +
" currencyCode: '" + currencyCode + "',\n" +
" total: {\n" +
" label: '" + totalLabel + "',\n" +
" amount: '" + totalAmount + "'\n" +
" }\n" +
" };\n" +
" ApplePaySession.canMakePaymentsWithActiveCard('" + merchantIdentifier + "')\n" +
" .then(function(canMakePayments) {\n" +
" if (canMakePayments) {\n" +
" var session = new ApplePaySession(1, paymentRequest);\n" +
" session.begin();\n" +
" }\n" +
" })\n";
driver.executeScript(paymentRequestScript);
// Wait for the payment sheet to appear
Thread.sleep(5000);
// Click the "Buy with Apple Pay" button
driver.findElementByClassName("apple-pay-button").click();
// Wait for the payment to be processed
Thread.sleep(5000);
// Verify that the payment was successful
String pageSource = driver.getPageSource();
if (pageSource.contains("Thank you for your order!")) {
System.out.println("Payment successful!");
} else {
System.out.println("Payment failed.");
}
} else {
System.out.println("Apple Pay is not supported on this device.");
}
driver.quit();
}
}
This test script launches Safari on an iPhone 12 Pro Max device running iOS 14.5, navigates to an ecommerce website, and interacts with the Apple Pay button to initiate a payment. The test script then waits for the payment to be processed and verifies that the payment was successful by checking the page source for a confirmation message. Finally, the script quits the driver.