Make sure that you have the following software installed and configured on your development environment:
- PHP version supported by the Magento instance under test
- Composer 1.3 or later
- Java 1.8 or later
- Selenium Server Standalone 3.1 or later and ChromeDriver 2.33 or later or other webdriver in the same directory
Use instructions below to install Magento.
git clone https://github.com/magento/magento2.git
or
git clone [email protected]:magento/magento2.git
Checkout the Magento version that you are going to test.
cd magento2/
git checkout 2.4-develop
Install the Magento application.
composer install
Configure the following settings in Magento as described below.
A Selenium web driver cannot enter data to fields with WYSIWYG.
To disable the WYSIWYG and enable the web driver to process these fields as simple text areas:
- Log in to the Magento Admin as an administrator.
- Navigate to Stores > Settings > Configuration > General > Content Management.
- In the WYSIWYG Options section set the Enable WYSIWYG Editor option to Disabled Completely.
- Click Save Config.
or via command line:
bin/magento config:set cms/wysiwyg/enabled disabled
Clean the cache after changing the configuration values:
bin/magento cache:clean config full_page
To enable the Admin Account Sharing setting, to avoid unpredictable logout during a testing session, and disable the Add Secret Key in URLs setting, to open pages using direct URLs:
- Navigate to Stores > Settings > Configuration > Advanced > Admin > Security.
- Set Admin Account Sharing to Yes.
- Set Add Secret Key to URLs to No.
- Click Save Config.
or via command line:
bin/magento config:set admin/security/admin_account_sharing 1
bin/magento config:set admin/security/use_form_key 0
Clean the cache after changing the configuration values:
bin/magento cache:clean config full_page
If the Magento instance under test has the Magento Two-Factor Authentication (2FA) extension installed and enabled, additional configurations is needed to run MFTF tests. Learn more in Configure MFTF for Magento with Two-Factor Authentication (2FA).
MFTF does not support executing CLI commands if your web server points to <MAGE_ROOT_DIR>/pub
directory as recommended in the Installation Guide. For MFTF to execute the CLI commands, the web server must point to the Magento root directory.
If the Nginx Web server is used on your development environment, then Use Web Server Rewrites setting in Stores > Settings > Configuration > General > Web > Search Engine Optimization must be set to Yes.
Or via command line:
bin/magento config:set web/seo/use_rewrites 1
You must clean the cache after changing the configuration values:
bin/magento cache:clean config full_page
To be able to run Magento command line commands in tests, add the following location block to the Nginx configuration file in the Magento root directory:
location ~* ^/dev/tests/acceptance/utils($|/) {
root $MAGE_ROOT;
location ~ ^/dev/tests/acceptance/utils/command.php {
fastcgi_pass fastcgi_backend;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
This is the default setup of MFTF that you would need to cover your Magento project with functional tests.
It installs the framework using an existing Composer dependency such as magento/magento2-functional-testing-framework
.
If you want to set up MFTF as a standalone tool, refer to Set up a standalone MFTF.
Install MFTF.
composer install
In the Magento project root, run:
vendor/bin/mftf build:project
If you use PhpStorm, generate a URN catalog:
vendor/bin/mftf generate:urn-catalog .idea/misc.xml
If the file does not exist, add the --force
option to create it:
vendor/bin/mftf generate:urn-catalog --force .idea/misc.xml
See generate:urn-catalog
for more details.
In the magento2/dev/tests/acceptance/
directory, edit the .env
file to match your system.
vim dev/tests/acceptance/.env
Specify the following parameters, which are required to launch tests:
-
MAGENTO_BASE_URL
must contain a domain name of the Magento instance that will be tested. Example:MAGENTO_BASE_URL=http://magento.test
-
MAGENTO_BACKEND_NAME
must contain the relative path for the Admin area. Example:MAGENTO_BACKEND_NAME=admin
-
MAGENTO_ADMIN_USERNAME
must contain the username required for authorization in the Admin area. Example:MAGENTO_ADMIN_USERNAME=admin
-
MAGENTO_ADMIN_PASSWORD
must contain the user password required for authorization in the Admin area. Example:MAGENTO_ADMIN_PASSWORD=123123q
Learn more about environmental settings in Configuration.
In the Magento project root, run the following command to enable MFTF to send Magento CLI commands to your Magento instance.
cp dev/tests/acceptance/.htaccess.sample dev/tests/acceptance/.htaccess
To run tests, you need a running Selenium server and mftf
commands.
Run the Selenium server in the terminal. For example, the following commands download and run the Selenium server for Google Chrome:
curl -O http://selenium-release.storage.googleapis.com/3.14/selenium-server-standalone-3.14.0.jar
java -Dwebdriver.chrome.driver=chromedriver -jar selenium-server-standalone-3.14.0.jar
vendor/bin/mftf generate:tests
vendor/bin/codecept run functional -c dev/tests/acceptance/codeception.yml
See more commands in codecept
.
To clean up the previously generated tests, and then generate and run a single test AdminLoginSuccessfulTest
, run:
vendor/bin/mftf run:test AdminLoginSuccessfulTest --remove
See more commands in mftf
.
During testing, MFTF generates test reports in CLI. You can generate visual representations of the report data using the Allure Framework. To view the reports in a GUI:
- Install Allure
- Run the tool to serve the artifacts in
dev/tests/acceptance/tests/_output/allure-results/
:
allure serve dev/tests/acceptance/tests/_output/allure-results/
Learn more about Allure in the official documentation.
MFTF is a root level Magento dependency, but it is also available for use as a standalone application. You may want to use a standalone application when you develop for or contribute to MFTF, which facilitates debugging and tracking changes. These guidelines demonstrate how to set up and run Magento acceptance functional tests using standalone MFTF.
This installation requires a local instance of the Magento application.
MFTF uses the tests from Magento modules as well as the app/autoload.php
file.
If you develop or contribute to MFTF, it makes sense to clone your fork of the MFTF repository. For contribution guidelines, refer to the Contribution Guidelines for the Magento Functional Testing Framework.
cd magento2-functional-testing-framework
composer install
bin/mftf build:project
In the dev/.env
file, define the basic configuration and MAGENTO_BP
parameters.
Copy the etc/config/command.php
file into your Magento installation at <magento root directory>/dev/tests/acceptance/utils/
.
Create the utils/
directory, if you didn't find it.
MFTF uses the Magento app/autoload.php
file to read Magento modules.
The MFTF dependency in Magento supersedes the standalone registered namespaces unless it is removed at a Composer level.
composer remove magento/magento2-functional-testing-framework --dev -d <path to the Magento root directory>
Generate and run a single test that will check your logging to the Magento Admin functionality:
bin/mftf run:test AdminLoginSuccessfulTest
You can find the generated test at dev/tests/functional/tests/MFTF/_generated/default/
.
The standalone MFTF generates Allure reports at dev/tests/_output/allure-results/
.
Run the Allure server pointing to this directory:
allure serve dev/tests/_output/allure-results/