Skip to content

Db mftf extensionpoints #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions docs/merge_points/extend-action-groups.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Extend action groups

Extending an action group doesn't affect the existing action group.

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.

## Starting action group

```xml
<actionGroup name="FillAdminSimpleProductForm">
<arguments>
<argument name="category"/>
<argument name="simpleProduct"/>
</arguments>
<amOnPage url="{{AdminProductIndexPage.url}}" stepKey="navigateToProductIndex"/>
<click selector="{{AdminProductGridActionSection.addProductToggle}}" stepKey="clickAddProductDropdown"/>
<click selector="{{AdminProductGridActionSection.addSimpleProduct}}" stepKey="clickAddSimpleProduct"/>
<fillField userInput="{{simpleProduct.name}}" selector="{{AdminProductFormSection.productName}}" stepKey="fillName"/>
<fillField userInput="{{simpleProduct.sku}}" selector="{{AdminProductFormSection.productSku}}" stepKey="fillSKU"/>
<fillField userInput="{{simpleProduct.price}}" selector="{{AdminProductFormSection.productPrice}}" stepKey="fillPrice"/>
<fillField userInput="{{simpleProduct.quantity}}" selector="{{AdminProductFormSection.productQuantity}}" stepKey="fillQuantity"/>
<searchAndMultiSelectOption selector="{{AdminProductFormSection.categoriesDropdown}}" parameterArray="[{{category.name}}]" stepKey="searchAndSelectCategory"/>
<click selector="{{AdminProductSEOSection.sectionHeader}}" stepKey="openSeoSection"/>
<fillField userInput="{{simpleProduct.urlKey}}" selector="{{AdminProductSEOSection.urlKeyInput}}" stepKey="fillUrlKey"/>
<click selector="{{AdminProductFormActionSection.saveButton}}" stepKey="saveProduct"/>
<seeElement selector="{{AdminProductMessagesSection.successMessage}}" stepKey="assertSaveMessageSuccess"/>
<seeInField userInput="{{simpleProduct.name}}" selector="{{AdminProductFormSection.productName}}" stepKey="assertFieldName"/>
<seeInField userInput="{{simpleProduct.sku}}" selector="{{AdminProductFormSection.productSku}}" stepKey="assertFieldSku"/>
<seeInField userInput="{{simpleProduct.price}}" selector="{{AdminProductFormSection.productPrice}}" stepKey="assertFieldPrice"/>
<click selector="{{AdminProductSEOSection.sectionHeader}}" stepKey="openSeoSectionAssert"/>
<seeInField userInput="{{simpleProduct.urlKey}}" selector="{{AdminProductSEOSection.urlKeyInput}}" stepKey="assertFieldUrlKey"/>
</actionGroup>
```

## File to merge

```xml
<actionGroup name="FillAdminSimpleProductFormWithMyExtension" extends="FillAdminSimpleProductForm">
<!-- This will be added after the step "fillQuantity" on line 12 in the above test. -->
<click selector="{{MyExtensionSection.myCheckbox}}" stepKey="clickMyCheckbox" after="fillQuantity"/>
</actionGroup>
```

## Resultant action group

Note that there are now two action groups below.

```xml
<actionGroup name="FillAdminSimpleProductForm">
<arguments>
<argument name="category"/>
<argument name="simpleProduct"/>
</arguments>
<amOnPage url="{{AdminProductIndexPage.url}}" stepKey="navigateToProductIndex"/>
<click selector="{{AdminProductGridActionSection.addProductToggle}}" stepKey="clickAddProductDropdown"/>
<click selector="{{AdminProductGridActionSection.addSimpleProduct}}" stepKey="clickAddSimpleProduct"/>
<fillField userInput="{{simpleProduct.name}}" selector="{{AdminProductFormSection.productName}}" stepKey="fillName"/>
<fillField userInput="{{simpleProduct.sku}}" selector="{{AdminProductFormSection.productSku}}" stepKey="fillSKU"/>
<fillField userInput="{{simpleProduct.price}}" selector="{{AdminProductFormSection.productPrice}}" stepKey="fillPrice"/>
<fillField userInput="{{simpleProduct.quantity}}" selector="{{AdminProductFormSection.productQuantity}}" stepKey="fillQuantity"/>
<searchAndMultiSelectOption selector="{{AdminProductFormSection.categoriesDropdown}}" parameterArray="[{{category.name}}]" stepKey="searchAndSelectCategory"/>
<click selector="{{AdminProductSEOSection.sectionHeader}}" stepKey="openSeoSection"/>
<fillField userInput="{{simpleProduct.urlKey}}" selector="{{AdminProductSEOSection.urlKeyInput}}" stepKey="fillUrlKey"/>
<click selector="{{AdminProductFormActionSection.saveButton}}" stepKey="saveProduct"/>
<seeElement selector="{{AdminProductMessagesSection.successMessage}}" stepKey="assertSaveMessageSuccess"/>
<seeInField userInput="{{simpleProduct.name}}" selector="{{AdminProductFormSection.productName}}" stepKey="assertFieldName"/>
<seeInField userInput="{{simpleProduct.sku}}" selector="{{AdminProductFormSection.productSku}}" stepKey="assertFieldSku"/>
<seeInField userInput="{{simpleProduct.price}}" selector="{{AdminProductFormSection.productPrice}}" stepKey="assertFieldPrice"/>
<click selector="{{AdminProductSEOSection.sectionHeader}}" stepKey="openSeoSectionAssert"/>
<seeInField userInput="{{simpleProduct.urlKey}}" selector="{{AdminProductSEOSection.urlKeyInput}}" stepKey="assertFieldUrlKey"/>
</actionGroup>
<actionGroup name="FillAdminSimpleProductFormWithMyExtension">
<arguments>
<argument name="category"/>
<argument name="simpleProduct"/>
</arguments>
<amOnPage url="{{AdminProductIndexPage.url}}" stepKey="navigateToProductIndex"/>
<click selector="{{AdminProductGridActionSection.addProductToggle}}" stepKey="clickAddProductDropdown"/>
<click selector="{{AdminProductGridActionSection.addSimpleProduct}}" stepKey="clickAddSimpleProduct"/>
<fillField userInput="{{simpleProduct.name}}" selector="{{AdminProductFormSection.productName}}" stepKey="fillName"/>
<fillField userInput="{{simpleProduct.sku}}" selector="{{AdminProductFormSection.productSku}}" stepKey="fillSKU"/>
<fillField userInput="{{simpleProduct.price}}" selector="{{AdminProductFormSection.productPrice}}" stepKey="fillPrice"/>
<fillField userInput="{{simpleProduct.quantity}}" selector="{{AdminProductFormSection.productQuantity}}" stepKey="fillQuantity"/>

<click selector="{{MyExtensionSection.myCheckbox}}" stepKey="clickMyCheckbox"/>

<searchAndMultiSelectOption selector="{{AdminProductFormSection.categoriesDropdown}}" parameterArray="[{{category.name}}]" stepKey="searchAndSelectCategory"/>
<click selector="{{AdminProductSEOSection.sectionHeader}}" stepKey="openSeoSection"/>
<fillField userInput="{{simpleProduct.urlKey}}" selector="{{AdminProductSEOSection.urlKeyInput}}" stepKey="fillUrlKey"/>
<click selector="{{AdminProductFormActionSection.saveButton}}" stepKey="saveProduct"/>
<seeElement selector="{{AdminProductMessagesSection.successMessage}}" stepKey="assertSaveMessageSuccess"/>
<seeInField userInput="{{simpleProduct.name}}" selector="{{AdminProductFormSection.productName}}" stepKey="assertFieldName"/>
<seeInField userInput="{{simpleProduct.sku}}" selector="{{AdminProductFormSection.productSku}}" stepKey="assertFieldSku"/>
<seeInField userInput="{{simpleProduct.price}}" selector="{{AdminProductFormSection.productPrice}}" stepKey="assertFieldPrice"/>
<click selector="{{AdminProductSEOSection.sectionHeader}}" stepKey="openSeoSectionAssert"/>
<seeInField userInput="{{simpleProduct.urlKey}}" selector="{{AdminProductSEOSection.urlKeyInput}}" stepKey="assertFieldUrlKey"/>
</actionGroup>
```
70 changes: 70 additions & 0 deletions docs/merge_points/extend-data.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Extend data entities

Extending an action group doesn't affect the existing action group.

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.

## Starting entity

```xml
<entity name="SimpleProduct" type="product">
<data key="sku" unique="suffix">SimpleProduct</data>
<data key="type_id">simple</data>
<data key="attribute_set_id">4</data>
<data key="name" unique="suffix">SimpleProduct</data>
<data key="price">123.00</data>
<data key="visibility">4</data>
<data key="status">1</data>
<data key="quantity">1000</data>
<data key="urlKey" unique="suffix">simpleproduct</data>
<data key="weight">1</data>
<requiredEntity type="product_extension_attribute">EavStockItem</requiredEntity>
<requiredEntity type="custom_attribute_array">CustomAttributeCategoryIds</requiredEntity>
</entity>
```

## File to merge

```xml
<entity name="ExtensionProduct" type="product" extends="SimpleProduct">
<!-- myExtensionData will simply be added to the product and quantity will be changed to 1001. -->
<data key="quantity">1001</data>
<data key="myExtensionData">dataHere</data>
</entity>
```

## Resultant entity

Note that there are now two data entities below.

```xml
<entity name="SimpleProduct" type="product">
<data key="sku" unique="suffix">SimpleProduct</data>
<data key="type_id">simple</data>
<data key="attribute_set_id">4</data>
<data key="name" unique="suffix">SimpleProduct</data>
<data key="price">123.00</data>
<data key="visibility">4</data>
<data key="status">1</data>
<data key="quantity">1000</data>
<data key="urlKey" unique="suffix">simpleproduct</data>
<data key="weight">1</data>
<requiredEntity type="product_extension_attribute">EavStockItem</requiredEntity>
<requiredEntity type="custom_attribute_array">CustomAttributeCategoryIds</requiredEntity>
</entity>
<entity name="ExtensionProduct" type="product">
<data key="sku" unique="suffix">SimpleProduct</data>
<data key="type_id">simple</data>
<data key="attribute_set_id">4</data>
<data key="name" unique="suffix">SimpleProduct</data>
<data key="price">123.00</data>
<data key="visibility">4</data>
<data key="status">1</data>
<data key="quantity">1001</data>
<data key="urlKey" unique="suffix">simpleproduct</data>
<data key="weight">1</data>
<requiredEntity type="product_extension_attribute">EavStockItem</requiredEntity>
<requiredEntity type="custom_attribute_array">CustomAttributeCategoryIds</requiredEntity>
<data key="myExtensionData">dataHere</data>
</entity>
```
145 changes: 145 additions & 0 deletions docs/merge_points/extend-tests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# Extend tests

Data objects can be merged to cover the needs of your extension.

In this example, we add an action group to a new copy of the original test for our extension.

## Starting test

```xml
<test name="AdminCreateSimpleProductTest">
<annotations>
<features value="Catalog"/>
<stories value="Create a Simple Product via Admin"/>
<title value="Admin should be able to create a Simple Product"/>
<description value="Admin should be able to create a Simple Product"/>
<severity value="CRITICAL"/>
<testCaseId value="MAGETWO-23414"/>
<group value="product"/>
</annotations>
<before>
<createData entity="_defaultCategory" stepKey="createPreReqCategory"/>
</before>
<after>
<amOnPage url="admin/admin/auth/logout/" stepKey="amOnLogoutPage"/>
<deleteData createDataKey="createPreReqCategory" stepKey="deletePreReqCategory"/>
</after>

<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin1"/>
<actionGroup ref="FillAdminSimpleProductForm" stepKey="fillProductFieldsInAdmin">
<argument name="category" value="$$createPreReqCategory$$"/>
<argument name="simpleProduct" value="_defaultProduct"/>
</actionGroup>
<actionGroup ref="AssertProductInStorefrontCategoryPage" stepKey="assertProductInStorefront1">
<argument name="category" value="$$createPreReqCategory$$"/>
<argument name="product" value="_defaultProduct"/>
</actionGroup>
<actionGroup ref="AssertProductInStorefrontProductPage" stepKey="assertProductInStorefront2">
<argument name="product" value="_defaultProduct"/>
</actionGroup>
</test>
```

## File to merge

```xml
<test name="AdminCreateSimpleProductExtensionTest" extends="AdminCreateSimpleProductTest">
<!-- Since this is its own test you need the annotations block -->
<annotations>
<features value="Catalog"/>
<stories value="Create a Simple Product via Admin"/> <!-- you should leave this the same since it is part of the same group -->
<title value="Admin should be able to create a Simple Product with my extension"/>
<description value="Admin should be able to create a Simple Product with my extension via the product grid"/>
<severity value="CRITICAL"/>
<testCaseId value="Extension/Github Issue Number"/>
<group value="product"/>
</annotations>
<!-- This will be added after the step "fillProductFieldsInAdmin" on line 20 in the above test. -->
<actionGroup ref="AddMyExtensionData" stepKey="extensionField" after="fillProductFieldsInAdmin">
<argument name="extensionData" value="_myData"/>
</actionGroup>

<!-- This will be added after the step "assertProductInStorefront2" on line 28 in the above test. -->
<actionGroup ref="AssertMyExtensionDataExists" stepKey="assertExtensionInformation" after="assertProductInStorefront2">
<argument name="extensionData" value="_myData"/>
</actionGroup>
</test>
```

## Resultant test

Note that there are now two tests below.

```xml
<test name="AdminCreateSimpleProductTest">
<annotations>
<features value="Catalog"/>
<stories value="Create a Simple Product via Admin"/>
<title value="Admin should be able to create a Simple Product"/>
<description value="Admin should be able to create a Simple Product"/>
<severity value="CRITICAL"/>
<testCaseId value="MAGETWO-23414"/>
<group value="product"/>
</annotations>
<before>
<createData entity="_defaultCategory" stepKey="createPreReqCategory"/>
</before>
<after>
<amOnPage url="admin/admin/auth/logout/" stepKey="amOnLogoutPage"/>
<deleteData createDataKey="createPreReqCategory" stepKey="deletePreReqCategory"/>
</after>

<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin1"/>
<actionGroup ref="FillAdminSimpleProductForm" stepKey="fillProductFieldsInAdmin">
<argument name="category" value="$$createPreReqCategory$$"/>
<argument name="simpleProduct" value="_defaultProduct"/>
</actionGroup>
<actionGroup ref="AssertProductInStorefrontCategoryPage" stepKey="assertProductInStorefront1">
<argument name="category" value="$$createPreReqCategory$$"/>
<argument name="product" value="_defaultProduct"/>
</actionGroup>
<actionGroup ref="AssertProductInStorefrontProductPage" stepKey="assertProductInStorefront2">
<argument name="product" value="_defaultProduct"/>
</actionGroup>
</test>
<test name="AdminCreateSimpleProductExtensionTest">
<annotations>
<features value="Catalog"/>
<stories value="Create a Simple Product via Admin"/>
<title value="Admin should be able to create a Simple Product with my extension"/>
<description value="Admin should be able to create a Simple Product with my extension via the product grid"/>
<severity value="CRITICAL"/>
<testCaseId value="Extension/Github Issue Number"/>
<group value="product"/>
</annotations>
<before>
<createData entity="_defaultCategory" stepKey="createPreReqCategory"/>
</before>
<after>
<amOnPage url="admin/admin/auth/logout/" stepKey="amOnLogoutPage"/>
<deleteData createDataKey="createPreReqCategory" stepKey="deletePreReqCategory"/>
</after>

<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin1"/>
<actionGroup ref="FillAdminSimpleProductForm" stepKey="fillProductFieldsInAdmin">
<argument name="category" value="$$createPreReqCategory$$"/>
<argument name="simpleProduct" value="_defaultProduct"/>
</actionGroup>

<actionGroup ref="AddMyExtensionData" stepKey="extensionField">
<argument name="extensionData" value="_myData"/>
</actionGroup>

<actionGroup ref="AssertProductInStorefrontCategoryPage" stepKey="assertProductInStorefront1">
<argument name="category" value="$$createPreReqCategory$$"/>
<argument name="product" value="_defaultProduct"/>
</actionGroup>
<actionGroup ref="AssertProductInStorefrontProductPage" stepKey="assertProductInStorefront2">
<argument name="product" value="_defaultProduct"/>
</actionGroup>

<actionGroup ref="AssertMyExtensionDataExists" stepKey="assertExtensionInformation">
<argument name="extensionData" value="_myData"/>
</actionGroup>
</test>
```
39 changes: 39 additions & 0 deletions docs/merge_points/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Merge Points for testing extensions in MFTF

The Magento Functional Testing Framework (MFTF) allows great flexibility when writing XML tests for extensions.
All parts of tests can be used, reused, and merged to best suit your needs and cut down on needless duplication.

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.
This topic shows how to merge and reuse test elements when testing extensions.

## Merging

Follow the links below for an example of how to merge:

- [Merge Action Groups][]
- [Merge Data][]
- [Merge Pages][]
- [Merge Sections][]
- [Merge Tests][]

## Extending

Only Test, Action Group, and Data objects in the MFTF Framework can be extended.
Extending can be very useful for extension developers since it will not affect existing tests.

Consult [when to use Extends][] to use extends when deciding whether to merge or extend.

- [Extend Action Groups][]
- [Extend Data][]
- [Extend Tests][]

<!-- Link definitions -->
[when to use Extends]: https://devdocs.magento.com/mftf/docs/best-practices.html#when-to-use-extends
[Merge Action Groups]: https://devdocs.magento.com/mftf/docs/merge_points/merge-action-groups.html
[Merge Data]: https://devdocs.magento.com/mftf/docs/merge_points/merge-data.html
[Merge Pages]: https://devdocs.magento.com/mftf/docs/merge_points/merge-pages.html
[Merge Sections]: https://devdocs.magento.com/mftf/docs/merge_points/merge-sections.html
[Merge Tests]: https://devdocs.magento.com/mftf/docs/merge_points/merge-tests.html
[Extend Action Groups]: https://devdocs.magento.com/mftf/docs/merge_points/extend-action-groups.html
[Extend Data]: https://devdocs.magento.com/mftf/docs/merge_points/extend-data.html
[Extend Tests]: https://devdocs.magento.com/mftf/docs/merge_points/extend-tests.html
Loading