<?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="GoToUserRoles">
        <click selector="#menu-magento-backend-system" stepKey="clickOnSystemIcon"/>
        <waitForPageLoad stepKey="waitForSystemsPageToOpen"/>
        <click selector="//span[contains(text(), 'User Roles')]" stepKey="clickToSelectUserRoles"/>
        <waitForPageLoad stepKey="waitForUserRolesPageToOpen"/>
    </actionGroup>

    <!--Create new role-->
    <actionGroup name="AdminCreateNewRole">
        <arguments>
            <argument name="role" type="string" defaultValue=""/>
            <argument name="resource" type="string" defaultValue="All"/>
            <argument name="scope" type="string" defaultValue="Custom"/>
            <argument name="websites" type="string" defaultValue="Main Website"/>
        </arguments>
        <click selector="{{AdminCreateRoleSection.create}}" stepKey="clickToAddNewRole"/>
        <fillField selector="{{AdminCreateRoleSection.name}}" userInput="{{role.name}}" stepKey="setRoleName"/>
        <fillField stepKey="setPassword" selector="{{AdminCreateRoleSection.password}}" userInput="{{_ENV.MAGENTO_ADMIN_PASSWORD}}"/>
        <click selector="{{AdminCreateRoleSection.roleResources}}" stepKey="clickToOpenRoleResources"/>
        <waitForPageLoad stepKey="waitForRoleResourcePage" time="5"/>
        <click stepKey="checkSales" selector="//a[text()='Sales']"/>
        <click selector="{{AdminCreateRoleSection.save}}" stepKey="clickToSaveRole"/>
        <waitForPageLoad stepKey="waitForPageLoad" time="10"/>
        <see userInput="You saved the role." stepKey="seeSuccessMessage" />
    </actionGroup>

    <!--Delete role-->
    <actionGroup name="AdminDeleteRoleActionGroup">
        <arguments>
            <argument name="role" defaultValue=""/>
        </arguments>
        <click stepKey="clickOnRole" selector="{{AdminDeleteRoleSection.theRole}}"/>
        <fillField stepKey="TypeCurrentPassword" selector="{{AdminDeleteRoleSection.current_pass}}" userInput="{{_ENV.MAGENTO_ADMIN_PASSWORD}}"/>
        <click stepKey="clickToDeleteRole" selector="{{AdminDeleteRoleSection.delete}}"/>
        <waitForAjaxLoad stepKey="waitForDeleteConfirmationPopup" time="5"/>
        <click stepKey="clickToConfirm" selector="{{AdminDeleteRoleSection.confirm}}"/>
        <waitForPageLoad stepKey="waitForPageLoad" time="10"/>
        <see stepKey="seeSuccessMessage" userInput="You deleted the role."/>
    </actionGroup>
</actionGroups>
