Class WebSession

Namespace
ProtoTest.Web
Assembly
ProtoTest.Web.dll

Test-scoped entry point for pages, operations, and explicit native backend access.

public sealed class WebSession : IAsyncDisposable
Inheritance
WebSession
Implements
Inherited Members
Extension Methods

Properties

Application

Gets the application this session targets, from ProtoTest:Web:Sessions:{name}:Application and defaulting to the session name.

public string Application { get; }

Property Value

string

BackendName

public string BackendName { get; }

Property Value

string

BaseUrl

Gets the origin for relative navigation, read from the application's ProtoTest:Applications:{application}:BaseUrl — the same section REST and GraphQL clients target, so a browser session and an HTTP client can share one application address.

public Uri? BaseUrl { get; }

Property Value

Uri

Name

public string Name { get; }

Property Value

string

Methods

DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

public ValueTask DisposeAsync()

Returns

ValueTask

A task that represents the asynchronous dispose operation.

DownloadAsync(Func<CancellationToken, Task>, string?, TimeSpan?, CancellationToken)

Runs trigger — typically a click that starts a download — and captures the file the browser downloads. The file is returned and registered as a test attachment; a backend without the download capability throws WebBackendCapabilityException before the trigger runs.

public ValueTask<WebDownload> DownloadAsync(Func<CancellationToken, Task> trigger, string? name = null, TimeSpan? timeout = null, CancellationToken cancellationToken = default)

Parameters

trigger Func<CancellationToken, Task>

The action that starts the download.

name string

An explicit file name for the capture. Defaults to the browser's suggested file name; an extension in the explicit name refines the media type guess.

timeout TimeSpan?

How long the backend waits for the download. When omitted, the backend's own wait timeout applies.

cancellationToken CancellationToken

Cancels the capture.

Returns

ValueTask<WebDownload>

GetBackendAsync<TBackend>(CancellationToken)

Initializes the named session when necessary and returns its native backend.

public ValueTask<TBackend> GetBackendAsync<TBackend>(CancellationToken cancellationToken = default) where TBackend : class, IWebBackend

Parameters

cancellationToken CancellationToken

Returns

ValueTask<TBackend>

Type Parameters

TBackend

GetBackend<TBackend>()

Explicit escape hatch. Referencing an adapter type makes backend coupling visible.

public TBackend GetBackend<TBackend>() where TBackend : class, IWebBackend

Returns

TBackend

Type Parameters

TBackend

Page<TPage>()

Returns the page for this session, creating it on first use and reusing it afterwards.

public TPage Page<TPage>() where TPage : WebPage, new()

Returns

TPage

Type Parameters

TPage

WaitUntilAsync(Func<CancellationToken, ValueTask<bool>>, TimeSpan?, string?, CancellationToken)

Polls condition until it holds or timeout elapses. Use it to wait on one session for a change another session produced, or for any condition that is not a single element assertion.

public ValueTask WaitUntilAsync(Func<CancellationToken, ValueTask<bool>> condition, TimeSpan? timeout = null, string? description = null, CancellationToken cancellationToken = default)

Parameters

condition Func<CancellationToken, ValueTask<bool>>

Returns whether the awaited condition currently holds.

timeout TimeSpan?

How long to keep polling. Defaults to five seconds.

description string

Defaults to the source text of condition.

cancellationToken CancellationToken

Cancels the wait.

Returns

ValueTask