Edit in GitHubLog an issue

Application testing

In a Cloud Docker development environment, you can use the Magento Functional Testing Framework (MFTF) for 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:

Copied to your clipboard
docker compose run test mftf-command generate:tests --debug=none

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.

      Copied to your clipboard
      composer require "magento/magento2-functional-testing-framework" --no-update
    • Install the new Composer dependencies.

      Copied to your clipboard
      composer update
  2. Generate the docker-compose.yml file.

    Copied to your clipboard
    ./vendor/bin/ece-docker build:compose --with-selenium --with-test
  3. Start the Cloud Docker for Commerce environment. Optionally, you can set up Cloud Docker for Commerce to work in Developer Mode.

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

    Copied to your clipboard
    CONFIG="MAGENTO_BASE_URL=http://magento2.docker/
    CREDENTIALS="magento/MAGENTO_ADMIN_PASSWORD=123123q"
    MAGENTO_BACKEND_NAME=admin
    MAGENTO_ADMIN_USERNAME=admin
    MAGENTO_ADMIN_PASSWORD=123123q
    MODULE_ALLOWLIST=Magento_Framework,Magento_ConfigurableProductWishlist,Magento_ConfigurableProductCatalogSearch
    SELENIUM_HOST=selenium"
    Copied to your clipboard
    docker compose run deploy bash -c "echo \"$CREDENTIALS\" > /app/dev/tests/acceptance/.credentials"
    Copied to your clipboard
    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.

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

    Copied to your clipboard
    docker compose run deploy magento-command config:set system/full_page_cache/caching_application 2 --lock-env
    Copied to your clipboard
    docker compose run deploy magento-command setup:config:set --http-cache-hosts=varnish
  7. Clear the cache.

    Copied to your clipboard
    docker compose run deploy magento-command cache:clean
  8. Generate MFTF tests.

    Copied to your clipboard
    docker compose run test mftf-command build:project
    Copied to your clipboard
    docker compose run test mftf-command generate:tests --debug=none
  9. Run the generated tests.

    Copied to your clipboard
    docker compose run test mftf-command run:test AdminLoginTest --debug=none
    Copied to your clipboard
    docker compose run test mftf-command run:test AddProductBySkuWithEmptyQtyTest --debug=none
  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2024 Adobe. All rights reserved.