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:
docker compose run test mftf-command generate:tests --debug=none
data-variant=info
data-slots=text
magento/magento-cloud-docker version 1.0 or later.To set up and run MFTF tests in a Cloud Docker environment:
-
Prepare the local environment.
-
Add the MFTF dependency to your project using Composer.
composer require "magento/magento2-functional-testing-framework" --no-update -
Install the new Composer dependencies.
composer update
-
-
Generate the
docker-compose.ymlfile../vendor/bin/ece-docker build:compose --with-selenium --with-test -
Start the Cloud Docker for Commerce environment. Optionally, you can set up Cloud Docker for Commerce to work in Developer Mode.
./bin/magento-docker up./bin/magento-docker ece-redeploy -
Prepare the Magento application by adding environment variables that are specific to MFTF.
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"docker compose run deploy bash -c "echo \"$CREDENTIALS\" > /app/dev/tests/acceptance/.credentials"docker compose run deploy bash -c "echo \"$CONFIG\" > /app/dev/tests/acceptance/.env"<!-- <InlineAlert variant="info" slots="text"/> -->
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_URLto the remote URL and update the credentials as needed. -
Disable the Magento settings that conflict with MFTF functionality.
docker compose run deploy magento-command config:set admin/security/admin_account_sharing 1docker compose run deploy magento-command config:set admin/security/use_form_key 0docker compose run deploy magento-command config:set web/secure/use_in_adminhtml 0 -
Enable the Varnish cache for the Magento application.
docker compose run deploy magento-command config:set system/full_page_cache/caching_application 2 --lock-envdocker compose run deploy magento-command setup:config:set --http-cache-hosts=varnish -
Clear the cache.
docker compose run deploy magento-command cache:clean -
Generate MFTF tests.
docker compose run test mftf-command build:projectdocker compose run test mftf-command generate:tests --debug=none -
Run the generated tests.
docker compose run test mftf-command run:test AdminLoginTest --debug=nonedocker compose run test mftf-command run:test AddProductBySkuWithEmptyQtyTest --debug=none
<!-- link definitions -->