How to preprocess group title render in views? I tried to preprocess a title of the group in the result of the rendering of the view.

Example:

Actual:

Group 1 title
Item 1
Item 2
Item 3
Group 2 title
Item 4
Item 5
Item 6


Expected:

&lt;span class="test"&gt;Group 1 title&lt;span&gt;
Item 1
Item 2
Item 3
&lt;span class="test"&gt;Group 2 title&lt;/span&gt;
Item 4
Item 5
Item 6


Here the similar question on the drupal.org https://www.drupal.org/project/drupal/issues/2950737.
If you want to change the template for the title of the group, why don't you override the template file views-view-grouping.tpl.php for Drupal 7, or views-view-grouping.html.twig for Drupal 8.

By standard Drupal templates names, overrides are also working with this one.

views-view-grouping--MACHINEVIEWNAME.tpl.php for a specific view

views-view-grouping--MACHINEVIEWNAME--MACHINEDISPLAYNAME.tpl.php for a specific display of a specific view.

Hope this can help you.