RenderedComponent<TComponent> Class

A component rendered by a ComponentTestHost, and the DOM nodes it renders. Its locators search the elements rendered by the component.

public sealed class RenderedComponent<TComponent> : LocatorScope where TComponent : IComponent

Type parameters

TComponent
The type of the component.
Inheritance
LocatorScope RenderedComponent<TComponent>

Properties

NameDescription
ComponentIdGets the identifier of the component in the renderer.
HostGets the test host that renders the component.
InstanceGets the instance of the component.
MarkupGets the HTML rendered by the component, formatted for snapshots.
NodesGets the DOM nodes rendered by the component and its descendants, at the top level of its output.
RenderCountGets the number of times the component was rendered.

Gets the identifier of the component in the renderer.

public int ComponentId { get; }

Property value

int

Gets the test host that renders the component.

public ComponentTestHost Host { get; }

Property value

ComponentTestHost

Gets the instance of the component.

public TComponent Instance { get; }

Property value

TComponent

Gets the HTML rendered by the component, formatted for snapshots.

public string Markup { get; }

Property value

string

Gets the DOM nodes rendered by the component and its descendants, at the top level of its output.

public IReadOnlyList<Node> Nodes { get; }

Property value

IReadOnlyList<Node>

Gets the number of times the component was rendered.

public int RenderCount { get; }

Property value

int

Methods

NameDescription
Find(string)Gets the first element rendered by the component that matches a CSS selector, now (see LocatorScope.Locator for a locator that waits).
Find<TElement>(string)Gets the first element rendered by the component of a type that matches a CSS selector, now.
FindAll(string)Gets the elements rendered by the component that match a CSS selector now, in document order.
FindComponent<TChild>()Gets the first descendant component of a type, in render order.
FindComponents<TChild>()Gets the descendant components of a type, in render order.
FindOrDefault(string)Gets the first element rendered by the component that matches a CSS selector now, or null.
GetAccessibilitySnapshot()Gets the accessibility tree of the elements rendered by the component, as a YAML snapshot (the format of the ARIA snapshots of Playwright).
GetMarkup(MarkupOptions?)Gets the HTML rendered by the component, formatted for snapshots.
SetParametersAsync(Action<ComponentParameterCollectionBuilder<TComponent>>, CancellationToken)Sets parameters of the component (the other parameters keep their values), and waits until the components are idle.
TakeScreenshotAsPng()Takes a screenshot of the elements rendered by the component, encoded as PNG.

Find overloads

Gets the first element rendered by the component that matches a CSS selector, now (see LocatorScope.Locator for a locator that waits).

public Element Find(string selector)
Parameters
selector string
The CSS selector.
Returns

Element The element.

Exceptions
ElementNotFoundException
No element matches the selector.

Find<TElement>(string)

RenderedComponent.cs

Gets the first element rendered by the component of a type that matches a CSS selector, now.

public TElement Find<TElement>(string selector) where TElement : Element
Type parameters
TElement
The type of the element.
Parameters
selector string
The CSS selector.
Returns

TElement The element.

Exceptions
ElementNotFoundException
No element of type TElement matches the selector.

FindAll(string)

RenderedComponent.cs

Gets the elements rendered by the component that match a CSS selector now, in document order.

public IReadOnlyList<Element> FindAll(string selector)

Parameters

selector string
The CSS selector.

Returns

IReadOnlyList<Element> The elements.

FindComponent<TChild>()

RenderedComponent.cs

Gets the first descendant component of a type, in render order.

public RenderedComponent<TChild> FindComponent<TChild>() where TChild : IComponent

Type parameters

TChild
The type of the component.

Returns

RenderedComponent<TChild> The component.

Exceptions

ComponentNotFoundException
The component has no descendant of type TChild.

FindComponents<TChild>()

RenderedComponent.cs

Gets the descendant components of a type, in render order.

public IReadOnlyList<RenderedComponent<TChild>> FindComponents<TChild>() where TChild : IComponent

Type parameters

TChild
The type of the components.

Returns

IReadOnlyList<RenderedComponent<TChild>> The components.

FindOrDefault(string)

RenderedComponent.cs

Gets the first element rendered by the component that matches a CSS selector now, or null.

public Element? FindOrDefault(string selector)

Parameters

selector string
The CSS selector.

Returns

Element? The element, or null.

GetAccessibilitySnapshot()

RenderedComponent.cs

Gets the accessibility tree of the elements rendered by the component, as a YAML snapshot (the format of the ARIA snapshots of Playwright).

public string GetAccessibilitySnapshot()

Returns

string The snapshot.

GetMarkup(MarkupOptions?)

RenderedComponent.cs

Gets the HTML rendered by the component, formatted for snapshots.

public string GetMarkup(MarkupOptions? options = null)

Parameters

options MarkupOptions?
The options, or null for the default options.

Returns

string The HTML.

SetParametersAsync(Action<ComponentParameterCollectionBuilder<TComponent>>, CancellationToken)

RenderedComponent.cs

Sets parameters of the component (the other parameters keep their values), and waits until the components are idle.

public Task SetParametersAsync(Action<ComponentParameterCollectionBuilder<TComponent>> parameters, CancellationToken cancellationToken = default)

Parameters

parameters Action<ComponentParameterCollectionBuilder<TComponent>>
Sets the parameters.
cancellationToken CancellationToken
A token to cancel the wait.

Returns

Task A task completed once the components are idle.

Exceptions

InvalidOperationException
The component is not a root component.

TakeScreenshotAsPng()

RenderedComponent.cs

Takes a screenshot of the elements rendered by the component, encoded as PNG.

public byte[] TakeScreenshotAsPng()

Returns

byte[] The PNG image.

Exceptions

InvalidOperationException
The component renders no element.