### Setup Environment Variables (Bash)
Source: https://developer.adobe.com/commerce/testing/functional-testing-framework/commands/mftf
Updates configuration parameter values in the `.env` file or creates it if it doesn't exist. Parameters are passed as options with values, e.g., `--MAGENTO_BASE_URL=http://magento.local/`. If a parameter doesn't exist, an error is returned. Example parameters are sourced from `etc/config/.env.example`.
```bash
vendor/bin/mftf setup:env --MAGENTO_BASE_URL=http://magento.local/ --BROWSER=firefox
vendor/bin/mftf setup:env
```
--------------------------------
### Install Magento 2 Dependencies with Composer
Source: https://developer.adobe.com/commerce/testing/functional-testing-framework/getting-started
This section covers navigating to the Magento 2 directory, checking out a specific development branch, and installing the application's dependencies using Composer. Ensure Composer is installed and accessible in your PATH.
```bash
cd magento2/
git checkout 2.4-develop
composer install
```
--------------------------------
### Define Starting Test in XML
Source: https://developer.adobe.com/commerce/testing/functional-testing-framework/merge-points/extend-tests
This XML snippet defines a base test case for creating a simple product via the admin interface. It includes annotations, setup steps (before), cleanup steps (after), and a sequence of action groups to execute the test.
```xml
```
--------------------------------
### Build Project with MFTF CLI
Source: https://developer.adobe.com/commerce/testing/functional-testing-framework/commands/mftf
Builds the Codeception project by cloning example configuration files. The `--upgrade` option can be used to upgrade installed tests after a framework upgrade.
```bash
vendor/bin/mftf build:project
vendor/bin/mftf build:project --upgrade
```
--------------------------------
### MFTF Test Generation Example (testNames.txt)
Source: https://developer.adobe.com/commerce/testing/functional-testing-framework/commands/mftf
An example format for a `testNames.txt` file used with the `generate:tests -p` command. It lists test names and suite names for targeted test generation.
```text
testName1
testName2
testNameN
suiteName:testInSuite
```
--------------------------------
### Run Codeception Tests
Source: https://developer.adobe.com/commerce/testing/functional-testing-framework/commands/codeception
Executes the default test suites defined in the Codeception configuration. This is the most basic command to start your test execution.
```bash
vendor/bin/codecept run
```
--------------------------------
### Define Starting Test for Merging - XML
Source: https://developer.adobe.com/commerce/testing/functional-testing-framework/merge-points/merge-tests
This XML code defines a starting test case for merging. It includes annotations, setup steps (before), teardown steps (after), and action groups for logging in, filling a product form, and asserting product details. This serves as the base test to which new functionalities will be added.
```xml
```
--------------------------------
### Download and Run Selenium Server for Functional Testing
Source: https://developer.adobe.com/commerce/testing/functional-testing-framework/getting-started
Download the Selenium server standalone JAR file and run it to facilitate browser automation for functional tests. This example uses version 3.14.0 and specifies the ChromeDriver path.
```bash
curl -O http://selenium-release.storage.googleapis.com/3.14/selenium-server-standalone-3.14.0.jar
```
```bash
java -Dwebdriver.chrome.driver=chromedriver -jar selenium-server-standalone-3.14.0.jar
```
--------------------------------
### Basic Assertion Example with Variable Substitution
Source: https://developer.adobe.com/commerce/testing/functional-testing-framework/test/assertions
This example demonstrates a common assertion pattern where a value is first grabbed from a page and then asserted to match an expected string. It showcases the use of `stepKey` for referencing previous actions and embedding variables within assertion strings using `{$stepKey}`.
```xml
Some StringA long assert string {$stepKeyOfGrab} with an embedded variable reference.
```
--------------------------------
### Inline Alert Slot Example
Source: https://developer.adobe.com/commerce/testing/functional-testing-framework/test-writing/best-practices
An example demonstrating the use of slots within an inline alert component, suggesting a pattern for content injection or customization.
```html
```
--------------------------------
### REST API Header Example (XML)
Source: https://developer.adobe.com/commerce/testing/functional-testing-framework/metadata
Provides an example of how to define a REST API header parameter using the '' tag. The 'param' attribute specifies the header name, and the content is the header value.
```xml
available
```
--------------------------------
### Build Efficient Selectors by Starting with Parent Context
Source: https://developer.adobe.com/commerce/testing/functional-testing-framework/test-writing/tips-tricks
Illustrates the recommended approach for building selectors for form elements by starting with the parent context and then specifying the element's `name` attribute. This pattern `{{section_selector}} {{input_selector}}` or `{{section_selector}} {{button_selector}}` ensures accurate targeting and improves lookup efficiency.
```xml
```
```xml
```
--------------------------------
### Build Project with Options
Source: https://developer.adobe.com/commerce/testing/functional-testing-framework/commands/mftf
Builds the project and allows setting environment configuration parameters. The `--upgrade` option can be used to upgrade installed tests.
```bash
vendor/bin/mftf build:project --MAGENTO_BASE_URL=http://magento.local/ --MAGENTO_BACKEND_NAME=admin214365
vendor/bin/mftf build:project --upgrade
```
--------------------------------
### Example Suite Configuration (XML)
Source: https://developer.adobe.com/commerce/testing/functional-testing-framework/test-writing/using-suites
An example of an XML suite definition for the Magento Functional Testing Framework. This suite, named 'WYSIWYGDisabledSuite', disables WYSIWYG before running tests from the 'Catalog' module and re-enables it afterward, excluding a specific incompatible test.
```xml
```
--------------------------------
### Use Descriptive stepKey Names in Tests (XML)
Source: https://developer.adobe.com/commerce/testing/functional-testing-framework/test-writing/tips-tricks
Illustrates the importance of using descriptive `stepKey` names for better readability and clarity in test scripts. The 'Good' example shows the recommended practice of using meaningful names, while the 'Bad' example shows the less maintainable approach of using generic numbers.
```xml
```
--------------------------------
### Configure .credentials file for Functional Testing Framework
Source: https://developer.adobe.com/commerce/testing/functional-testing-framework/credentials
This snippet demonstrates how to set up and use the .credentials file for storing sensitive data in the Functional Testing Framework. It includes steps for copying the example file, adding it to .gitignore, and defining key-value pairs for credentials.
```bash
cd dev/tests/acceptance/
cp .credentials.example .credentials
```
```bash
git check-ignore .credentials
```
--------------------------------
### XML Example: Nested Assertion Syntax - Functional Testing Framework
Source: https://developer.adobe.com/commerce/testing/functional-testing-framework/backward-incompatible-changes
Demonstrates the nested assertion syntax required by the updated XSD schema. This example shows how to use `` with explicit actual and expected result types.
```xml
$billingAddressOrderPage$shippingAddressOrderPage
```
--------------------------------
### Use Isolation for Selectors (CSS Example)
Source: https://developer.adobe.com/commerce/testing/functional-testing-framework/test-writing/selectors
Explains the concept of 'isolation' in selector writing by targeting a parent element first, then a child. This example shows how to select a 'Sign In' button within a specific login form using a combined selector.
```css
#login-form .sign-in-button
```
--------------------------------
### Define Starting Action Group - XML
Source: https://developer.adobe.com/commerce/testing/functional-testing-framework/merge-points/extend-action-groups
Defines a starting action group named 'AdminFillSimpleProductFormActionGroup' for filling out a simple product form. It includes arguments for category and product details, navigates to the product index page, fills various product fields, selects a category, opens the SEO section, fills the URL key, saves the product, and asserts the success message and field values.
```xml
```
--------------------------------
### Array with Primitive Items Example (XML)
Source: https://developer.adobe.com/commerce/testing/functional-testing-framework/metadata
Shows how to populate an array with primitive data type items. This XML structure represents the actual data assigned to an array, like a list of IDs.
```xml
12
```
--------------------------------
### Define Starting Page Structure (XML)
Source: https://developer.adobe.com/commerce/testing/functional-testing-framework/merge-points/merge-pages
This XML snippet defines the initial structure of a page, listing various sections that are part of its default configuration. It serves as the base for merging additional sections.
```xml
```
--------------------------------
### MFTF Action Group Declaration Example (Login)
Source: https://developer.adobe.com/commerce/testing/functional-testing-framework/test/action-groups
This example demonstrates a complete action group declaration for logging into the Admin area in MFTF. It includes annotations for description, arguments with default values, and a sequence of actions like navigating to the page, filling fields, clicking login, and closing notifications. The `userInput` variables reference data values for test execution.
```xml
Login to Backend Admin using provided User Data. PLEASE NOTE: This Action Group does NOT validate that you are Logged In.
```
--------------------------------
### Example composer.json for Functional Test Module
Source: https://developer.adobe.com/commerce/testing/functional-testing-framework/mftf-tests-packaging
This JSON file demonstrates the required format for a functional test module's composer.json. It specifies the 'magento2-functional-test-module' type and lists module dependencies using the 'suggest' block with specific type and name formats.
```json
{
"name": "magento/module-configurable-product-catalog-search-functional-test",
"description": "test module for Magento_ConfigurableProduct and Magento_CatalogSearch",
"type": "magento2-functional-test-module",
"config": {
"sort-packages": true
},
"require": {
"magento/magento2-functional-testing-framework": ">=2.5"
},
"suggest": {
"magento/module-configurable-product": "type: magento2-module, name: Magento_ConfigurableProduct, version: *",
"magento/module-catalog-search": "type: magento2-module, name: Magento_CatalogSearch, version: *"
},
"license": [
"OSL-3.0",
"AFL-3.0"
]
}
```
--------------------------------
### Use Numbers in stepKey for Order Importance (XML)
Source: https://developer.adobe.com/commerce/testing/functional-testing-framework/test-writing/tips-tricks
Provides an exception to the rule of using descriptive `stepKey` names. This example shows when it is appropriate to use numbers within `stepKeys`, specifically when the order of operations is critical, such as in testing sort order.
```xml
```
--------------------------------
### Automate customer sign-in steps (XML)
Source: https://developer.adobe.com/commerce/testing/functional-testing-framework/test/actions
This example demonstrates a sequence of actions to automate the customer sign-in process. It includes navigating to the sign-in page, filling in the email and password fields, and clicking the sign-in button. Each action uses specific selectors and input data, with `stepKey` attributes for referencing.
```xml
```
--------------------------------
### MFTF Category Operations Example (XML)
Source: https://developer.adobe.com/commerce/testing/functional-testing-framework/metadata
Illustrates how to define different operations (create, update, delete, get) for a 'category' data entity within an MFTF metadata file. This allows for comprehensive management of category data in tests.
```xml
...
...
...
...
```
--------------------------------
### Serve Allure Report (Bash)
Source: https://developer.adobe.com/commerce/testing/functional-testing-framework/reporting
Serves the generated Allure HTML report in a temporary folder and automatically opens it in the default web browser. This provides immediate access to test results for review.
```bash
allure serve dev/tests/acceptance/tests/_output/allure-results/
```
--------------------------------
### Enable CLI Commands for Functional Testing Framework
Source: https://developer.adobe.com/commerce/testing/functional-testing-framework/getting-started
Copy the sample .htaccess file to enable the Functional Testing Framework to send CLI commands to your Adobe Commerce or Magento Open Source instance. This step is performed in the project root directory.
```bash
cp dev/tests/acceptance/.htaccess.sample dev/tests/acceptance/.htaccess
```
--------------------------------
### Install hoa/console for Interactive Pause
Source: https://developer.adobe.com/commerce/testing/functional-testing-framework/interactive-pause
This command installs the 'hoa/console' library, which is a prerequisite for the interactive pause feature to function correctly within the MFTF. Ensure you run this in your project's root directory.
```bash
composer require hoa/console
```
--------------------------------
### MFTF Section Example: Admin Category Sidebar
Source: https://developer.adobe.com/commerce/testing/functional-testing-framework/section
An example of an MFTF section definition in XML for the 'AdminCategorySidebarActionSection'. It demonstrates how to declare button elements with their types and selectors.
```xml
```
--------------------------------
### Build Tests Using Action Groups (XML)
Source: https://developer.adobe.com/commerce/testing/functional-testing-framework/test-writing/tips-tricks
Demonstrates how to build tests using action groups, even for single actions. This approach enhances maintainability for extension developers by allowing updates to multiple tests through a single action group modification. The 'Good' example shows the recommended structure.
```xml
```
--------------------------------
### Array Containing Data Field Example (XML)
Source: https://developer.adobe.com/commerce/testing/functional-testing-framework/metadata
Demonstrates declaring an array that holds specific fields from other data types. This example shows an array of 'id' fields from the 'tax_rate' data type.
```xml
tax_rate.id
```
--------------------------------
### Inline Alert Warning Example
Source: https://developer.adobe.com/commerce/testing/functional-testing-framework/test-writing/best-practices
A simple example of an inline alert with a warning variant, likely used for UI feedback or notifications within the framework's context.
```html
```
--------------------------------
### Serve Allure Test Reports
Source: https://developer.adobe.com/commerce/testing/functional-testing-framework/getting-started
Generate and serve visual representations of test reports using the Allure Framework. This command serves the artifacts located in the specified allure-results directory, making them accessible via a GUI.
```bash
allure serve dev/tests/acceptance/tests/_output/allure-results/
```
--------------------------------
### Run Codeception Tests with Functional Testing Framework
Source: https://developer.adobe.com/commerce/testing/functional-testing-framework/commands/mftf
A wrapper command that executes `vendor/bin/codecept run` for the functional suite. Tests must be generated prior to execution. Supports running all tests, specific suites, or individual test files with various options.
```bash
vendor/bin/mftf codecept:run [] --[