Magento application testing

In a Cloud Docker development environment, you can use the Magento Functional Testing Framework (MFTF) for Magento application testing. In this environment, you run MFTF commands using the mftf-command (CLI container command). For example, the following command generates the MFTF tests:

1
docker-compose run test mftf-command generate:tests --debug=none

Support for MFTF requires magento-cloud-docker version 1.0 or later.

To set up and run MFTF tests in a Cloud Docker environment:

  1. Prepare the local environment.

    • Add the MFTF dependency to your project using Composer.

      1
      
      composer require "magento/magento2-functional-testing-framework" --no-update
      
    • Install the new Composer dependencies.

      1
      
      composer update
      
  2. Generate the docker-compose.yml file.

    1
    
     ./vendor/bin/ece-docker build:compose --with-selenium
    
  3. Start the Magento Cloud Docker environment. Optionally, you can set up Magento Cloud Docker to work in Developer Mode.

    1
    
    ./bin/magento-docker up
    
    1
    
     ./bin/magento-docker ece-redeploy
    
  4. Prepare the Magento application by adding environment variables that are specific to MFTF.

    1
    2
    3
    4
    5
    6
    
    CONFIG="MAGENTO_BASE_URL=http://magento2.docker/
    MAGENTO_BACKEND_NAME=admin
    MAGENTO_ADMIN_USERNAME=admin
    MAGENTO_ADMIN_PASSWORD=123123q
    MODULE_WHITELIST=Magento_Framework,Magento_ConfigurableProductWishlist,Magento_ConfigurableProductCatalogSearch
    SELENIUM_HOST=selenium"
    
    1
    
    docker-compose run deploy bash -c "echo \"$CONFIG\" > /app/dev/tests/acceptance/.env"
    

    In this example, the variable configuration is for testing a Magento application deployed to the Docker environment. To run tests in a remote environment, change the value of MAGENTO_BASE_URL to the remote URL and update the credentials as needed.

  5. Disable the Magento settings that conflict with MFTF functionality.

    1
    
    docker-compose run deploy magento-command config:set admin/ security/admin_account_sharing 1
    
    1
    
    docker-compose run deploy magento-command config:set admin/ security/use_form_key 0
    
    1
    
    docker-compose run deploy magento-command config:set web/ secure/use_in_adminhtml 0
    
  6. Enable the Varnish cache for the Magento application.

    1
    
    docker-compose run deploy magento-command config:set  system/full_page_cache/caching_application 2 --lock-env
    
    1
    
    docker-compose run deploy magento-command setup:config:set  --http-cache-hosts=varnish
    
  7. Generate MFTF tests.

    1
    
    docker-compose run test mftf-command build:project
    
    1
    
    docker-compose run test mftf-command generate:tests --debug=none
    
  8. Run the generated tests.

    1
    
    docker-compose run test mftf-command run:test AdminLoginTest --debug=none
    
    1
    
    docker-compose run test mftf-command run:test AddProductBySkuWithEmptyQtyTest --debug=none