RadzenDataGrid (component) custom attributes

Hi,

We would like RadzenDataGrid (and other Razden Components) to generate a custom attribute e.g. data-testid="my-grid" for UI test automation navigation. Is this possible?

I can see that RazdenComponent exposes Attributes Components (Blazor) (radzen.com) however there is no example on how to use this (with binding e.g.) and I could not get it to work with experimenting...

Kind regards,
Stefan

Hi @stefanz,

You just need to assign the custom attribute:

<RadzenDataGrid data-testid="mygrid" ...>
1 Like

Thank you that works, user error obviously...

@korchev is there a supported way to do this programmatically (outside of this component/blazor markup?)

we would like to conditionally set the data-testid and preferably avoid introducing if...else into (every) razor markup

Something like this
public static void SetDataTestId(this RadzenComponent component, string dataTestId) { if (..running tests...) { var attributes = new Dictionary<string, object>(component.Attributes); attributes["data-testid"] = dataTestId; #pragma warning disable BL0005 // Component parameter should not be set outside of its component. component.Attributes = attributes; #pragma warning restore BL0005 // Component parameter should not be set outside of its component. } }

I appreciate this might be a Blazor limitation not Razden, still worth asking

I think setting an attribute to null makes it not render. You try that instead. I don't think setting attributes per component instance should be done (as you are trying with the extension method).

Another solution is to inherit from RadzenDataGrid and use component activator for tests. Check this thread for more info: Localize Radzen Datagrid Advanced Filter - #5 by korchev

1 Like

null works thank you