Skip to content

Commit cb395ff

Browse files
authored
Merge pull request #2 from magento-devdocs/db_MFTF_extensionpoints
Db mftf extensionpoints
2 parents 551e925 + f901e4f commit cb395ff

9 files changed

+677
-0
lines changed
+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Extend action groups
2+
3+
Extending an action group doesn't affect the existing action group.
4+
5+
In this example we add a `<click>` command to check the checkbox that our extension added with a new action group for the simple product creation form.
6+
7+
## Starting action group
8+
9+
```xml
10+
<actionGroup name="FillAdminSimpleProductForm">
11+
<arguments>
12+
<argument name="category"/>
13+
<argument name="simpleProduct"/>
14+
</arguments>
15+
<amOnPage url="{{AdminProductIndexPage.url}}" stepKey="navigateToProductIndex"/>
16+
<click selector="{{AdminProductGridActionSection.addProductToggle}}" stepKey="clickAddProductDropdown"/>
17+
<click selector="{{AdminProductGridActionSection.addSimpleProduct}}" stepKey="clickAddSimpleProduct"/>
18+
<fillField userInput="{{simpleProduct.name}}" selector="{{AdminProductFormSection.productName}}" stepKey="fillName"/>
19+
<fillField userInput="{{simpleProduct.sku}}" selector="{{AdminProductFormSection.productSku}}" stepKey="fillSKU"/>
20+
<fillField userInput="{{simpleProduct.price}}" selector="{{AdminProductFormSection.productPrice}}" stepKey="fillPrice"/>
21+
<fillField userInput="{{simpleProduct.quantity}}" selector="{{AdminProductFormSection.productQuantity}}" stepKey="fillQuantity"/>
22+
<searchAndMultiSelectOption selector="{{AdminProductFormSection.categoriesDropdown}}" parameterArray="[{{category.name}}]" stepKey="searchAndSelectCategory"/>
23+
<click selector="{{AdminProductSEOSection.sectionHeader}}" stepKey="openSeoSection"/>
24+
<fillField userInput="{{simpleProduct.urlKey}}" selector="{{AdminProductSEOSection.urlKeyInput}}" stepKey="fillUrlKey"/>
25+
<click selector="{{AdminProductFormActionSection.saveButton}}" stepKey="saveProduct"/>
26+
<seeElement selector="{{AdminProductMessagesSection.successMessage}}" stepKey="assertSaveMessageSuccess"/>
27+
<seeInField userInput="{{simpleProduct.name}}" selector="{{AdminProductFormSection.productName}}" stepKey="assertFieldName"/>
28+
<seeInField userInput="{{simpleProduct.sku}}" selector="{{AdminProductFormSection.productSku}}" stepKey="assertFieldSku"/>
29+
<seeInField userInput="{{simpleProduct.price}}" selector="{{AdminProductFormSection.productPrice}}" stepKey="assertFieldPrice"/>
30+
<click selector="{{AdminProductSEOSection.sectionHeader}}" stepKey="openSeoSectionAssert"/>
31+
<seeInField userInput="{{simpleProduct.urlKey}}" selector="{{AdminProductSEOSection.urlKeyInput}}" stepKey="assertFieldUrlKey"/>
32+
</actionGroup>
33+
```
34+
35+
## File to merge
36+
37+
```xml
38+
<actionGroup name="FillAdminSimpleProductFormWithMyExtension" extends="FillAdminSimpleProductForm">
39+
<!-- This will be added after the step "fillQuantity" on line 12 in the above test. -->
40+
<click selector="{{MyExtensionSection.myCheckbox}}" stepKey="clickMyCheckbox" after="fillQuantity"/>
41+
</actionGroup>
42+
```
43+
44+
## Resultant action group
45+
46+
Note that there are now two action groups below.
47+
48+
```xml
49+
<actionGroup name="FillAdminSimpleProductForm">
50+
<arguments>
51+
<argument name="category"/>
52+
<argument name="simpleProduct"/>
53+
</arguments>
54+
<amOnPage url="{{AdminProductIndexPage.url}}" stepKey="navigateToProductIndex"/>
55+
<click selector="{{AdminProductGridActionSection.addProductToggle}}" stepKey="clickAddProductDropdown"/>
56+
<click selector="{{AdminProductGridActionSection.addSimpleProduct}}" stepKey="clickAddSimpleProduct"/>
57+
<fillField userInput="{{simpleProduct.name}}" selector="{{AdminProductFormSection.productName}}" stepKey="fillName"/>
58+
<fillField userInput="{{simpleProduct.sku}}" selector="{{AdminProductFormSection.productSku}}" stepKey="fillSKU"/>
59+
<fillField userInput="{{simpleProduct.price}}" selector="{{AdminProductFormSection.productPrice}}" stepKey="fillPrice"/>
60+
<fillField userInput="{{simpleProduct.quantity}}" selector="{{AdminProductFormSection.productQuantity}}" stepKey="fillQuantity"/>
61+
<searchAndMultiSelectOption selector="{{AdminProductFormSection.categoriesDropdown}}" parameterArray="[{{category.name}}]" stepKey="searchAndSelectCategory"/>
62+
<click selector="{{AdminProductSEOSection.sectionHeader}}" stepKey="openSeoSection"/>
63+
<fillField userInput="{{simpleProduct.urlKey}}" selector="{{AdminProductSEOSection.urlKeyInput}}" stepKey="fillUrlKey"/>
64+
<click selector="{{AdminProductFormActionSection.saveButton}}" stepKey="saveProduct"/>
65+
<seeElement selector="{{AdminProductMessagesSection.successMessage}}" stepKey="assertSaveMessageSuccess"/>
66+
<seeInField userInput="{{simpleProduct.name}}" selector="{{AdminProductFormSection.productName}}" stepKey="assertFieldName"/>
67+
<seeInField userInput="{{simpleProduct.sku}}" selector="{{AdminProductFormSection.productSku}}" stepKey="assertFieldSku"/>
68+
<seeInField userInput="{{simpleProduct.price}}" selector="{{AdminProductFormSection.productPrice}}" stepKey="assertFieldPrice"/>
69+
<click selector="{{AdminProductSEOSection.sectionHeader}}" stepKey="openSeoSectionAssert"/>
70+
<seeInField userInput="{{simpleProduct.urlKey}}" selector="{{AdminProductSEOSection.urlKeyInput}}" stepKey="assertFieldUrlKey"/>
71+
</actionGroup>
72+
<actionGroup name="FillAdminSimpleProductFormWithMyExtension">
73+
<arguments>
74+
<argument name="category"/>
75+
<argument name="simpleProduct"/>
76+
</arguments>
77+
<amOnPage url="{{AdminProductIndexPage.url}}" stepKey="navigateToProductIndex"/>
78+
<click selector="{{AdminProductGridActionSection.addProductToggle}}" stepKey="clickAddProductDropdown"/>
79+
<click selector="{{AdminProductGridActionSection.addSimpleProduct}}" stepKey="clickAddSimpleProduct"/>
80+
<fillField userInput="{{simpleProduct.name}}" selector="{{AdminProductFormSection.productName}}" stepKey="fillName"/>
81+
<fillField userInput="{{simpleProduct.sku}}" selector="{{AdminProductFormSection.productSku}}" stepKey="fillSKU"/>
82+
<fillField userInput="{{simpleProduct.price}}" selector="{{AdminProductFormSection.productPrice}}" stepKey="fillPrice"/>
83+
<fillField userInput="{{simpleProduct.quantity}}" selector="{{AdminProductFormSection.productQuantity}}" stepKey="fillQuantity"/>
84+
85+
<click selector="{{MyExtensionSection.myCheckbox}}" stepKey="clickMyCheckbox"/>
86+
87+
<searchAndMultiSelectOption selector="{{AdminProductFormSection.categoriesDropdown}}" parameterArray="[{{category.name}}]" stepKey="searchAndSelectCategory"/>
88+
<click selector="{{AdminProductSEOSection.sectionHeader}}" stepKey="openSeoSection"/>
89+
<fillField userInput="{{simpleProduct.urlKey}}" selector="{{AdminProductSEOSection.urlKeyInput}}" stepKey="fillUrlKey"/>
90+
<click selector="{{AdminProductFormActionSection.saveButton}}" stepKey="saveProduct"/>
91+
<seeElement selector="{{AdminProductMessagesSection.successMessage}}" stepKey="assertSaveMessageSuccess"/>
92+
<seeInField userInput="{{simpleProduct.name}}" selector="{{AdminProductFormSection.productName}}" stepKey="assertFieldName"/>
93+
<seeInField userInput="{{simpleProduct.sku}}" selector="{{AdminProductFormSection.productSku}}" stepKey="assertFieldSku"/>
94+
<seeInField userInput="{{simpleProduct.price}}" selector="{{AdminProductFormSection.productPrice}}" stepKey="assertFieldPrice"/>
95+
<click selector="{{AdminProductSEOSection.sectionHeader}}" stepKey="openSeoSectionAssert"/>
96+
<seeInField userInput="{{simpleProduct.urlKey}}" selector="{{AdminProductSEOSection.urlKeyInput}}" stepKey="assertFieldUrlKey"/>
97+
</actionGroup>
98+
```

docs/merge_points/extend-data.md

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Extend data entities
2+
3+
Extending an action group doesn't affect the existing action group.
4+
5+
In this example we add a `<click>` command to check the checkbox that our extension added with a new action group for the simple product creation form.
6+
7+
## Starting entity
8+
9+
```xml
10+
<entity name="SimpleProduct" type="product">
11+
<data key="sku" unique="suffix">SimpleProduct</data>
12+
<data key="type_id">simple</data>
13+
<data key="attribute_set_id">4</data>
14+
<data key="name" unique="suffix">SimpleProduct</data>
15+
<data key="price">123.00</data>
16+
<data key="visibility">4</data>
17+
<data key="status">1</data>
18+
<data key="quantity">1000</data>
19+
<data key="urlKey" unique="suffix">simpleproduct</data>
20+
<data key="weight">1</data>
21+
<requiredEntity type="product_extension_attribute">EavStockItem</requiredEntity>
22+
<requiredEntity type="custom_attribute_array">CustomAttributeCategoryIds</requiredEntity>
23+
</entity>
24+
```
25+
26+
## File to merge
27+
28+
```xml
29+
<entity name="ExtensionProduct" type="product" extends="SimpleProduct">
30+
<!-- myExtensionData will simply be added to the product and quantity will be changed to 1001. -->
31+
<data key="quantity">1001</data>
32+
<data key="myExtensionData">dataHere</data>
33+
</entity>
34+
```
35+
36+
## Resultant entity
37+
38+
Note that there are now two data entities below.
39+
40+
```xml
41+
<entity name="SimpleProduct" type="product">
42+
<data key="sku" unique="suffix">SimpleProduct</data>
43+
<data key="type_id">simple</data>
44+
<data key="attribute_set_id">4</data>
45+
<data key="name" unique="suffix">SimpleProduct</data>
46+
<data key="price">123.00</data>
47+
<data key="visibility">4</data>
48+
<data key="status">1</data>
49+
<data key="quantity">1000</data>
50+
<data key="urlKey" unique="suffix">simpleproduct</data>
51+
<data key="weight">1</data>
52+
<requiredEntity type="product_extension_attribute">EavStockItem</requiredEntity>
53+
<requiredEntity type="custom_attribute_array">CustomAttributeCategoryIds</requiredEntity>
54+
</entity>
55+
<entity name="ExtensionProduct" type="product">
56+
<data key="sku" unique="suffix">SimpleProduct</data>
57+
<data key="type_id">simple</data>
58+
<data key="attribute_set_id">4</data>
59+
<data key="name" unique="suffix">SimpleProduct</data>
60+
<data key="price">123.00</data>
61+
<data key="visibility">4</data>
62+
<data key="status">1</data>
63+
<data key="quantity">1001</data>
64+
<data key="urlKey" unique="suffix">simpleproduct</data>
65+
<data key="weight">1</data>
66+
<requiredEntity type="product_extension_attribute">EavStockItem</requiredEntity>
67+
<requiredEntity type="custom_attribute_array">CustomAttributeCategoryIds</requiredEntity>
68+
<data key="myExtensionData">dataHere</data>
69+
</entity>
70+
```

docs/merge_points/extend-tests.md

+145
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# Extend tests
2+
3+
Data objects can be merged to cover the needs of your extension.
4+
5+
In this example, we add an action group to a new copy of the original test for our extension.
6+
7+
## Starting test
8+
9+
```xml
10+
<test name="AdminCreateSimpleProductTest">
11+
<annotations>
12+
<features value="Catalog"/>
13+
<stories value="Create a Simple Product via Admin"/>
14+
<title value="Admin should be able to create a Simple Product"/>
15+
<description value="Admin should be able to create a Simple Product"/>
16+
<severity value="CRITICAL"/>
17+
<testCaseId value="MAGETWO-23414"/>
18+
<group value="product"/>
19+
</annotations>
20+
<before>
21+
<createData entity="_defaultCategory" stepKey="createPreReqCategory"/>
22+
</before>
23+
<after>
24+
<amOnPage url="admin/admin/auth/logout/" stepKey="amOnLogoutPage"/>
25+
<deleteData createDataKey="createPreReqCategory" stepKey="deletePreReqCategory"/>
26+
</after>
27+
28+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin1"/>
29+
<actionGroup ref="FillAdminSimpleProductForm" stepKey="fillProductFieldsInAdmin">
30+
<argument name="category" value="$$createPreReqCategory$$"/>
31+
<argument name="simpleProduct" value="_defaultProduct"/>
32+
</actionGroup>
33+
<actionGroup ref="AssertProductInStorefrontCategoryPage" stepKey="assertProductInStorefront1">
34+
<argument name="category" value="$$createPreReqCategory$$"/>
35+
<argument name="product" value="_defaultProduct"/>
36+
</actionGroup>
37+
<actionGroup ref="AssertProductInStorefrontProductPage" stepKey="assertProductInStorefront2">
38+
<argument name="product" value="_defaultProduct"/>
39+
</actionGroup>
40+
</test>
41+
```
42+
43+
## File to merge
44+
45+
```xml
46+
<test name="AdminCreateSimpleProductExtensionTest" extends="AdminCreateSimpleProductTest">
47+
<!-- Since this is its own test you need the annotations block -->
48+
<annotations>
49+
<features value="Catalog"/>
50+
<stories value="Create a Simple Product via Admin"/> <!-- you should leave this the same since it is part of the same group -->
51+
<title value="Admin should be able to create a Simple Product with my extension"/>
52+
<description value="Admin should be able to create a Simple Product with my extension via the product grid"/>
53+
<severity value="CRITICAL"/>
54+
<testCaseId value="Extension/Github Issue Number"/>
55+
<group value="product"/>
56+
</annotations>
57+
<!-- This will be added after the step "fillProductFieldsInAdmin" on line 20 in the above test. -->
58+
<actionGroup ref="AddMyExtensionData" stepKey="extensionField" after="fillProductFieldsInAdmin">
59+
<argument name="extensionData" value="_myData"/>
60+
</actionGroup>
61+
62+
<!-- This will be added after the step "assertProductInStorefront2" on line 28 in the above test. -->
63+
<actionGroup ref="AssertMyExtensionDataExists" stepKey="assertExtensionInformation" after="assertProductInStorefront2">
64+
<argument name="extensionData" value="_myData"/>
65+
</actionGroup>
66+
</test>
67+
```
68+
69+
## Resultant test
70+
71+
Note that there are now two tests below.
72+
73+
```xml
74+
<test name="AdminCreateSimpleProductTest">
75+
<annotations>
76+
<features value="Catalog"/>
77+
<stories value="Create a Simple Product via Admin"/>
78+
<title value="Admin should be able to create a Simple Product"/>
79+
<description value="Admin should be able to create a Simple Product"/>
80+
<severity value="CRITICAL"/>
81+
<testCaseId value="MAGETWO-23414"/>
82+
<group value="product"/>
83+
</annotations>
84+
<before>
85+
<createData entity="_defaultCategory" stepKey="createPreReqCategory"/>
86+
</before>
87+
<after>
88+
<amOnPage url="admin/admin/auth/logout/" stepKey="amOnLogoutPage"/>
89+
<deleteData createDataKey="createPreReqCategory" stepKey="deletePreReqCategory"/>
90+
</after>
91+
92+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin1"/>
93+
<actionGroup ref="FillAdminSimpleProductForm" stepKey="fillProductFieldsInAdmin">
94+
<argument name="category" value="$$createPreReqCategory$$"/>
95+
<argument name="simpleProduct" value="_defaultProduct"/>
96+
</actionGroup>
97+
<actionGroup ref="AssertProductInStorefrontCategoryPage" stepKey="assertProductInStorefront1">
98+
<argument name="category" value="$$createPreReqCategory$$"/>
99+
<argument name="product" value="_defaultProduct"/>
100+
</actionGroup>
101+
<actionGroup ref="AssertProductInStorefrontProductPage" stepKey="assertProductInStorefront2">
102+
<argument name="product" value="_defaultProduct"/>
103+
</actionGroup>
104+
</test>
105+
<test name="AdminCreateSimpleProductExtensionTest">
106+
<annotations>
107+
<features value="Catalog"/>
108+
<stories value="Create a Simple Product via Admin"/>
109+
<title value="Admin should be able to create a Simple Product with my extension"/>
110+
<description value="Admin should be able to create a Simple Product with my extension via the product grid"/>
111+
<severity value="CRITICAL"/>
112+
<testCaseId value="Extension/Github Issue Number"/>
113+
<group value="product"/>
114+
</annotations>
115+
<before>
116+
<createData entity="_defaultCategory" stepKey="createPreReqCategory"/>
117+
</before>
118+
<after>
119+
<amOnPage url="admin/admin/auth/logout/" stepKey="amOnLogoutPage"/>
120+
<deleteData createDataKey="createPreReqCategory" stepKey="deletePreReqCategory"/>
121+
</after>
122+
123+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin1"/>
124+
<actionGroup ref="FillAdminSimpleProductForm" stepKey="fillProductFieldsInAdmin">
125+
<argument name="category" value="$$createPreReqCategory$$"/>
126+
<argument name="simpleProduct" value="_defaultProduct"/>
127+
</actionGroup>
128+
129+
<actionGroup ref="AddMyExtensionData" stepKey="extensionField">
130+
<argument name="extensionData" value="_myData"/>
131+
</actionGroup>
132+
133+
<actionGroup ref="AssertProductInStorefrontCategoryPage" stepKey="assertProductInStorefront1">
134+
<argument name="category" value="$$createPreReqCategory$$"/>
135+
<argument name="product" value="_defaultProduct"/>
136+
</actionGroup>
137+
<actionGroup ref="AssertProductInStorefrontProductPage" stepKey="assertProductInStorefront2">
138+
<argument name="product" value="_defaultProduct"/>
139+
</actionGroup>
140+
141+
<actionGroup ref="AssertMyExtensionDataExists" stepKey="assertExtensionInformation">
142+
<argument name="extensionData" value="_myData"/>
143+
</actionGroup>
144+
</test>
145+
```

docs/merge_points/introduction.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Merge Points for testing extensions in MFTF
2+
3+
The Magento Functional Testing Framework (MFTF) allows great flexibility when writing XML tests for extensions.
4+
All parts of tests can be used, reused, and merged to best suit your needs and cut down on needless duplication.
5+
6+
Extension developers can utilitze these merge points to leverage existing tests and modify just the parts needed to test their extension. For instance, if your extension adds a form field to a Catalog admin page, you can modify the existing Catalog tests and add actions, data, etc as needed to test the custom field.
7+
This topic shows how to merge and reuse test elements when testing extensions.
8+
9+
## Merging
10+
11+
Follow the links below for an example of how to merge:
12+
13+
- [Merge Action Groups][]
14+
- [Merge Data][]
15+
- [Merge Pages][]
16+
- [Merge Sections][]
17+
- [Merge Tests][]
18+
19+
## Extending
20+
21+
Only Test, Action Group, and Data objects in the MFTF Framework can be extended.
22+
Extending can be very useful for extension developers since it will not affect existing tests.
23+
24+
Consult [when to use Extends][] to use extends when deciding whether to merge or extend.
25+
26+
- [Extend Action Groups][]
27+
- [Extend Data][]
28+
- [Extend Tests][]
29+
30+
<!-- Link definitions -->
31+
[when to use Extends]: https://devdocs.magento.com/mftf/docs/best-practices.html#when-to-use-extends
32+
[Merge Action Groups]: https://devdocs.magento.com/mftf/docs/merge_points/merge-action-groups.html
33+
[Merge Data]: https://devdocs.magento.com/mftf/docs/merge_points/merge-data.html
34+
[Merge Pages]: https://devdocs.magento.com/mftf/docs/merge_points/merge-pages.html
35+
[Merge Sections]: https://devdocs.magento.com/mftf/docs/merge_points/merge-sections.html
36+
[Merge Tests]: https://devdocs.magento.com/mftf/docs/merge_points/merge-tests.html
37+
[Extend Action Groups]: https://devdocs.magento.com/mftf/docs/merge_points/extend-action-groups.html
38+
[Extend Data]: https://devdocs.magento.com/mftf/docs/merge_points/extend-data.html
39+
[Extend Tests]: https://devdocs.magento.com/mftf/docs/merge_points/extend-tests.html

0 commit comments

Comments
 (0)