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 clipboarddocker compose run test mftf-command generate:tests --debug=none
Support for MFTF requires 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.
Copied to your clipboardcomposer require "magento/magento2-functional-testing-framework" --no-updateInstall the new Composer dependencies.
Copied to your clipboardcomposer update
Generate the
docker-compose.yml
file.Copied to your clipboard./vendor/bin/ece-docker build:compose --with-selenium --with-testStart 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 upCopied to your clipboard./bin/magento-docker ece-redeployPrepare the Magento application by adding environment variables that are specific to MFTF.
Copied to your clipboardCONFIG="MAGENTO_BASE_URL=http://magento2.docker/CREDENTIALS="magento/MAGENTO_ADMIN_PASSWORD=123123q"MAGENTO_BACKEND_NAME=adminMAGENTO_ADMIN_USERNAME=adminMAGENTO_ADMIN_PASSWORD=123123qMODULE_ALLOWLIST=Magento_Framework,Magento_ConfigurableProductWishlist,Magento_ConfigurableProductCatalogSearchSELENIUM_HOST=selenium"Copied to your clipboarddocker compose run deploy bash -c "echo \"$CREDENTIALS\" > /app/dev/tests/acceptance/.credentials"Copied to your clipboarddocker 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.Disable the Magento settings that conflict with MFTF functionality.
Copied to your clipboarddocker compose run deploy magento-command config:set admin/security/admin_account_sharing 1Copied to your clipboarddocker compose run deploy magento-command config:set admin/security/use_form_key 0Copied to your clipboarddocker compose run deploy magento-command config:set web/secure/use_in_adminhtml 0Enable the Varnish cache for the Magento application.
Copied to your clipboarddocker compose run deploy magento-command config:set system/full_page_cache/caching_application 2 --lock-envCopied to your clipboarddocker compose run deploy magento-command setup:config:set --http-cache-hosts=varnishClear the cache.
Copied to your clipboarddocker compose run deploy magento-command cache:cleanGenerate MFTF tests.
Copied to your clipboarddocker compose run test mftf-command build:projectCopied to your clipboarddocker compose run test mftf-command generate:tests --debug=noneRun the generated tests.
Copied to your clipboarddocker compose run test mftf-command run:test AdminLoginTest --debug=noneCopied to your clipboarddocker compose run test mftf-command run:test AddProductBySkuWithEmptyQtyTest --debug=none