Skip to content

Commit b8b4d25

Browse files
committed
MQE-1639: [DEVDOCS] Best Practices for including HTML Source in Tests
- Add content about encoding HTML for use in tests
1 parent cd04795 commit b8b4d25

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

docs/test/actions.md

+27-9
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,18 @@ The following test actions handle data entities using [metadata](../metadata.md)
179179

180180
Learn more in [Handling a REST API response](../metadata.md#rest-response).
181181

182+
## Actions specifying HTML values
183+
184+
To use HTML in actions you must encode the HTML string using a tool. We recommend [CyberChef](https://gchq.github.io/CyberChef/#recipe=To_HTML_Entity(false,'Numeric%20entities')). Using CyberChef or a similar tool is easy. You just need to enter in your HTML string, copy the encoded result, and paste that value into your MFTF test.
185+
186+
For example, we want to ensure we don't see this HTML: `<h1 class="login-header">`
187+
188+
After passing `<h1 class="login-header">` through CyberChef we get `&#60;h1 class&#61;&#34;login-header&#34;&#62;` which can be used in a test like:
189+
190+
```xml
191+
<dontSeeInSource html="&#60;h1 class&#61;&#34;login-header&#34;&#62;" stepKey="dontSeeInSource"/>
192+
```
193+
182194
## Reference
183195

184196
The following list contains reference documentation about all action elements available in the MFTF.
@@ -868,17 +880,19 @@ See [dontSeeInSource docs on codeception.com](http://codeception.com/docs/module
868880

869881
Attribute|Type|Use|Description
870882
---|---|---|---
871-
`html`|string|optional| HTML code to search for within the source code.
883+
`html`|string|optional| HTML code to search for within the source code. The value must be encoded. See example.
872884
`stepKey`|string|required| A unique identifier of the action.
873885
`skipReadiness`|boolean|optional| A flag to skip the readiness check.
874886
`before`|string|optional| `stepKey` of action that must be executed next.
875887
`after`|string|optional| `stepKey` of preceding action.
876888

877889
#### Example
878890

891+
You must encode the `html` using a tool such as [CyberChef](https://gchq.github.io/CyberChef/#recipe=To_HTML_Entity(false,'Numeric%20entities')).
892+
879893
```xml
880-
<!-- Verify that the page does not contain the raw source code `<h1>Sample text</h1>`. -->
881-
<dontSeeInSource userInput="<h1>Sample text</h1>" stepKey="dontSeeInSource"/>
894+
<!-- Verify that the page does not contain the raw source code `<h1 class="login-header">`. -->
895+
<dontSeeInSource html="&#60;h1 class&#61;&#34;login-header&#34;&#62;" stepKey="dontSeeInSource"/>
882896
```
883897

884898
### dontSeeInTitle
@@ -1922,17 +1936,19 @@ See [seeInPageSource docs on codeception.com](http://codeception.com/docs/module
19221936

19231937
Attribute|Type|Use|Description
19241938
---|---|---|---
1925-
`html`|string|optional| HTML code to be searched for within the document.
1939+
`html`|string|optional| HTML code to be searched for within the document. The value must be encoded. See example.
19261940
`stepKey`|string|required| A unique identifier of the action.
19271941
`skipReadiness`|boolean|optional| A flag to skip the readiness check.
19281942
`before`|string|optional| `stepKey` of action that must be executed next.
19291943
`after`|string|optional| `stepKey` of preceding action.
19301944

19311945
#### Example
19321946

1947+
You must encode the `html` using a tool such as [CyberChef](https://gchq.github.io/CyberChef/#recipe=To_HTML_Entity(false,'Numeric%20entities')).
1948+
19331949
```xml
1934-
<!-- Verify that the page source contains the string "Sample text". -->
1935-
<seeInPageSource userInput="Sample text" stepKey="seeInPageSource"/>
1950+
<!-- Verify that the page source contains the raw source code `<h1 class="login-header">`. -->
1951+
<seeInPageSource html="&#60;h1 class&#61;&#34;login-header&#34;&#62;" stepKey="seeInPageSource"/>
19361952
```
19371953

19381954
### seeInPopup
@@ -1960,17 +1976,19 @@ See [seeInSource docs on codeception.com](http://codeception.com/docs/modules/We
19601976

19611977
Attribute|Type|Use|Description
19621978
---|---|---|---
1963-
`html`|string|optional| HTML code to be searched for within the page source.
1979+
`html`|string|optional| HTML code to be searched for within the page source. The value must be encoded. See example.
19641980
`stepKey`|string|required| A unique identifier of the action.
19651981
`skipReadiness`|boolean|optional| A flag to skip the readiness check.
19661982
`before`|string|optional| `stepKey` of action that must be executed next.
19671983
`after`|string|optional| `stepKey` of preceding action.
19681984

19691985
#### Example
19701986

1987+
You must encode the `html` using a tool such as [CyberChef](https://gchq.github.io/CyberChef/#recipe=To_HTML_Entity(false,'Numeric%20entities')).
1988+
19711989
```xml
1972-
<!-- Verify that the page does contains the raw source code `<h1>Sample text</h1>`. -->
1973-
<seeInSource userInput="<h1>Sample text</h1>" stepKey="seeInSource"/>
1990+
<!-- Verify that the page does contains the raw source code `<h1 class="login-header">`. -->
1991+
<seeInSource html="&#60;h1 class&#61;&#34;login-header&#34;&#62;" stepKey="seeInSource"/>
19741992
```
19751993

19761994
### seeInTitle

0 commit comments

Comments
 (0)