You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Due to complexity, you should only write new Custom Helpers as a last resort after trying to implement your test using built-in actions.
3
+
<divclass="bs-callout-warning">
4
+
Due to complexity, you should only write new custom helpers as a last resort, after trying to implement your test using built-in actions.
5
5
</div>
6
6
7
-
Custom Helpers allow test writers to write custom test actions to solve for advanced requirements beyond what MFTF offers out of the box.
7
+
Custom Helpers allow test writers to write custom test actions to solve advanced requirements beyond what MFTF offers out of the box.
8
8
9
-
In MFTF version 3.0.0, we removed the following test actions:
9
+
In MFTF version 3.0.0, the following test actions were removed:
10
10
11
-
*`<executeInSelenium>`
12
-
*`<performOn>`
11
+
*`<executeInSelenium>`
12
+
*`<performOn>`
13
13
14
14
These actions were removed because they allowed custom PHP code to be written inline inside of XML files. This code was difficult to read. It had no proper syntax highlighting and no linting. It was difficult to maintain, troubleshoot, and modify.
15
15
16
16
However, sometimes custom logic beyond what MFTF offers is necessary so we have provided an alternative solution: the `<helper>` action.
17
17
18
18
## Example
19
19
20
-
Custom Helpers are implemented in PHP files that must be placed in this directory:
21
-
```
20
+
Custom helpers are implemented in PHP files that must be placed in this directory:
21
+
22
+
```text
22
23
<ModuleName>/Test/Mftf/Helper
23
24
```
24
25
25
-
Let's take a look at one. This Custom Helper selects text on the page by this approach:
26
+
This custom helper selects text on the page with this approach:
26
27
27
-
1. Move to a very specific X,Y starting position
28
-
2. Click and hold the mouse button down
29
-
3. Move to another specific X,Y position
30
-
4. Release the mouse button
28
+
1. Move to a very specific X,Y starting position.
29
+
1. Click and hold the mouse button down.
30
+
1. Move to another specific X,Y position.
31
+
1. Release the mouse button.
31
32
32
33
This functionality is used to select text on the page and cannot be accomplished using built-in test actions.
33
34
@@ -79,20 +80,21 @@ class SelectText extends Helper
79
80
}
80
81
```
81
82
82
-
### Notes About The PHP File
83
+
### Notes about this PHP file
84
+
85
+
The following details are important about the above file:
83
86
84
-
The following details are important about the file above:
85
-
1. The `namespace` must match the file location like `namespace Magento\PageBuilder\Test\Mftf\Helper;`
86
-
2. The class must `extends Helper` and have the corresponding `use` statement to match
87
-
3. You can get access to the WebDriver object via `$this->getModule('\Magento\FunctionalTestingFramework\Module\MagentoWebDriver')`
88
-
4. You can implement multiple related methods in the same class.
89
-
5. Specify the correct function argument types to match the types of the values you want to pass in. In this case we specified `string $context, int $startX, int $startY, int $endX, int $endY` so in the XML we will match these types.
87
+
1. The `namespace` must match the file location: `namespace Magento\PageBuilder\Test\Mftf\Helper;`
88
+
2. The class must `extends Helper` and have the corresponding `use` statement to match.
89
+
3. You may access the WebDriver object via `$this->getModule('\Magento\FunctionalTestingFramework\Module\MagentoWebDriver')`.
90
+
4. You may implement multiple related methods within the same class.
91
+
5. Specify the correct function argument types to match the type of values you want to pass in. In this case, we specified `string $context, int $startX, int $startY, int $endX, int $endY`. In the XML we will match these types.
90
92
91
-
You should follow the same patterns in any Custom Helpers that you write yourself. But you can implement any logic or iteration that you need to solve for your use case.
93
+
You should follow the same patterns in any custom helpers that you write yourself, but you may implement any logic or iteration that you need to solve for your use case.
92
94
93
-
### Referencing In A Test
95
+
### Referencing in a test
94
96
95
-
Once you have implemented something like the above PHP file. You can then reference it in a test like this:
97
+
Once you have implemented something like the above PHP file, reference it in a test:
@@ -104,23 +106,23 @@ Once you have implemented something like the above PHP file. You can then refere
104
106
</helper>
105
107
```
106
108
107
-
### Notes About The XML
109
+
### Notes about the XML
108
110
109
111
1. Specify an argument value for every argument that matches our PHP implementation. This allows us to pass other test data to the Custom Helper.
110
-
2. The `class` attribute matches the namespace we specified in the PHP file
111
-
3.You can specify the method from the class via the `method` attribute
112
-
4. If the function has a return value, it will be assigned to the stepKey variable. In this case `$selectHeadingTextInTinyMCE`would hold the return value.
112
+
2. The `class` attribute matches the namespace specified in the PHP file.
113
+
3.Specify the method from the class via the `method` attribute.
114
+
4. If the function has a return value, it will be assigned to the `stepKey` variable. In this case,`$selectHeadingTextInTinyMCE`holds the return value.
113
115
5. The types of argument values must match the PHP implementation's expected types.
114
116
115
-
## Key Takeaways
117
+
## Key takeaways
116
118
117
-
Custom Helpers allow you to solve for complex use cases such as conditional logic, iteration, or complex WebDriver usage.
119
+
Custom helpers allow you to solve complex use cases such as conditional logic, iteration, or complex WebDriver usage.
118
120
119
121
With access to the WebDriver object, you have a lot of flexibility available to you. See the [Codeception WebDriver](https://github.com/Codeception/module-webdriver/blob/master/src/Codeception/Module/WebDriver.php) for technical details and functionality available for use.
120
122
121
-
A Custom Helper is written in a PHP file and then referenced in test XML like other actions.
123
+
A custom helper is written in a PHP file and then referenced in test XML, like other actions.
122
124
123
-
Due to complexity, you should only use these as a last resort after trying to implement your test using built-in actions.
125
+
You should only use these as a last resort after trying to implement your test using built-in actions.
0 commit comments