<?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">
        <annotations>
            <description>Goes to the Admin Orders grid page. Clicks on 'Create New Order'. Clicks on 'Create New Customer'. Select the provided Store View, if present. Validates that Page Title is present and correct.</description>
        </annotations>
        <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">
        <annotations>
            <description>Goes to the Admin Orders grid page. Clicks on 'Create New Order'. Clicks on 'Create New Customer'. Validates that Page Title is present and correct.</description>
        </annotations>
        <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">
        <annotations>
            <description>Goes tot he Admin Orders grid page. Clicks on 'Create New Order'. Filters the grid for the provided Customer. Clicks on the Customer. Selects the provided Store View, if present. Validates that the Page Title is present and correct.</description>
        </annotations>
        <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">
        <annotations>
            <description>EXTENDS: navigateToNewOrderPageExistingCustomer. Clicks on the provided Store View.</description>
        </annotations>
        <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">
        <annotations>
            <description>Clears the Email, First Name, Last Name, Street Line 1, City, Postal Code and Phone fields when adding an Order and then verifies that they are required after attempting to Save.</description>
        </annotations>

        <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">
        <annotations>
            <description>Adds the provided Simple Product to an Order. Fills in the provided Product Qty. Clicks on 'Add Selected Product(s) to Order'.</description>
        </annotations>
        <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">
        <annotations>
            <description>Adds the provided Configurable Product with the provided Option to an Order. Fills in the provided Product Qty. Clicks on 'Add Selected Product(s) to Order'.</description>
        </annotations>
        <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">
        <annotations>
            <description>EXTENDS: addConfigurableProductToOrder. Selects the provided Option to the Configurable Product.</description>
        </annotations>

        <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">
        <annotations>
            <description>Clicks on 'Configure' for a Product in the 'Please select products' under the 'Create New Order for' page. Selects the provided Option and Attribute. Fills in the provided Qty. Clicks on Ok.</description>
        </annotations>
        <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">
        <annotations>
            <description>Adds the provided Bundled Product with the provided Option to an Order. Fills in the provided Product Qty. Clicks on 'Add Selected Product(s) to Order'.</description>
        </annotations>
        <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">
        <annotations>
            <description>EXTENDS: addBundleProductToOrder. Validates that the provided Product Price is present and correct in the 'Items Ordered' section.</description>
        </annotations>
        <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">
        <annotations>
            <description>Adds a Downloadable Product to an Order. Clicks on 'Add Selected Product(s) to Order'.</description>
        </annotations>

        <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">
        <annotations>
            <description>Adds the provided Grouped Product with the provided Option to an Order. Fills in the provided Product Qty. Clicks on 'Add Selected Product(s) to Order'.</description>
        </annotations>
        <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">
        <annotations>
            <description>Fills in the provided Customer and Address details on the Admin 'Create New Order for' page.</description>
        </annotations>
        <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">
        <annotations>
            <description>Selects the 'Flat Rate' Shipping Method on the Admin 'Create New Order for' page.</description>
        </annotations>

        <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>

    <actionGroup name="changeShippingMethod">
        <annotations>
            <description>Change Shipping Method on the Admin 'Create New Order for' page.</description>
        </annotations>
        <arguments>
            <argument name="shippingMethod" defaultValue="flatrate_flatrate" type="string"/>
        </arguments>
        <click selector="{{AdminOrderFormPaymentSection.header}}" stepKey="unfocus"/>
        <waitForPageLoad stepKey="waitForJavascriptToFinish"/>
        <click selector="{{AdminOrderFormPaymentSection.getShippingMethods}}" stepKey="clickShippingMethods1"/>
        <waitForElementVisible selector="{{AdminOrderFormPaymentSection.getShippingMethods}}" stepKey="waitForChangeShippingMethod"/>
        <click selector="{{AdminOrderFormPaymentSection.getShippingMethods}}" stepKey="clickShippingMethods2"/>
        <waitForElementVisible selector="{{AdminOrderFormPaymentSection.shippingMethod}}" stepKey="waitForShippingOptions2"/>
        <selectOption selector="{{AdminOrderFormPaymentSection.shippingMethod}}" userInput="{{shippingMethod}}" stepKey="checkFlatRate"/>
    </actionGroup>

    <!--Select free shipping method-->
    <actionGroup name="orderSelectFreeShipping">
        <annotations>
            <description>Selects the 'Free Shipping' Shipping Method on the Admin 'Create New Order for' page.</description>
        </annotations>

        <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">
        <annotations>
            <description>Validates that the provided Customer, Shipping/Billing Address and Customer Group are present and correct on the Admin Orders view page.</description>
        </annotations>
        <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">
        <annotations>
            <description>Validates that the Success Message, Order Status (Pending) and Order ID are present and correct.</description>
        </annotations>

        <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">
        <annotations>
            <description>Validates that the provided Product is present and correct in the 'Items Ordered' section on the Admin Orders view page.</description>
        </annotations>
        <arguments>
            <argument name="product"/>
        </arguments>

        <see selector="{{AdminOrderItemsOrderedSection.productSkuColumn}}" userInput="{{product.sku}}" stepKey="seeSkuInItemsOrdered"/>
    </actionGroup>

    <actionGroup name="CreateOrderInStoreActionGroup">
        <annotations>
            <description>Goes to the Admin Create Order page. Creates an Order based on the provided Customer, Store View and Product. Validates that the Success Message is present and correct.</description>
        </annotations>
        <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">
        <annotations>
            <description>Goes to the Admin Create Order page. Creates an Order based on the provided Customer, Store View and Product. Validates that the Success Message is present and correct.</description>
        </annotations>
        <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">
        <annotations>
            <description>Cancels the Pending Order on the Admin Orders view page. Validates that the provided Order Status is present and correct.</description>
        </annotations>
        <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">
        <annotations>
            <description>Selects the 'Check / Money Order' Payment Method on the Admin Create New Order page.</description>
        </annotations>

        <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">
        <annotations>
            <description>Goes to the Admin Create New Order page. Selects the provided Customer. Adds the provided Product to the Order. Clicks on Submit Order. Validates that the Success Message is present and correct.</description>
        </annotations>
        <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>
    <actionGroup name="CreateOrderFilteringCustomerByEmailActionGroup" extends="CreateOrderActionGroup">
        <click stepKey="chooseCustomer" selector="{{AdminOrdersGridSection.customerInOrdersSection(customer.email)}}"/>
    </actionGroup>
</actionGroups>
