<?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="AdminCreateUserWithoutPasswordActionGroup">
        <annotations>
            <description>Goes to the Admin Users grid page. Clicks on Create User. Fills in the provided Role and User.</description>
        </annotations>
        <arguments>
            <argument name="role"/>
            <argument name="user" defaultValue="newAdmin"/>
            <argument name="password" type="string" defaultValue="{{_ENV.ADOBE_IMS_PASSWORD}}"/>
        </arguments>

        <!--Open New Admin User Page. -->
        <amOnPage url="{{AdminNewUserPage.url}}" stepKey="navigateToNewAdminUser"/>
        <waitForPageLoad stepKey="waitForNewAdminUserPage"/>

        <!-- Fill admin user data. -->
        <fillField selector="{{AdminCreateUserSection.usernameTextField}}" userInput="{{user.username}}" stepKey="enterAdminUserName"/>
        <fillField selector="{{AdminCreateUserSection.firstNameTextField}}" userInput="{{user.firstName}}" stepKey="enterAdminFirstName"/>
        <fillField selector="{{AdminCreateUserSection.lastNameTextField}}" userInput="{{user.lastName}}" stepKey="enterAdminLastName"/>
        <fillField selector="{{AdminCreateUserSection.emailTextField}}" userInput="{{user.username}}@magento.com" stepKey="enterAdminEmail"/>

        <!-- Verify Current Admin User Identity via Adobe IMS. -->
        <click selector="{{AdminCreateUserSection.confirmIdentity}}" stepKey="clickConfirmIdentity"/>

         <!-- Switch to Admin IMS Window. -->
        <switchToNextTab stepKey="switchToNextTab"/>
        <waitForElementVisible selector="{{AdminAdobeImsSignInSection.password}}" stepKey="waitForAdobeImsForm"/>
        <fillField selector="{{AdminCreateUserSection.password}}" userInput="{{password}}" stepKey="fillPassword"/>
        <click selector="{{AdminAdobeImsSignInSection.AdobeImsPasswordContinueButton}}" stepKey="clickPasswordContinue"/>
        <waitForElementNotVisible selector="{{AdminAdobeImsSignInSection.password}}" time="30" stepKey="waitForAdobeImsFormToDisappear"/>

        <!-- Switch to Adobe Commerce Window. -->
        <switchToPreviousTab userInput="1" stepKey="switchPreviousTab"/>

        <!-- Select Admin User Role. -->
        <click selector="{{AdminCreateUserSection.userRoleTab}}" stepKey="clickUserRole"/>
        <click selector="{{AdminStoreSection.createdRoleInUserPage(role.name)}}" stepKey="chooseRole"/>

        <!-- Save admin user. -->
        <click selector="{{AdminCreateUserSection.saveButton}}" stepKey="clickSaveUser"/>
        <waitForPageLoad stepKey="waitForSaveTheUser"/>
    </actionGroup>
</actionGroups>
