<?xml version="1.0" encoding="UTF-8"?>
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
    <actionGroup name="FillDataOnNewPaymentMethodFormActionGroup">
        <annotations>
            <description>Fills the card number, expiration date and the security code on a Stripe Elements add payment method form.</description>
        </annotations>
        <arguments>
            <argument name="CardNumber" defaultValue="{{Cards.successCard}}" type="string"/>
            <argument name="ExpDate" defaultValue="{{Cards.expDate}}" type="string"/>
            <argument name="CVC" defaultValue="{{Cards.cvc}}" type="string"/>
            <argument name="country" defaultValue="{{SavedPaymentMethod.country}}" type="string"/>
            <argument name="zipCode" defaultValue="{{SavedPaymentMethod.zipCode}}" type="string"/>
        </arguments>

        <!-- Switch to Pay By Card iFrame -->
        <switchToIFrame selector="{{StorefrontCustomerPaymentMethodsFormSection.paymentElementIframe}}" stepKey="switchToPaymentElementIframe"/>

        <!-- Wait for element with class ".p-PaymentMethodSelector" -->
        <waitForElementVisible selector="{{StorefrontCustomerPaymentMethodsFormSection.paymentMethodSelector}}" stepKey="waitForPaymentMethodSelector" time="30"/>

        <!-- Wait for the payment method form to load -->
        <waitForElementVisible selector="{{StorefrontCustomerPaymentMethodsFormSection.paymentForm}}" stepKey="waitForPaymentForm" time="5"/>

        <!-- Fill the card number -->
        <fillField selector="{{StorefrontCustomerPaymentMethodsFormSection.payByCardNumberField}}" userInput="{{CardNumber}}" stepKey="fillCardNumber"/>
        <wait time="1" stepKey="waitForChangeEvent1"/>

        <!-- Fill the expiration date -->
        <fillField selector="{{StorefrontCustomerPaymentMethodsFormSection.payByCardExpField}}" userInput="{{ExpDate}}" stepKey="fillExpDate"/>
        <wait time="1" stepKey="waitForChangeEvent2"/>

        <!-- Fill the CVC number -->
        <fillField selector="{{StorefrontCustomerPaymentMethodsFormSection.payByCardCvcField}}" userInput="{{CVC}}" stepKey="fillCVC"/>
        <wait time="1" stepKey="waitForChangeEvent3"/>

        <!-- Select the country -->
        <selectOption selector="{{StorefrontCustomerPaymentMethodsFormSection.payByCardCountryField}}" userInput="{{country}}" stepKey="fillCountry"/>

        <!-- Wait for the zip code field -->
        <waitForElementVisible selector="{{StorefrontCustomerPaymentMethodsFormSection.payByCardZipField}}" stepKey="waitForZipField" time="5"/>
        <wait time="1" stepKey="waitForChangeEvent4"/>

        <!-- Fill zip code -->
        <fillField selector="{{StorefrontCustomerPaymentMethodsFormSection.payByCardZipField}}" userInput="{{zipCode}}" stepKey="fillZipcode"/>
        <wait time="1" stepKey="waitForChangeEvent5"/>

        <switchToIFrame stepKey="switchOutOfPayByCardIframe"/>

    </actionGroup>
</actionGroups>
