|
2 | 2 |
|
3 | 3 | Check out our best practices below to ensure you are getting the absolute most out of the Magento Functional Testing Framework.
|
4 | 4 |
|
| 5 | +## Focus on reusability |
| 6 | + |
| 7 | +### Use existing Tests and resources |
| 8 | + |
| 9 | +Magento offers more than **3000** acceptance tests, **2500** [Action group]s, **750** Page declarations with more than **1500** Section definitions. |
| 10 | +It is very probable that behaviour you want to test already exists as a Test or Action Group. |
| 11 | +Instead of writing everything by yourself - use `extends` attribute to refer to existing element and customize it. |
| 12 | + |
| 13 | +**Reusable Resources** |
| 14 | + |
| 15 | +{%raw%} |
| 16 | + |
| 17 | +* Tests (reusable with `<test extends="...">` argument) |
| 18 | +* Action Group (reusable with including `<actionGroup ref="...">`, or extending `<actionGroup extends="...">`) |
| 19 | +* Pages (reusable with reference `{{PageDefinition.url}}`) |
| 20 | +* Sections (reusable with reference `{{SectionDefinition.elementDefinition}}`) |
| 21 | +* Data Entities (reusable with reference `<createData entity="...">"` or extending `<entity extends="...">`) |
| 22 | + |
| 23 | +{%endraw%} |
| 24 | + |
| 25 | +<div class="bs-callout bs-callout-warning" markdown="1"> |
| 26 | + |
| 27 | +Avoid using resources that are marked as **Deprecated**. Usually there is a replacement provided for a deprecated resource. |
| 28 | + |
| 29 | +</div> |
| 30 | + |
| 31 | +### Extract repetitive Actions |
| 32 | + |
| 33 | +Instead of writing a few of Tests that perform mostly the same actions, you should thing about [Action group] that is a container for repetitive Actions. |
| 34 | +If each run needs different data, use `<arguments>` to inject necessary information. |
| 35 | + |
| 36 | +We recommend to keep Action Groups having single responsibility, for example `AdminLoginActionGroup`, which expected outcome is being logged in as Administrator when [Action group] is executed. |
| 37 | + |
| 38 | +## Contribute |
| 39 | + |
| 40 | +Althought the Magento Core team and Contributors join forces to cover most of the features with tests, it is impossible to have this done quickly. |
| 41 | +If you've covered Magento Core feature with Functional Tests - you are more than welcome to contribute. |
| 42 | + |
| 43 | +You can also help with MFTF Test Migration to get the experience and valuable feedback from other community members and maintainers. |
| 44 | + |
5 | 45 | ## Action group
|
6 | 46 |
|
7 |
| -1. [Action group] names should be sufficiently descriptive to inform a test writer of what the action group does and when it should be used. |
8 |
| - Add additional explanation in annotations if needed. |
| 47 | +1. [Action group] names should be sufficiently descriptive to inform a test writer of what the action group does and when it should be used. Add additional explanation in annotations if needed. |
9 | 48 | 2. Provide default values for the arguments that apply to your most common case scenarios.
|
10 | 49 | 3. One `<actionGroup>` tag is allowed per action group XML file.
|
11 | 50 |
|
@@ -95,20 +134,20 @@ Use the _Foo.camelCase_ naming convention, which is similar to _Classes_ and _cl
|
95 | 134 |
|
96 | 135 | Use an upper case first letter for:
|
97 | 136 |
|
98 |
| -- File names. Example: _StorefrontCreateCustomerTest.xml_ |
99 |
| -- Test name attributes. Example: `<test name="TestAllTheThingsTest">` |
100 |
| -- Data entity names. Example: `<entity name="OutOfStockProduct">` |
101 |
| -- Page name. Example: `<page name="AdminLoginPage">` |
102 |
| -- Section name. Example: `<section name="AdminCategorySidebarActionSection">` |
103 |
| -- Action group name. Example: `<actionGroup name="LoginToAdminActionGroup">` |
| 137 | +* File names. Example: _StorefrontCreateCustomerTest.xml_ |
| 138 | +* Test name attributes. Example: `<test name="TestAllTheThingsTest">` |
| 139 | +* Data entity names. Example: `<entity name="OutOfStockProduct">` |
| 140 | +* Page name. Example: `<page name="AdminLoginPage">` |
| 141 | +* Section name. Example: `<section name="AdminCategorySidebarActionSection">` |
| 142 | +* Action group name. Example: `<actionGroup name="LoginToAdminActionGroup">` |
104 | 143 |
|
105 | 144 | #### Lower case
|
106 | 145 |
|
107 | 146 | Use a lower case first letter for:
|
108 | 147 |
|
109 |
| -- Data keys. Example: `<data key="firstName">` |
110 |
| -- Element names. Examples: `<element name="confirmDeleteButton"/>` |
111 |
| -- Step keys. For example: `<click selector="..." stepKey="clickLogin"/>` |
| 148 | +* Data keys. Example: `<data key="firstName">` |
| 149 | +* Element names. Examples: `<element name="confirmDeleteButton"/>` |
| 150 | +* Step keys. For example: `<click selector="..." stepKey="clickLogin"/>` |
112 | 151 |
|
113 | 152 | ## Page object
|
114 | 153 |
|
@@ -147,9 +186,9 @@ Define these three elements and reference them by name in the tests.
|
147 | 186 | 1. Keep your tests short and granular for target testing, easier reviews, and easier merge conflict resolution.
|
148 | 187 | It also helps you to identify the cause of test failure.
|
149 | 188 | 1. Use comments to keep tests readable and maintainable:
|
150 |
| - - Keep the inline `<!-- XML comments -->` and [`<comment>`] tags up to date. |
| 189 | + * Keep the inline `<!-- XML comments -->` and [`<comment>`] tags up to date. |
151 | 190 | It helps to inform the reader of what you are testing and to yield a more descriptive Allure report.
|
152 |
| - - Explain in comments unclear or tricky test steps. |
| 191 | + * Explain in comments unclear or tricky test steps. |
153 | 192 | 1. Refer to [sections] instead of writing selectors.
|
154 | 193 | 1. One `<test>` tag is allowed per test XML file.
|
155 | 194 |
|
@@ -178,3 +217,4 @@ Since the configurable product module could be disabled, this approach is more r
|
178 | 217 | [merging]: merging.html
|
179 | 218 | [parameterized selectors]: section/parameterized-selectors.html
|
180 | 219 | [sections]: section.html
|
| 220 | +[MFTF Test Migration]: https://github.com/magento/magento-functional-tests-migration |
0 commit comments