<?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">
    <actionGroup name="ApplyCartRuleOnStorefrontActionGroup">
        <annotations>
            <description>Clicks on Add to Cart on a Storefront Product page. Validates that the Success Message is present and correct. Goes to the Storefront Shopping Cart page. Applies the provided Coupon Code to the Shopping Cart.</description>
        </annotations>
        <arguments>
            <argument name="product"/>
            <argument name="couponCode" type="string"/>
        </arguments>

        <waitForElementNotVisible selector="{{StorefrontProductActionSection.addToCartDisabled}}" stepKey="waitForAddToCartButtonToRemoveDisabledState"/>
        <waitForElementClickable selector="{{StorefrontProductActionSection.addToCart}}" stepKey="waitForAddToCartButton"/>
        <click selector="{{StorefrontProductActionSection.addToCart}}" stepKey="addToCart"/>
        <waitForPageLoad stepKey="waitForAddToCart"/>
        <waitForElementVisible selector="{{StorefrontMessagesSection.success}}" stepKey="waitForSuccessMessage"/>
        <waitForText userInput="You added {{product.name}} to your shopping cart." stepKey="waitForText"/>
        <amOnPage url="{{CheckoutCartPage.url}}" stepKey="goToCheckoutPage"/>
        <waitForPageLoad stepKey="waitForPageLoad1"/>
        <click selector="{{DiscountSection.DiscountTab}}" stepKey="clickToDiscountTab"/>
        <fillField selector="{{DiscountSection.CouponInput}}" userInput="{{couponCode}}" stepKey="fillCouponCode"/>
        <click selector="{{DiscountSection.ApplyCodeBtn}}" stepKey="applyCode"/>
        <waitForPageLoad stepKey="waitForPageLoad2"/>
    </actionGroup>
</actionGroups>
