Class WebSession
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
BackendName
public string BackendName { get; }
Property Value
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
Name
public string Name { get; }
Property Value
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
triggerFunc<CancellationToken, Task>The action that starts the download.
namestringAn 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.
timeoutTimeSpan?How long the backend waits for the download. When omitted, the backend's own wait timeout applies.
cancellationTokenCancellationTokenCancels the capture.
Returns
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
cancellationTokenCancellationToken
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
conditionFunc<CancellationToken, ValueTask<bool>>Returns whether the awaited condition currently holds.
timeoutTimeSpan?How long to keep polling. Defaults to five seconds.
descriptionstringDefaults to the source text of
condition.cancellationTokenCancellationTokenCancels the wait.