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 ?
    Read 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 :-

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

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

    => Open 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=""
        <test name="GridTest">
                <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"/>
            <!--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="{{}}"/>
            <wait time="5" stepKey="gridDataSave"/>
    • 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=""
        <page name="AdminGridPage" url="/grid/grid/" area="admin" module="Magento_Grid">
    • 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=""
        <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"/>
    • 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=""
        <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>

    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 🙂

    . . .
    Discuss on Helpdesk

    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