Reading list Switch to dark mode

    How to create MFTF for custom module in magento 2

    Updated 16 July 2021

    In this blog we are creating MFTF test case for Grid module in Magento 2. You can check Functional Test blog link for basic understanding of MFTF.

    Requirement for MFTF

    1- Selenium Server Standalone jar file
    2- Chrome Driver
    3- Magento2 latest version(2.2.4 and above)

    You can download Selenium Server jar file and Chrome Drive from link .

    Prepare Magento for MFTF 

    1. Selenium server can’t enter data in editor so WYSIWYG setting Disabled Completely from your admin panel.

    Searching for an experienced
    Magento 2 Company ?
    Find out More

    2. Disable the Add Secret Key setting from your admin panel.

    Install dependencies

    <span class="nb"> cd </span>magentoRoot/dev/tests/acceptance
     composer install

    => Put Selenium Server jar file and Chrome Drive in a folder.

    => Edit .env file on MagentoRoot/dev/tests/acceptance directory.
    Example :-
    MAGENTO_BASE_URL=http://magento.test
    MAGENTO_BACKEND_NAME=admin
    MAGENTO_ADMIN_USERNAME=admin
    MAGENTO_ADMIN_PASSWORD=123123q

    => Run command “vendor/bin/robo build:project” on MagentoRoot/dev/tests/acceptance location.

    => Run Selenium server command “java -jar <selenium server name>”

    => Open http://127.0.0.1:4444/wd/hub/static/resource/hub.html link on chrome browser and set session of chrome browser.

    You can put the MFTF test cases inside your custom module at {Magento_Root}/app/code/Company/TestModule/Test/Mftf/ location:

    Now we are starting how to create test case of Grid module. Firstly we need to install grid module
    (Grid module Code).

    • Create test case on GridTest.xml on {Magento_Root}/app/code/Company/TestModule/Test/Mftf/Test/ location.
    <?xml version="1.0" encoding="UTF-8"?>
    <tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd">
        <test name="GridTest">
            <annotations>
                <features value="Grid module test case."/>
                <stories value="Add new row/delete row"/>
                <title value="Grid module test case."/>
                <description value="Grid module test case create."/>
                <severity value="CRITICAL"/>
                <testCaseId value="MAGETWO-71195"/>
                <group value="grid"/>
            </annotations>
            <!--Login admin -->
            <actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin1"/> 
            <!--Open Grid list page -->
            <amOnPage url="{{AdminGridPage.url}}" stepKey="gridListPageOpen"/>
            <wait time="2" stepKey="gridListPageLoad"/>
            <!--Click on grid add button-->
            <click stepKey="addBtn" selector="{{AdminGridSection.addBtn}}"/>
            <wait time="5" stepKey="addRowPageOpen"/>
            <!--Grid data fill and save -->
            <fillField userInput="{{GridData.title}}" selector="{{AdminGridSection.gridTitle}}" stepKey="gridTitle"/>
            <fillField userInput="{{GridData.content}}" selector="{{AdminGridSection.gridContent}}" stepKey="gridContent"/>  
            <fillField userInput="{{GridData.publishDate}}" selector="{{AdminGridSection.publishDate}}" stepKey="publishDate"/>  
            <selectOption userInput="{{GridData.gridStauts}}" selector="{{AdminGridSection.gridStauts}}" stepKey="gridStauts"/>  
            <click stepKey="save" selector="{{AdminGridSection.save}}"/>
            <wait time="5" stepKey="gridDataSave"/>
        </test>
    </tests>
    
    • Create page on AdminGridPage.xml on {Magento_Root}/app/code/Company/TestModule/Test/Mftf/Page/ location.
    <?xml version="1.0" encoding="UTF-8"?>
     <pages xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Page/etc/PageObject.xsd">
        <page name="AdminGridPage" url="/grid/grid/" area="admin" module="Magento_Grid">
        </page>
    </pages>
    
    
    • Create test section on AdminGridSection.xml on {Magento_Root}/app/code/Company/TestModule/Test/Mftf/Section/ location.
    <?xml version="1.0" encoding="UTF-8"?>
    <sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Page/etc/SectionObject.xsd">
        <section name="AdminGridSection">
            <element name="addBtn" type="button" selector="#add" />
            <element name="gridTitle"  type="input" selector="#wkgrid_title"/>
            <element name="gridContent"  type="input" selector="#wkgrid_content"/>
            <element name="publishDate"  type="input" selector="#wkgrid_publish_date"/>
            <element name="gridStauts"  type="input" selector="#wkgrid_is_active"/>
            <element name="save"  type="button" selector="#save"/>
        </section>
    </sections>
    • Create test section on GridData.xml on {Magento_Root}/app/code/Company/TestModule/Test/Mftf/Data/ location.
    <?xml version="1.0" encoding="UTF-8"?>
    <entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/DataGenerator/etc/dataProfileSchema.xsd">
        <entity name="GridData" type="product">
            <data key="title">New grid</data>
            <data key="content">An electrical grid is an interconnected network</data>
            <data key="publishDate">09/26/2018 8:23:03</data>
            <data key="gridStauts">1</data>
       </entity>
    </entities>
    

    Test case of grid module has been done.Now we run this test case using both command “vendor/bin/robo generate:tests” and “vendor/bin/codecept run functional –group grid” on dev/tests/acceptance/ location.

    Thanks 🙂

    . . .

    Leave a Comment

    Your email address will not be published. Required fields are marked*


    Be the first to comment.

    Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home