Today we turn to testing with Magento Functional Testing Framework (MFTF), a powerful native tool that can help you facilitate testing.
So what does this framework provide to testers?
What is MFTF?
This autoconversion spares QA specialists the trouble of scripting and enables them to write test cases on the fly. Besides, the framework provides a set of functions, and the existing tests can be used as a viable template for writing new tests. However, to use the whole range of functions MFTF offers, you should configure it correctly.
Planning to work with MFTF or just started testing with it? Here at Amasty, we have decided to share some useful tips from our MFTF experience. They will help you avoid stumbling blocks and make a fast and efficient start.
So let’s begin.
So here are the 3 preparatory steps for seamless testing:
Testing a Magento 2.3 system, you should store the test cases in the module folder, directory Test/Mftf.
Apart from the directory that stores your test cases, you should set up such subdirectories as ActionGroup, Data, Page, Section and other in the MFTF directory. These will store the data structures necessary to run the tests.
Prep steps 1 and 2
You should set noNamespaceSchemaLocation correctly. For Magento 2.3 test cases, it should start with urn:magento:mftf. Otherwise your test won’t start. Please, see the examples of incorrect and correct implementations below.
Prep step 3. Incorrect implementation
Prep step 3. Correct implementation
Simple prep steps complete, you are ready to proceed with writing test cases. And there comes another surprise: annotation section. In MFTF test annotations are of special importance.
Mind annotation section
- Make sure the Value field in a Group annotation is meaningful. Value permits to run a separate Group of tests independently. Relying on our testing practice, we recommend that each test case covers the following Groups. (Note that one test can employ several Groups.):
- VendorName Group for all your tests.
- Module Group that corresponds to the name of the module folder and unites all tests belonging to this module. For example, the group of Order Attributes module is called Orderattr.
- Magento functionality Group (optional). This group includes test cases that cover native Magento features, such as Checkout.
- You can also single out separate logical groups of tests within some module or new custom features. This was the case with testing Improved Layered Navigation module when we introduced several groups of test cases: for filters (FiltersILN), for brands (ShopByBrandILN), for SEO (SeoILN), and more.
Here are the bad and the good example of the Value field.
A reasonably descriptive annotation will help the whole project team to locate the detected issues swiftly. But good annotations are not the only aspect ensuring a smooth start.
Testing with MFTF: cleansing
First of all, upon completion, a test case should clean up the data that may hamper repeating it or running other tests.
Example: A test sets up a field in ?heckout, and in case this field is empty, you can’t place an order. Logically, this will affect the tests related to order placement functionality.
Remember that “cleaning up” is not always about deleting the data. You can simply render a field necessary in the first test optional in the second test. To do so, go to Magento or module settings.
The data a test creates should be unique. This applies to IDs, URLs, keys, names, etc.
In this post, we’ve decided to share some ideas on making the start with MFTF painless and swift. So here’s a short sum-up based on our practice:
- Prep steps: Do invest some time in the correct naming and storing of your test cases.
- Informative annotation section: Make annotations to your test cases reasonably detailed. This will ensure that the whole team understand what a test case is about.
- Tidy test environment: Clotting your test environment with unnecessary data will only make your test cases stumble. So clean it up timely.
This neat checklist helps us set off to testing quickly.
Maybe you have something to add? Please, leave your comments.
For more specific questions arising in the process of testing, you can consult a comprehensive MFTF guide.