<?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">
    <!--Navigate to create order page (New Order -> Create New Customer)-->
    <actionGroup name="navigateToNewOrderPageNewCustomer">
        <arguments>
            <argument name="storeView" defaultValue="_defaultStore"/>
        </arguments>
        <amOnPage url="{{AdminOrdersPage.url}}" stepKey="navigateToOrderIndexPage"/>
        <waitForPageLoad stepKey="waitForIndexPageLoad"/>
        <see selector="{{AdminHeaderSection.pageTitle}}" userInput="Orders" stepKey="seeIndexPageTitle"/>
        <click selector="{{AdminOrdersGridSection.createNewOrder}}" stepKey="clickCreateNewOrder"/>
        <click selector="{{AdminOrderFormActionSection.CreateNewCustomer}}" stepKey="clickCreateCustomer"/>
        <conditionalClick selector="{{AdminOrderStoreScopeTreeSection.storeOption(storeView.name)}}" dependentSelector="{{AdminOrderStoreScopeTreeSection.storeOption(storeView.name)}}" visible="true" stepKey="selectStoreViewIfAppears"/>
        <waitForPageLoad stepKey="waitForCreateOrderPageLoadAfterStoreSelect" />
        <see selector="{{AdminHeaderSection.pageTitle}}" userInput="Create New Order" stepKey="seeNewOrderPageTitle"/>
    </actionGroup>

    <!--Navigate to create order page (New Order -> Create New Customer)-->
    <actionGroup name="navigateToNewOrderPageNewCustomerSingleStore">
        <arguments>
            <argument name="storeView" defaultValue="_defaultStore"/>
        </arguments>
        <amOnPage url="{{AdminOrdersPage.url}}" stepKey="navigateToOrderIndexPage"/>
        <waitForPageLoad stepKey="waitForIndexPageLoad"/>
        <see selector="{{AdminHeaderSection.pageTitle}}" userInput="Orders" stepKey="seeIndexPageTitle"/>
        <click selector="{{AdminOrdersGridSection.createNewOrder}}" stepKey="clickCreateNewOrder"/>
        <click selector="{{AdminOrderFormActionSection.CreateNewCustomer}}" stepKey="clickCreateCustomer"/>
        <see selector="{{AdminHeaderSection.pageTitle}}" userInput="Create New Order" stepKey="seeNewOrderPageTitle"/>
    </actionGroup>

    <!--Navigate to create order page (New Order -> Select Customer)-->
    <actionGroup name="navigateToNewOrderPageExistingCustomer">
        <arguments>
            <argument name="customer"/>
            <argument name="storeView" defaultValue="_defaultStore"/>
        </arguments>
        <amOnPage url="{{AdminOrdersPage.url}}" stepKey="navigateToOrderIndexPage"/>
        <waitForPageLoad stepKey="waitForIndexPageLoad"/>
        <see selector="{{AdminHeaderSection.pageTitle}}" userInput="Orders" stepKey="seeIndexPageTitle"/>
        <click selector="{{AdminOrdersGridSection.createNewOrder}}" stepKey="clickCreateNewOrder"/>
        <waitForPageLoad stepKey="waitForCustomerGridLoad"/>
        <!--Clear grid filters-->
        <conditionalClick selector="{{AdminOrderCustomersGridSection.resetButton}}" dependentSelector="{{AdminOrderCustomersGridSection.resetButton}}" visible="true" stepKey="clearExistingCustomerFilters"/>
        <fillField userInput="{{customer.email}}" selector="{{AdminOrderCustomersGridSection.emailInput}}" stepKey="filterEmail"/>
        <click selector="{{AdminOrderCustomersGridSection.apply}}" stepKey="applyFilter"/>
        <waitForPageLoad stepKey="waitForFilteredCustomerGridLoad"/>
        <click selector="{{AdminOrderCustomersGridSection.firstRow}}" stepKey="clickOnCustomer"/>
        <waitForPageLoad stepKey="waitForCreateOrderPageLoad" />
        <!-- Select store view if appears -->
        <conditionalClick selector="{{AdminOrderStoreScopeTreeSection.storeOption(storeView.name)}}" dependentSelector="{{AdminOrderStoreScopeTreeSection.storeOption(storeView.name)}}" visible="true" stepKey="selectStoreViewIfAppears"/>
        <waitForPageLoad stepKey="waitForCreateOrderPageLoadAfterStoreSelect" />
        <see selector="{{AdminHeaderSection.pageTitle}}" userInput="Create New Order" stepKey="seeNewOrderPageTitle"/>
    </actionGroup>

    <!--Navigate to New Order Page for existing Customer And Store-->
    <actionGroup name="NavigateToNewOrderPageExistingCustomerAndStoreActionGroup" extends="navigateToNewOrderPageExistingCustomer" >
        <arguments>
            <argument name="storeView" defaultValue="_defaultStore"/>
        </arguments>
        <click selector="{{AdminOrderStoreScopeTreeSection.storeOption(storeView.name)}}" stepKey="selectStoreView" after="waitForCreateOrderPageLoad"/>
        <waitForPageLoad stepKey="waitForLoad" after="selectStoreView"/>
    </actionGroup>

    <!--Check the required fields are actually required-->
    <actionGroup name="checkRequiredFieldsNewOrderForm">
        <seeElement selector="{{AdminOrderFormAccountSection.requiredGroup}}" stepKey="seeCustomerGroupRequired"/>
        <seeElement selector="{{AdminOrderFormAccountSection.requiredEmail}}" stepKey="seeEmailRequired"/>
        <clearField selector="{{AdminOrderFormAccountSection.email}}" stepKey="clearEmailField"/>
        <clearField selector="{{AdminOrderFormBillingAddressSection.FirstName}}" stepKey="clearFirstNameField"/>
        <clearField selector="{{AdminOrderFormBillingAddressSection.LastName}}" stepKey="clearLastNameField"/>
        <clearField selector="{{AdminOrderFormBillingAddressSection.StreetLine1}}" stepKey="clearStreetField"/>
        <clearField selector="{{AdminOrderFormBillingAddressSection.City}}" stepKey="clearCityField"/>
        <selectOption selector="{{AdminOrderFormBillingAddressSection.Country}}" userInput="United States" stepKey="selectUSCountry"/>
        <selectOption selector="{{AdminOrderFormBillingAddressSection.State}}" userInput="Please select" stepKey="selectNoState"/>
        <clearField selector="{{AdminOrderFormBillingAddressSection.PostalCode}}" stepKey="clearPostalCodeField"/>
        <clearField selector="{{AdminOrderFormBillingAddressSection.Phone}}" stepKey="clearPhoneField"/>
        <seeElement selector="{{AdminOrderFormPaymentSection.getShippingMethods}}" stepKey="seeShippingMethodNotSelected"/>
        <click selector="{{AdminOrderFormActionSection.SubmitOrder}}" stepKey="trySubmitOrder"/>
        <see selector="{{AdminOrderFormBillingAddressSection.emailError}}" userInput="This is a required field." stepKey="seeThatEmailIsRequired"/>
        <see selector="{{AdminOrderFormBillingAddressSection.firstNameError}}" userInput="This is a required field." stepKey="seeFirstNameRequired"/>
        <see selector="{{AdminOrderFormBillingAddressSection.lastNameError}}" userInput="This is a required field." stepKey="seeLastNameRequired"/>
        <see selector="{{AdminOrderFormBillingAddressSection.streetAddressError}}" userInput="This is a required field." stepKey="seeStreetRequired"/>
        <see selector="{{AdminOrderFormBillingAddressSection.cityError}}" userInput="This is a required field." stepKey="seeCityRequired"/>
        <see selector="{{AdminOrderFormBillingAddressSection.stateError}}" userInput="This is a required field." stepKey="seeStateRequired"/>
        <see selector="{{AdminOrderFormBillingAddressSection.postalCodeError}}" userInput="This is a required field." stepKey="seePostalCodeRequired"/>
        <see selector="{{AdminOrderFormBillingAddressSection.phoneError}}" userInput="This is a required field." stepKey="seePhoneRequired"/>
        <see selector="{{AdminOrderFormPaymentSection.shippingError}}" userInput="This is a required field." stepKey="seeShippingMethodRequired"/>
    </actionGroup>

    <!--Add a simple product to order-->
    <actionGroup name="addSimpleProductToOrder">
        <arguments>
            <argument name="product" defaultValue="_defaultProduct" type="entity"/>
            <argument name="productQty" defaultValue="1" type="string"/>
        </arguments>
        <click selector="{{AdminOrderFormItemsSection.addProducts}}" stepKey="clickAddProducts"/>
        <fillField selector="{{AdminOrderFormItemsSection.skuFilter}}" userInput="{{product.sku}}" stepKey="fillSkuFilter"/>
        <click selector="{{AdminOrderFormItemsSection.search}}" stepKey="clickSearch"/>
        <scrollTo selector="{{AdminOrderFormItemsSection.rowCheck('1')}}" x="0" y="-100" stepKey="scrollToCheckColumn"/>
        <checkOption selector="{{AdminOrderFormItemsSection.rowCheck('1')}}" stepKey="selectProduct"/>
        <fillField selector="{{AdminOrderFormItemsSection.rowQty('1')}}" userInput="{{productQty}}" stepKey="fillProductQty"/>
        <scrollTo selector="{{AdminOrderFormItemsSection.addSelected}}" x="0" y="-100" stepKey="scrollToAddSelectedButton"/>
        <click selector="{{AdminOrderFormItemsSection.addSelected}}" stepKey="clickAddSelectedProducts"/>
        <wait time="5" stepKey="waitForOptionsToLoad"/>
    </actionGroup>

    <actionGroup name="AddSimpleProductWithQtyToOrderActionGroup" extends="addSimpleProductToOrder">
        <arguments>
            <argument name="product" defaultValue="_defaultProduct" type="entity"/>
            <argument name="productQty" type="string"/>
        </arguments>
        <fillField selector="{{AdminOrderFormItemsSection.rowQty('1')}}" userInput="{{productQty}}" stepKey="fillProductQty"/>
    </actionGroup>

    <!--Add configurable product to order -->
    <actionGroup name="addConfigurableProductToOrder">
        <arguments>
            <argument name="product"/>
            <argument name="attribute"/>
            <argument name="option"/>
        </arguments>
        <click selector="{{AdminOrderFormItemsSection.addProducts}}" stepKey="clickAddProducts"/>
        <fillField selector="{{AdminOrderFormItemsSection.skuFilter}}" userInput="{{product.sku}}" stepKey="fillSkuFilterConfigurable"/>
        <click selector="{{AdminOrderFormItemsSection.search}}" stepKey="clickSearchConfigurable"/>
        <scrollTo selector="{{AdminOrderFormItemsSection.rowCheck('1')}}" x="0" y="-100" stepKey="scrollToCheckColumn"/>
        <checkOption selector="{{AdminOrderFormItemsSection.rowCheck('1')}}" stepKey="selectConfigurableProduct"/>
        <waitForElementVisible selector="{{AdminOrderFormConfigureProductSection.optionSelect(attribute.default_label)}}" stepKey="waitForConfigurablePopover"/>
        <wait time="2" stepKey="waitForOptionsToLoad"/>
        <selectOption selector="{{AdminOrderFormConfigureProductSection.optionSelect(attribute.default_label)}}"
                      userInput="{{option.name}}" stepKey="selectionConfigurableOption"/>
        <click selector="{{AdminOrderFormConfigureProductSection.ok}}" stepKey="clickOkConfigurablePopover"/>
        <scrollTo selector="{{AdminOrderFormItemsSection.addSelected}}" x="0" y="-100" stepKey="scrollToAddSelectedButton"/>
        <click selector="{{AdminOrderFormItemsSection.addSelected}}" stepKey="clickAddSelectedProducts"/>
    </actionGroup>

    <actionGroup name="newAddConfigurableProductToOrder" extends="addConfigurableProductToOrder">
        <remove keyForRemoval="waitForConfigurablePopover"/>
        <remove keyForRemoval="selectionConfigurableOption"/>
        <selectOption selector="{{AdminOrderFormConfigureProductSection.selectOption}}" userInput="{{option.value}}" stepKey="selectOption" after="waitForOptionsToLoad"/>
    </actionGroup>

    <!--Add configurable product to order -->
    <actionGroup name="addConfigurableProductToOrderFromAdmin" extends="addConfigurableProductToOrder">
        <waitForElementVisible selector="{{AdminOrderFormConfigureProductSection.optionSelect(attribute.default_frontend_label)}}" stepKey="waitForConfigurablePopover"/>
        <selectOption selector="{{AdminOrderFormConfigureProductSection.optionSelect(attribute.default_frontend_label)}}"
                      userInput="{{option.label}}" stepKey="selectionConfigurableOption"/>
    </actionGroup>

    <actionGroup name="configureOrderedConfigurableProduct">
        <arguments>
            <argument name="attribute"/>
            <argument name="option"/>
            <argument name="quantity" type="string"/>
        </arguments>
        <click selector="{{AdminOrderFormItemsSection.configure}}" stepKey="clickConfigure"/>
        <waitForElementVisible selector="{{AdminOrderFormConfigureProductSection.optionSelect(attribute.default_frontend_label)}}" stepKey="waitForConfigurablePopover"/>
        <wait time="2" stepKey="waitForOptionsToLoad"/>
        <selectOption selector="{{AdminOrderFormConfigureProductSection.optionSelect(attribute.default_frontend_label)}}"
                      userInput="{{option.label}}" stepKey="selectionConfigurableOption"/>
        <fillField selector="{{AdminOrderFormConfigureProductSection.quantity}}" userInput="{{quantity}}" stepKey="fillQuantity"/>
        <click selector="{{AdminOrderFormConfigureProductSection.ok}}" stepKey="clickOkConfigurablePopover"/>
    </actionGroup>

    <!--Add bundle product to order -->
    <actionGroup name="addBundleProductToOrder">
        <arguments>
            <argument name="product"/>
            <argument name="quantity" type="string" defaultValue="1"/>
        </arguments>
        <click selector="{{AdminOrderFormItemsSection.addProducts}}" stepKey="clickAddProducts"/>
        <fillField selector="{{AdminOrderFormItemsSection.skuFilter}}" userInput="{{product.sku}}" stepKey="fillSkuFilterBundle"/>
        <click selector="{{AdminOrderFormItemsSection.search}}" stepKey="clickSearchBundle"/>
        <scrollTo selector="{{AdminOrderFormItemsSection.rowCheck('1')}}" x="0" y="-100" stepKey="scrollToCheckColumn"/>
        <checkOption selector="{{AdminOrderFormItemsSection.rowCheck('1')}}" stepKey="selectBundleProduct"/>
        <waitForElementVisible selector="{{AdminOrderFormBundleProductSection.quantity}}" stepKey="waitForBundleOptionLoad"/>
        <wait time="2" stepKey="waitForOptionsToLoad"/>
        <fillField selector="{{AdminOrderFormBundleProductSection.quantity}}" userInput="{{quantity}}" stepKey="fillQuantity"/>
        <click selector="{{AdminOrderFormConfigureProductSection.ok}}" stepKey="clickOk"/>
        <scrollTo selector="{{AdminOrderFormItemsSection.addSelected}}" x="0" y="-100" stepKey="scrollToAddSelectedButton"/>
        <click selector="{{AdminOrderFormItemsSection.addSelected}}" stepKey="clickAddSelectedProducts"/>
    </actionGroup>

    <!--Add bundle product to order and check product price in the grid-->
    <actionGroup name="addBundleProductToOrderAndCheckPriceInGrid" extends="addBundleProductToOrder">
        <arguments>
            <argument name="price" type="string"/>
        </arguments>
        <grabTextFrom selector="{{AdminOrderFormItemsSection.rowPrice('1')}}" stepKey="grabProductPriceFromGrid" after="clickOk"/>
        <assertEquals stepKey="assertProductPriceInGrid" message="Bundle product price in grid should be equal {{price}}" after="grabProductPriceFromGrid">
            <expectedResult type="string">{{price}}</expectedResult>
            <actualResult type="variable">grabProductPriceFromGrid</actualResult>
        </assertEquals>
    </actionGroup>

    <!--Add downloadable product to order -->
    <actionGroup name="addDownloadableProductToOrder">
        <arguments>
            <argument name="product"/>
            <argument name="link"/>
            <argument name="quantity" defaultValue="1" type="string"/>
        </arguments>
        <click selector="{{AdminOrderFormItemsSection.addProducts}}" stepKey="clickAddProducts"/>
        <waitForPageLoad time="30" stepKey="waitForPageLoad1"/>
        <fillField selector="{{AdminOrderFormItemsSection.skuFilter}}" userInput="{{product.sku}}" stepKey="fillSkuFilterDownloadable"/>
        <click selector="{{AdminOrderFormItemsSection.search}}" stepKey="clickSearchDownloadable"/>
        <scrollTo selector="{{AdminOrderFormItemsSection.rowCheck('1')}}" x="0" y="-100" stepKey="scrollToCheckColumn"/>
        <checkOption selector="{{AdminOrderFormItemsSection.rowCheck('1')}}" stepKey="selectDownloadableProduct"/>
        <waitForElementVisible selector="{{AdminOrderFormDownloadableProductSection.optionSelect(link.title)}}" stepKey="waitForLinkLoad"/>
        <click selector="{{AdminOrderFormDownloadableProductSection.optionSelect(link.title)}}" stepKey="selectLink"/>
        <fillField selector="{{AdminOrderFormDownloadableProductSection.quantity}}" userInput="{{quantity}}" stepKey="setQuantity"/>
        <click selector="{{AdminOrderFormDownloadableProductSection.ok}}" stepKey="confirmConfiguration"/>
        <scrollTo selector="{{AdminOrderFormItemsSection.addSelected}}" x="0" y="-100" stepKey="scrollToAddSelectedButton"/>
        <click selector="{{AdminOrderFormItemsSection.addSelected}}" stepKey="clickAddSelectedProducts"/>
    </actionGroup>

    <!--Add grouped product option to order -->
    <actionGroup name="addGroupedProductOptionToOrder">
        <arguments>
            <argument name="product"/>
            <argument name="option"/>
            <argument name="quantity" type="string" defaultValue="1"/>
        </arguments>

        <click selector="{{AdminOrderFormItemsSection.addProducts}}" stepKey="clickAddProducts"/>
        <fillField selector="{{AdminOrderFormItemsSection.skuFilter}}" userInput="{{product.sku}}" stepKey="fillSkuFilterGrouped"/>
        <click selector="{{AdminOrderFormItemsSection.search}}" stepKey="clickSearchGrouped"/>
        <scrollTo selector="{{AdminOrderFormItemsSection.rowCheck('1')}}" x="0" y="-100" stepKey="scrollToCheckColumn"/>
        <checkOption selector="{{AdminOrderFormItemsSection.rowCheck('1')}}" stepKey="selectGroupedProduct"/>
        <waitForElementVisible selector="{{AdminOrderFormGroupedProductSection.optionQty(option.sku)}}" stepKey="waitForGroupedOptionLoad"/>
        <wait time="2" stepKey="waitForOptionsToLoad"/>
        <fillField selector="{{AdminOrderFormGroupedProductSection.optionQty(option.sku)}}" userInput="{{quantity}}" stepKey="fillOptionQuantity"/>
        <click selector="{{AdminOrderFormConfigureProductSection.ok}}" stepKey="clickOk"/>
        <scrollTo selector="{{AdminOrderFormItemsSection.addSelected}}" x="0" y="-100" stepKey="scrollToAddSelectedButton"/>
        <click selector="{{AdminOrderFormItemsSection.addSelected}}" stepKey="clickAddSelectedProducts"/>
    </actionGroup>

    <!--Fill customer billing address-->
    <actionGroup name="fillOrderCustomerInformation">
        <arguments>
            <argument name="customer"/>
            <argument name="address"/>
        </arguments>
        <fillField selector="{{AdminOrderFormBillingAddressSection.FirstName}}" userInput="{{customer.firstname}}" stepKey="fillFirstName"/>
        <fillField selector="{{AdminOrderFormBillingAddressSection.LastName}}" userInput="{{customer.lastname}}" stepKey="fillLastName"/>
        <fillField selector="{{AdminOrderFormBillingAddressSection.StreetLine1}}" userInput="{{address.street[0]}}" stepKey="fillStreetLine1"/>
        <fillField selector="{{AdminOrderFormBillingAddressSection.City}}" userInput="{{address.city}}" stepKey="fillCity"/>
        <selectOption selector="{{AdminOrderFormBillingAddressSection.Country}}" userInput="{{address.country_id}}" stepKey="fillCountry"/>
        <selectOption selector="{{AdminOrderFormBillingAddressSection.State}}" userInput="{{address.state}}" stepKey="fillState"/>
        <fillField selector="{{AdminOrderFormBillingAddressSection.PostalCode}}" userInput="{{address.postcode}}" stepKey="fillPostalCode"/>
        <fillField selector="{{AdminOrderFormBillingAddressSection.Phone}}" userInput="{{address.telephone}}" stepKey="fillPhone"/>
    </actionGroup>

    <!--Select flat rate shipping method-->
    <actionGroup name="orderSelectFlatRateShipping">
        <click selector="{{AdminOrderFormPaymentSection.header}}" stepKey="unfocus"/>
        <waitForPageLoad stepKey="waitForJavascriptToFinish"/>
        <click selector="{{AdminOrderFormPaymentSection.getShippingMethods}}" stepKey="clickShippingMethods"/>
        <waitForElementVisible selector="{{AdminOrderFormPaymentSection.flatRateOption}}" stepKey="waitForShippingOptions"/>
        <selectOption selector="{{AdminOrderFormPaymentSection.flatRateOption}}" userInput="flatrate_flatrate" stepKey="checkFlatRate"/>
    </actionGroup>

    <!--Select free shipping method-->
    <actionGroup name="orderSelectFreeShipping">
        <click selector="{{AdminOrderFormPaymentSection.header}}" stepKey="unfocus"/>
        <waitForPageLoad stepKey="waitForJavascriptToFinish"/>
        <click selector="{{AdminOrderFormPaymentSection.getShippingMethods}}" stepKey="clickShippingMethods"/>
        <waitForElementVisible selector="{{AdminOrderFormPaymentSection.freeShippingOption}}" stepKey="waitForShippingOptions"/>
        <selectOption selector="{{AdminOrderFormPaymentSection.freeShippingOption}}" userInput="freeshipping_freeshipping" stepKey="checkFreeShipping"/>
    </actionGroup>

    <!--Check that customer information is correct in order-->
    <actionGroup name="verifyBasicOrderInformation">
        <arguments>
            <argument name="customer"/>
            <argument name="shippingAddress"/>
            <argument name="billingAddress"/>
            <argument name="customerGroup" defaultValue="GeneralCustomerGroup"/>
        </arguments>
        <see selector="{{AdminOrderDetailsInformationSection.customerName}}" userInput="{{customer.firstname}}" stepKey="seeCustomerName"/>
        <see selector="{{AdminOrderDetailsInformationSection.customerEmail}}" userInput="{{customer.email}}" stepKey="seeCustomerEmail"/>
        <see selector="{{AdminOrderDetailsInformationSection.customerGroup}}" userInput="{{customerGroup.code}}" stepKey="seeCustomerGroup"/>
        <see selector="{{AdminOrderAddressInformationSection.billingAddress}}" userInput="{{billingAddress.street[0]}}" stepKey="seeBillingAddressStreet"/>
        <see selector="{{AdminOrderAddressInformationSection.billingAddress}}" userInput="{{billingAddress.city}}" stepKey="seeBillingAddressCity"/>
        <see selector="{{AdminOrderAddressInformationSection.billingAddress}}" userInput="{{billingAddress.country_id}}" stepKey="seeBillingAddressCountry"/>
        <see selector="{{AdminOrderAddressInformationSection.billingAddress}}" userInput="{{billingAddress.postcode}}" stepKey="seeBillingAddressPostcode"/>
        <see selector="{{AdminOrderAddressInformationSection.shippingAddress}}" userInput="{{shippingAddress.street[0]}}" stepKey="seeShippingAddressStreet"/>
        <see selector="{{AdminOrderAddressInformationSection.shippingAddress}}" userInput="{{shippingAddress.city}}" stepKey="seeShippingAddressCity"/>
        <see selector="{{AdminOrderAddressInformationSection.shippingAddress}}" userInput="{{shippingAddress.country_id}}" stepKey="seeShippingAddressCountry"/>
        <see selector="{{AdminOrderAddressInformationSection.shippingAddress}}" userInput="{{shippingAddress.postcode}}" stepKey="seeShippingAddressPostcode"/>
    </actionGroup>
    <actionGroup name="AssertOrderAddressInformationActionGroup" extends="verifyBasicOrderInformation">
        <remove keyForRemoval="seeCustomerName"/>
        <remove keyForRemoval="seeCustomerEmail"/>
        <remove keyForRemoval="seeCustomerGroup"/>
        <remove keyForRemoval="seeBillingAddressCountry"/>
        <remove keyForRemoval="seeShippingAddressCountry"/>
        <see selector="{{AdminOrderAddressInformationSection.billingAddress}}" userInput="{{billingAddress.country}}" stepKey="seeBillingCountry" after="seeBillingAddressCity"/>
        <see selector="{{AdminOrderAddressInformationSection.shippingAddress}}" userInput="{{shippingAddress.country}}" stepKey="seeAddressCountry" after="seeShippingAddressCity"/>
    </actionGroup>

    <!--Verify order information-->
    <actionGroup name="verifyCreatedOrderInformation">
        <see selector="{{AdminOrderDetailsMessagesSection.successMessage}}" userInput="You created the order." stepKey="seeSuccessMessage"/>
        <see selector="{{AdminOrderDetailsInformationSection.orderStatus}}" userInput="Pending" stepKey="seeOrderPendingStatus" after="seeSuccessMessage"/>
        <grabTextFrom selector="|Order # (\d+)|" stepKey="getOrderId" after="seeOrderPendingStatus"/>
        <assertNotEmpty actual="$getOrderId" stepKey="assertOrderIdIsNotEmpty" after="getOrderId"/>
    </actionGroup>

    <!--Check for product in order items list-->
    <actionGroup name="seeProductInItemsOrdered">
        <arguments>
            <argument name="product"/>
        </arguments>
        <see selector="{{AdminOrderItemsOrderedSection.productSkuColumn}}" userInput="{{product.sku}}" stepKey="seeSkuInItemsOrdered"/>
    </actionGroup>

    <actionGroup name="CreateOrderInStoreActionGroup">
        <arguments>
            <argument name="product"/>
            <argument name="customer"/>
            <argument name="storeView"/>
        </arguments>
        <amOnPage stepKey="navigateToNewOrderPage" url="{{AdminOrderCreatePage.url}}"/>
        <click stepKey="chooseCustomer" selector="{{AdminOrdersGridSection.customerInOrdersSection(customer.firstname)}}"/>
        <waitForPageLoad stepKey="waitForStoresPageOpened"/>
        <click stepKey="chooseStore" selector="{{AdminOrderStoreScopeTreeSection.storeForOrder(storeView.name)}}"/>
        <scrollToTopOfPage stepKey="scrollToTop"/>
        <waitForPageLoad stepKey="waitForStoreToAppear"/>
        <click selector="{{OrdersGridSection.addProducts}}" stepKey="clickOnAddProducts"/>
        <waitForPageLoad stepKey="waitForProductsListForOrder"/>
        <click selector="{{AdminOrdersGridSection.productForOrder(product.sku)}}" stepKey="chooseTheProduct"/>
        <click selector="{{AdminOrderFormItemsSection.addSelected}}" stepKey="addSelectedProductToOrder"/>
        <waitForPageLoad stepKey="waitForProductAddedInOrder"/>
        <click selector="{{AdminInvoicePaymentShippingSection.getShippingMethodAndRates}}" stepKey="openShippingMethod"/>
        <waitForPageLoad stepKey="waitForShippingMethods"/>
        <click selector="{{AdminInvoicePaymentShippingSection.shippingMethod}}" stepKey="chooseShippingMethod"/>
        <waitForPageLoad stepKey="waitForShippingMethodsThickened"/>
        <click selector="{{OrdersGridSection.submitOrder}}" stepKey="submitOrder"/>
        <see stepKey="seeSuccessMessageForOrder" userInput="You created the order."/>
    </actionGroup>

    <actionGroup name="CreateOrderInStoreChoosingPaymentMethodActionGroup">
        <arguments>
            <argument name="product"/>
            <argument name="customer"/>
            <argument name="storeView"/>
        </arguments>
        <amOnPage stepKey="navigateToNewOrderPage" url="{{AdminOrderCreatePage.url}}"/>
        <click stepKey="chooseCustomer" selector="{{AdminOrdersGridSection.customerInOrdersSection(customer.firstname)}}"/>
        <waitForPageLoad stepKey="waitForStoresPageOpened"/>
        <click stepKey="chooseStore" selector="{{AdminOrderStoreScopeTreeSection.storeForOrder(storeView.name)}}"/>
        <scrollToTopOfPage stepKey="scrollToTop"/>
        <click selector="{{OrdersGridSection.addProducts}}" stepKey="clickOnAddProducts"/>
        <waitForPageLoad stepKey="waitForProductsListForOrder"/>
        <click selector="{{AdminOrdersGridSection.productForOrder(product.sku)}}" stepKey="chooseTheProduct"/>
        <click selector="{{AdminOrderFormItemsSection.addSelected}}" stepKey="addSelectedProductToOrder"/>
        <waitForPageLoad stepKey="waitForProductAddedInOrder"/>
        <click selector="{{AdminInvoicePaymentShippingSection.getShippingMethodAndRates}}" stepKey="openShippingMethod"/>
        <waitForPageLoad stepKey="waitForShippingMethods"/>
        <click selector="{{AdminInvoicePaymentShippingSection.shippingMethod}}" stepKey="chooseShippingMethod"/>
        <waitForPageLoad stepKey="waitForShippingMethodsThickened"/>
        <waitForElementVisible selector="{{AdminOrderFormPaymentSection.paymentBlock}}" stepKey="waitForPaymentOptions"/>
        <conditionalClick selector="{{AdminOrderFormPaymentSection.checkMoneyOption}}" dependentSelector="{{AdminOrderFormPaymentSection.checkMoneyOption}}" visible="true" stepKey="checkCheckMoneyOption"/>
        <click selector="{{OrdersGridSection.submitOrder}}" stepKey="submitOrder"/>
        <see stepKey="seeSuccessMessageForOrder" userInput="You created the order."/>
    </actionGroup>

    <!--Cancel order that is in pending status-->
    <actionGroup name="cancelPendingOrder">
        <arguments>
            <argument name="orderStatus" type="string" defaultValue="Canceled"/>
        </arguments>
        <click selector="{{AdminOrderDetailsMainActionsSection.cancel}}" stepKey="clickCancelOrder"/>
        <waitForElement selector="{{AdminConfirmationModalSection.message}}" stepKey="waitForCancelConfirmation"/>
        <see selector="{{AdminConfirmationModalSection.message}}" userInput="Are you sure you want to cancel this order?" stepKey="seeConfirmationMessage"/>
        <click selector="{{AdminConfirmationModalSection.ok}}" stepKey="confirmOrderCancel"/>
        <see selector="{{AdminMessagesSection.success}}" userInput="You canceled the order." stepKey="seeCancelSuccessMessage"/>
        <see selector="{{AdminOrderDetailsInformationSection.orderStatus}}" userInput="{{orderStatus}}" stepKey="seeOrderStatusCanceled"/>
    </actionGroup>

    <!--Assert that the product is not in the order items list-->
    <actionGroup name="dontSeeProductInItemsOrdered">
        <arguments>
            <argument name="product"/>
        </arguments>
        <dontSee selector="{{AdminOrderItemsOrderedSection.productSkuColumn}}" userInput="{{product.sku}}" stepKey="dontseeSkuInItemsOrdered"/>
    </actionGroup>

    <!--Select Check Money payment method-->
    <actionGroup name="SelectCheckMoneyPaymentMethod">
        <waitForElementVisible selector="{{AdminOrderFormPaymentSection.paymentBlock}}" stepKey="waitForPaymentOptions"/>
        <conditionalClick selector="{{AdminOrderFormPaymentSection.checkMoneyOption}}" dependentSelector="{{AdminOrderFormPaymentSection.checkMoneyOption}}" visible="true" stepKey="checkCheckMoneyOption"/>
    </actionGroup>

    <!--Select Bank Transfer payment method-->
    <actionGroup name="SelectBankTransferPaymentMethodActionGroup" extends="SelectCheckMoneyPaymentMethod">
        <remove keyForRemoval="checkCheckMoneyOption"/>
        <conditionalClick selector="{{AdminOrderFormPaymentSection.checkBankTransfer}}" dependentSelector="{{AdminOrderFormPaymentSection.checkBankTransfer}}" visible="true" stepKey="checkBankTransferOption" after="waitForPaymentOptions"/>
    </actionGroup>

    <!--Select Cash on Delivery payment method-->
    <actionGroup name="SelectCashOnDeliveryPaymentMethodActionGroup" extends="SelectCheckMoneyPaymentMethod">
        <remove keyForRemoval="checkCheckMoneyOption"/>
        <conditionalClick selector="{{AdminOrderFormPaymentSection.checkCashOnDelivery}}" dependentSelector="{{AdminOrderFormPaymentSection.checkCashOnDelivery}}" visible="true" stepKey="checkCashOnDeliveryOption" after="waitForPaymentOptions"/>
    </actionGroup>

    <!--Select Purchase Order payment method-->
    <actionGroup name="SelectPurchaseOrderPaymentMethodActionGroup" extends="SelectCheckMoneyPaymentMethod">
        <arguments>
            <argument name="purchaseOrderNumber" type="string"/>
        </arguments>
        <remove keyForRemoval="checkCheckMoneyOption"/>
        <conditionalClick selector="{{AdminOrderFormPaymentSection.checkPurchaseOrder}}" dependentSelector="{{AdminOrderFormPaymentSection.checkPurchaseOrder}}" visible="true" stepKey="checkPurchaseOrderOption" after="waitForPaymentOptions"/>
        <fillField selector="{{AdminOrderFormPaymentSection.fieldPurchaseOrderNumber}}" userInput="{{purchaseOrderNumber}}" stepKey="fillPurchaseOrderNumber"/>
    </actionGroup>

    <!-- Create Order -->
    <actionGroup name="CreateOrderActionGroup">
        <arguments>
            <argument name="product"/>
            <argument name="customer"/>
        </arguments>
        <amOnPage stepKey="navigateToNewOrderPage" url="{{AdminOrderCreatePage.url}}"/>
        <waitForPageLoad stepKey="waitForNewOrderPageOpened"/>
        <click stepKey="chooseCustomer" selector="{{AdminOrdersGridSection.customerInOrdersSection(customer.firstname)}}"/>
        <waitForPageLoad stepKey="waitForStoresPageOpened"/>
        <click selector="{{OrdersGridSection.addProducts}}" stepKey="clickOnAddProducts"/>
        <waitForPageLoad stepKey="waitForProductsListForOrder"/>
        <click selector="{{AdminOrdersGridSection.productForOrder(product.sku)}}" stepKey="chooseTheProduct"/>
        <waitForPageLoad stepKey="waitForClickProduct"/>
        <click selector="{{AdminOrderFormItemsSection.addSelected}}" stepKey="addSelectedProductToOrder"/>
        <waitForPageLoad stepKey="waitForProductAddedInOrder"/>
        <click selector="{{AdminInvoicePaymentShippingSection.getShippingMethodAndRates}}" stepKey="openShippingMethod"/>
        <waitForPageLoad stepKey="waitForShippingMethods"/>
        <click selector="{{AdminInvoicePaymentShippingSection.shippingMethod}}" stepKey="chooseShippingMethod"/>
        <waitForPageLoad stepKey="waitForShippingMethodsThickened"/>
        <click selector="{{OrdersGridSection.submitOrder}}" stepKey="submitOrder"/>
        <waitForPageLoad stepKey="waitForSubmitOrder"/>
        <see stepKey="seeSuccessMessageForOrder" userInput="You created the order."/>
    </actionGroup>
</actionGroups>
