Test cases
Test cases in the Functional Testing Framework are defined in XML as <tests>. <tests> is a Codeception test container that contains individual test <test> with its metadata (<annotations>), before (<before>) and after (<after>) section.
The Functional Testing Framework <test> is considered a sequence of actions with associated parameters. Any failed assertion within a test constitutes a failed test.
data-variant=info
data-slots=text
<before> and <after> hooks are not global within <tests>. They only apply to the <test> in which they are declared. The steps in <after> are run in both successful and failed test runs.The following diagram shows the structure of an test case:
Format
The format of a test XML file is:
<?xml version="1.0" encoding="UTF-8"?>
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="" insertBefore="" insertAfter="">
<annotations>
<!-- TEST ANNOTATIONS -->
</annotations>
<before>
<!-- ACTIONS AND ACTION GROUPS PERFORMED BEFORE THE TEST -->
</before>
<after>
<!-- ACTIONS AND ACTION GROUPS PERFORMED AFTER THE TEST -->
</after>
<!-- TEST ACTIONS, ACTION GROUPS, AND ASSERTIONS-->
</test>
</tests>
Principles
The following conventions apply to test:
- One
<test>tag is allowed per test XML file. - All names within the framework are in the PascalCase format and must be alphanumeric.
- Each action and action group call should have its own identifier
<stepKey>. - A test may have any number of assertions at any point within the
<test>. - If
<test>is included in<suite>, it cannot be generated in isolation from<before>and<after>section of the suite (see suites for details).
Elements reference
There are several XML elements that are used within <test> in the MFTF.
tests
<tests> is a container for test and must contain exactly one <test>.
test
<test> is a set of steps, including actions, assertions and Action Group calls. It is a sequence of test steps that define test flow within a test method.
nameremovetrue to remove the test when merging.insertBeforestepKey that you assigned in insertBefore.insertAfterstepKey of the test step after which you want to insert the test when merging.deprecated<test> may also contain <annotations>, <before>, <after>, any action, or <actionGroup>.
annotations
Annotations are supported by both Codeception and Allure.
Codeception annotations typically provide metadata and are able to influence test selection. Allure annotations provide metadata for reporting.
before
<before> wraps the steps that are preconditions for the <test>. For example: Change configuration, create Customer Account, Create Category and Product.
<before> may contain these child elements:
- Any Action
<actionGroup>
after
<after> wraps the steps to perform after the <test>. The steps are run in both successful and failed test runs. The goal of this section is to perform cleanup (revert the environment to the pre-test state).
<after> may contain:
- Any Action
<actionGroup>
actionGroup
<actionGroup> calls a corresponding action group.
refname.stepKey<test>.before<stepKey> of an action or action group that must be executed next while merging.after<stepKey> of an action or action group that must be executed one step before the current one while merging.<actionGroup> may contain <argument>.
argument
<argument> sets an argument that is used in the parent <actionGroup>.
namevalueSee Action groups for more information.