Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit 7755420

Browse files
authored
Merge pull request #2 from magento-pangolin/MQE-336
MQE-336: [Generator] Add support for Codeception "Locator" selectors
2 parents 9f5f57c + 0ba227c commit 7755420

File tree

3 files changed

+60
-2
lines changed

3 files changed

+60
-2
lines changed

_data/toc/magento-functional-testing-framework-guide.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ pages:
2727
- label: Parameterized selectors
2828
url: magento-functional-testing-framework/section/parameterized-selectors.html
2929

30+
- label: Locator Functions
31+
url: magento-functional-testing-framework/section/locator-functions.html
32+
3033
- label: CLI Commands
3134
versions: ["2.3"]
3235
children:

guides/v2.3/magento-functional-testing-framework/section.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ Attributes|Type|Use|Description
106106
---|---|---|---
107107
name|string|required|Element name
108108
type|string|required|The type of the element. Possible values: `text`, `textarea`, `input`, `button`, `checkbox`, `radio`, `checkboxset`, `radioset`, `date`, `file`, `select`, `multiselect`, `wysiwyg`, `iframe`.
109-
selector|string|required|[XPath] or [CSS] selector of the element.
109+
selector|string|optional|[XPath] or [CSS] selector of the element.
110+
locatorFunction|string|optional|[Locator Function] declaration to be used in lieu of a selector.
110111
timeout|string|optional|Default: `-`. Optional timeout value in seconds to wait for the operation on the element.
111112
parameterized|boolean|optional|Include and set to `true` if the `selector` for this element has parameters that need to be replaced for proper use.
112113
remove|boolean|optional|Default: `false`. Set to `true` to remove this element during parsing.
@@ -119,7 +120,8 @@ remove|boolean|optional|Default: `false`. Set to `true` to remove this element d
119120
[page]: page.html
120121
[CSS]: https://www.w3schools.com/cssref/css_selectors.asp
121122
[XPath]: https://www.w3schools.com/xml/xpath_nodes.asp
123+
[Locator Function]: section/locator-functions.html
122124
[cest]: cest.html
123125
[test]: cest.html#test
124126
[createData]: cest/actions.html#createdata
125-
[before]: cest.html#before
127+
[before]: cest.html#before
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
layout: default
3+
group: mftf
4+
title: Use Codeception's Locator Functions in the Magento Functional Testing Framework
5+
version: 2.3
6+
github_link: magento-functional-testing-framework/section/structure/locator-functions.md
7+
---
8+
9+
{%raw%}
10+
11+
## Defining Locator::functions in Elements
12+
13+
Codeception has a set of very useful [Locator Functions] that may be used by elements inside a [section].
14+
15+
Declaration of an element with a `locatorFunction` can be done as follows:
16+
```xml
17+
<element name="simpleLocator" type="button" locatorFunction="Locator::contains('label', 'Name')"/>
18+
```
19+
When using the `locatorFunction`, you can also omit `Locator::` for code simplicity.
20+
```xml
21+
<element name="simpleLocatorShorthand" type="button" locatorFunction="contains('label', 'Name')"/>
22+
```
23+
An element's `locatorFunction` can also be parameterized the same way as [parameterized-selectors].
24+
```xml
25+
<element name="simpleLocatorTwoParam" type="button" locatorFunction="contains({{arg1}}, {{arg2}})" parameterized="true"/>
26+
```
27+
Lastly, an element **cannot** have both a `selector` and a `locatorFunction`.
28+
29+
## Calling Elements that use locatorFunction
30+
31+
Given the above element definitions, we call the elements in a test just like any other element.
32+
33+
No special reference is required, as you are still just referring to an `element` inside a `section`.
34+
35+
```xml
36+
<test name="LocatorFuctionTest">
37+
<click mergeKey="SimpleLocator" selector="{{LocatorFunctionSection.simpleLocator}}"/>
38+
<click mergeKey="TwoParamLiteral" selector="{{LocatorFunctionSection.simpleLocatorTwoParam('string1', 'string2')}}"/>
39+
</test>
40+
```
41+
42+
{%endraw%}
43+
44+
45+
<!-- LINK DEFINITIONS -->
46+
47+
<!-- Internal -->
48+
49+
[section]: ../section.html
50+
[parameterized-selectors]: parameterized-selectors.html
51+
52+
<!-- External -->
53+
[Locator Functions]: http://codeception.com/docs/reference/Locator

0 commit comments

Comments
 (0)