<?xml version="1.0" encoding="UTF-8"?>
<!--
 /**
  * Copyright © Magento, Inc. All rights reserved.
  * See COPYING.txt for license details.
  */
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
    <!--Begin checkout and proceed to final step-->
    <actionGroup name="AmazonCheckoutBeginActionGroup">
        <waitForElement selector="{{CheckoutShippingMethodsSection.shippingMethodRow}}" time="20" stepKey="apWaitForShipping"/>
        <waitForPageLoad stepKey="apWaitPageLoadShipping" />

        <click selector="{{CheckoutShippingMethodsSection.firstShippingMethod}}" stepKey="clickShippingMethod"/>
        <waitForPageLoad stepKey="waitForPageLoadPayment1" />
        <waitForLoadingMaskToDisappear stepKey="waitForLoadingMaskToDisappear1"/>

        <click selector="{{CheckoutShippingMethodsSection.next}}" stepKey="clickContinueButton"/>
        <waitForPageLoad stepKey="waitForPageLoadPayment2" />
        <waitForLoadingMaskToDisappear stepKey="waitForLoadingMaskToDisappear2"/>
    </actionGroup>
    <!--Place order-->
    <actionGroup name="AmazonCheckoutSubmitActionGroup" extends="AmazonCheckoutBeginActionGroup">
        <!--Click Place Order button-->
        <click selector="{{CheckoutPaymentSection.placeOrder}}" stepKey="clickPlaceOrder"/>

        <!--See success messages-->
        <see selector="{{CheckoutSuccessMainSection.successTitle}}" userInput="Thank you for your purchase!" stepKey="waitForLoadSuccessPage"/>
    </actionGroup>
    <!--Select credit card number and submit-->
    <actionGroup name="AmazonCheckoutCcActionGroup">
        <arguments>
            <argument name="cc" defaultValue="1111" type="string"/>
        </arguments>
        <executeJS function="return window.name;" stepKey="topName"/>
        <!--Get wallet iframe name (dynamic)-->
        <executeJS function="return jQuery('#walletWidgetDiv iframe').attr('name');" stepKey="iframeName"/>
        <!--Expand Wallet Widget to expose all CC# (and avoid JS paging)-->
        <executeJS function="jQuery('#walletWidgetDiv').css('height', '450px');" stepKey="executeJsHeight"/>
        <!--Select CC#-->
        <switchToIFrame userInput="{$iframeName}" stepKey="switchToIFrameWidget"/>
        <executeJS function="$('.card-number:contains({{cc}})').closest('a').click();" stepKey="executeJsCc"/>
        <!--Place order-->
        <switchToWindow userInput="{$topName}" stepKey="switchToWindowTop" />
        <waitForPageLoad stepKey="waitForPageLoadPayment1" />
        <click selector="{{CheckoutPaymentSection.placeOrder}}" stepKey="clickPlaceOrder"/>
        <waitForPageLoad stepKey="waitForPageLoadPayment2"/>
    </actionGroup>
</actionGroups>