<?xml version="1.0" encoding="UTF-8"?>
<!--
 /**
  * Copyright © Magento, Inc. All rights reserved.
  * See COPYING.txt for license details.
  *
  * This file is part of the Klarna KP module
  *
  * (c) Klarna Bank AB (publ)
  *
  * For the full copyright and license information, please view the NOTICE
  * and LICENSE files that were distributed with this source code.
  */
-->
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
    <actionGroup name="PlaceOrderWithKlarnaPaymentsMethod">
        <arguments>
            <argument name="paymentMethod" type="entity"/>
        </arguments>
        <!--Select Klarna Payments method-->
        <waitForLoadingMaskToDisappear stepKey="waitForLoadingMask"/>
        <waitForElementVisible selector="{{CheckoutPaymentSection.klarnaPaymentsMethod(paymentMethod.label)}}" stepKey="waitForKlarnaPaymentsMethod"/>
        <click selector="{{CheckoutPaymentSection.klarnaPaymentsMethod(paymentMethod.label)}}" stepKey="selectKlarnaPaymentsMethod"/>

        <!--Wait for Klarna Payments iframe content to render and resize-->
        <waitForElementVisible selector="{{CheckoutPaymentSection.klarnaPaymentsIframeElement(paymentMethod.iframe)}}" stepKey="waitForKlarnaPaymentsIframe"/>
        <switchToIFrame selector="{{CheckoutPaymentSection.klarnaPaymentsIframe(paymentMethod.iframe)}}" stepKey="enterKlarnaPaymentsIframe"/>
        <waitForElementNotVisible selector="{{CheckoutPaymentSection.klarnaPaymentsPaymentSelectorLoader}}" stepKey="waitForLoaderToDisappear"/>
        <waitForElementVisible selector="{{CheckoutPaymentSection.klarnaPaymentsPaymentSelector}}" stepKey="waitForKlarnaPaymentSelector"/>
        <!--We need to wait to allow the iframe and place order button elements to stop moving around-->
        <wait time="1" stepKey="waitForKlarnaPaymentsIframeToResize"/>
        <switchToIFrame stepKey="goBackToTopLevelFrame"/>

        <!--Place order-->
        <waitForElement selector="{{CheckoutPaymentSection.klarnaPaymentsPlaceOrderButton}}" stepKey="waitForPlaceOrderButton"/>
        <click selector="{{CheckoutPaymentSection.klarnaPaymentsPlaceOrderButton}}" stepKey="clickPlaceOrderButton"/>

        <!--Confirm redirection to success page-->
        <waitForElementVisible selector="{{CheckoutSuccessMainSection.successTitle}}" time="30" stepKey="waitForSuccessPageTitle"/>
        <waitForElementVisible selector="{{CheckoutSuccessMainSection.success}}" time="30" stepKey="waitForSuccessPageSuccessBlock"/>
    </actionGroup>
</actionGroups>
