st_tag selector¶
Template operator st_tag
creates a custom HTML attribute that enables you to quickly find an HTML tag with this attribute.
This is especially helpful for Behat testing, because st_tag
provides consistent naming convention for page selectors.
Example¶
Twig template:
1 |
|
is rendered to HTML:
1 |
|
Enabling tagging¶
To enable tagging, define a dynamic SiteAccess-aware parameter siso_tools.default.tag-prefix
:
1 |
|
If you set an empty value to this parameter, then all tags are hidden.
It is important, for example, in prod
environment to remove Behat tags.
Implementation¶
Tagging is implemented with a template operator st_tag
.
The operator takes the following parameters:
Parameter | Required | Type | Description | Example |
---|---|---|---|---|
Module/Component | required | string | Identifies module/component/page that you are working on. | product , form |
Element (target) | required | string | Identifies specific field that you are searching for. | price , field , text , label |
Action | required | string | Identifies desired action for the selector. | read - reads to value of text nodefill /write - fills in form fieldclick /follow /submit - clicking on buttons, following links |
ID | optional | number, string | Identifies a unique element that occurs more than once on a page. Helpful when searching for specific element in collections, e.g. product list, multiple images, buttons, etc. | 1200 , button_action |
Value | optional | mix | If you don't want to take the value from the wrapper because it contains special characters or format, you can use this parameter to set a standard format. Can be helpful for example for getting prices. | 1600.00 (instead of 1.600,00 € ) |
Caution
Don't use these attributes in CSS (for styling) or JavaScript (for selecting, hooks, etc.). These attributes have different and specific purpose. In addition, in production mode they can be disabled, which breaks the selectors.
Examples¶
Read price¶
1 |
|
Output:
1 |
|
Read price with custom value¶
1 |
|
Output:
1 |
|
Follow/click a text link¶
1 |
|
Output:
1 |
|
Fill out form field¶
1 |
|
Output:
1 |
|
Check if there is a specific message on the page (e.g. after an Ajax response)¶
1 |
|
Output:
1 |
|
Submit buttons or links¶
Caution
Always use the same naming for buttons which submit data. A Behat test or Google tag manager doesn't recognize whether it is a button, a link or an input field which sends the form.
1 |
|
Output:
1 |
|