Use Codeception's Locator Functions in the Magento Functional Testing Framework

This topic was updated due to the 2.0.2 MFTF release.

Defining Locator::functions in Elements

Codeception has a set of very useful Locator Functions that may be used by elements inside a section.

Declaration of an element with a locatorFunction can be done as follows:

<element name="simpleLocator" type="button" locatorFunction="Locator::contains('label', 'Name')"/>

When using the locatorFunction, you can also omit Locator:: for code simplicity.

<element name="simpleLocatorShorthand" type="button" locatorFunction="contains('label', 'Name')"/>

An element’s locatorFunction can also be parameterized the same way as parameterized selectors.

<element name="simpleLocatorTwoParam" type="button" locatorFunction="contains({{arg1}}, {{arg2}})" parameterized="true"/>

Lastly, an element cannot have both a selector and a locatorFunction.

Calling Elements that use locatorFunction

Given the above element definitions, we call the elements in a test just like any other element.

No special reference is required, as you are still just referring to an element inside a section.

<test name="LocatorFuctionTest">
    <click selector="{{LocatorFunctionSection.simpleLocator}}" stepKey="SimpleLocator"/>
    <click selector="{{LocatorFunctionSection.simpleLocatorTwoParam('string1', 'string2')}}" stepKey="TwoParamLiteral"/>