Browser
Namespace: E2E
public sealed class BrowserThe browser the attempt drives, showing one active tab. It needs an engine
session that implements IBrowserSession, such as
WebEngine; on any other engine each member fails with
UNSUPPORTED_CAPABILITY.
Inheritance: object
Properties
Section titled “Properties”Keyboard
Section titled “Keyboard”public BrowserKeyboard Keyboard { get; }Viewport-level keyboard, for whatever has focus.
Value: BrowserKeyboard
public BrowserMouse Mouse { get; }Direct pointer input from test code, independent of agent observations.
Value: BrowserMouse
Methods
Section titled “Methods”AddInitScriptAsync(WebInitScript, object?, CancellationToken)
Section titled “AddInitScriptAsync(WebInitScript, object?, CancellationToken)”public Task AddInitScriptAsync(WebInitScript script, object? arg, CancellationToken cancellationToken = default)Adds an init script function (FromFunction(string)) the page calls with one JSON-safe argument. Only a function takes an argument.
Parameters
| Name | Type | Description |
|---|---|---|
script |
WebInitScript | |
arg |
object | |
cancellationToken |
CancellationToken |
Returns: Task
AddInitScriptAsync(WebInitScript, CancellationToken)
Section titled “AddInitScriptAsync(WebInitScript, CancellationToken)”public Task AddInitScriptAsync(WebInitScript script, CancellationToken cancellationToken = default)Adds an init script: source, a file of it (FromPath(string)), or a function the page calls with no argument (FromFunction(string)).
Parameters
| Name | Type | Description |
|---|---|---|
script |
WebInitScript | |
cancellationToken |
CancellationToken |
Returns: Task
AddInitScriptAsync(string, CancellationToken)
Section titled “AddInitScriptAsync(string, CancellationToken)”public Task AddInitScriptAsync(string script, CancellationToken cancellationToken = default)Adds JavaScript source every document runs before the page’s own, in every tab and frame, from the next navigation on, for the rest of the attempt.
Parameters
| Name | Type | Description |
|---|---|---|
script |
string | |
cancellationToken |
CancellationToken |
Returns: Task
BackAsync(CancellationToken)
Section titled “BackAsync(CancellationToken)”public Task BackAsync(CancellationToken cancellationToken = default)Navigates the history back once.
Parameters
| Name | Type | Description |
|---|---|---|
cancellationToken |
CancellationToken |
Returns: Task
CookiesAsync(CancellationToken)
Section titled “CookiesAsync(CancellationToken)”public Task<IReadOnlyList<BrowserCookie>> CookiesAsync(CancellationToken cancellationToken = default)Returns the cookies visible to the browser context.
Parameters
| Name | Type | Description |
|---|---|---|
cancellationToken |
CancellationToken |
Returns: Task<IReadOnlyList<BrowserCookie>>
EmulateMediaAsync(WebMedia, CancellationToken)
Section titled “EmulateMediaAsync(WebMedia, CancellationToken)”public Task EmulateMediaAsync(WebMedia media, CancellationToken cancellationToken = default)Emulates CSS media features on every open tab and every tab opened after them, the app’s own included,
for the rest of the attempt, through App.RestartAsync and App.ClearStateAsync: the page’s
@media rules and matchMedia both read them. A feature left out keeps its value. It works
before the first navigation, so the page loads with them.
Parameters
| Name | Type | Description |
|---|---|---|
media |
WebMedia | |
cancellationToken |
CancellationToken |
Returns: Task
EvaluateAsync<T>(string, object?, CancellationToken)
Section titled “EvaluateAsync<T>(string, object?, CancellationToken)”public Task<T?> EvaluateAsync<T>(string expression, object? arg, CancellationToken cancellationToken = default)Evaluates a function source in the page with one JSON-safe argument.
Type parameters
| Name | Description |
|---|---|
T |
Parameters
| Name | Type | Description |
|---|---|---|
expression |
string | |
arg |
object | |
cancellationToken |
CancellationToken |
Returns: Task<T>
EvaluateAsync<T>(string, CancellationToken)
Section titled “EvaluateAsync<T>(string, CancellationToken)”public Task<T?> EvaluateAsync<T>(string expression, CancellationToken cancellationToken = default)Evaluates trusted test code in the page: an expression, or a function
source that is called. The result must be JSON-safe and is deserialized to
<code class=“typeparamref”>T</code>. A throwing script fails with EVALUATE_FAILED, and a
script that does not finish within the action timeout with OPERATION_TIMEOUT.
Type parameters
| Name | Description |
|---|---|
T |
Parameters
| Name | Type | Description |
|---|---|---|
expression |
string | |
cancellationToken |
CancellationToken |
Returns: Task<T>
ForwardAsync(CancellationToken)
Section titled “ForwardAsync(CancellationToken)”public Task ForwardAsync(CancellationToken cancellationToken = default)Navigates the history forward once.
Parameters
| Name | Type | Description |
|---|---|---|
cancellationToken |
CancellationToken |
Returns: Task
FrameLocator(string)
Section titled “FrameLocator(string)”public FrameScreen FrameLocator(string selector)Creates a screen query scope inside one iframe: every Screen query answers from inside the frame. The frame is the
one element <code class=“paramref”>selector</code> names; none yet is polled for by an action, and answers no match to a read. Upstream’s
browser.frameLocator.
Parameters
| Name | Type | Description |
|---|---|---|
selector |
string |
Returns: FrameScreen
Exceptions
| Type | Condition |
|---|---|
| TestException | INVALID_LOCATOR: <code class=“paramref”>selector</code> is empty. |
GotoAsync(string, GotoOptions?, CancellationToken)
Section titled “GotoAsync(string, GotoOptions?, CancellationToken)”public Task GotoAsync(string url, GotoOptions? options = null, CancellationToken cancellationToken = default)Navigates to <code class=“paramref”>url</code>, resolved against the base URL like App.OpenAsync,
and waits for WaitUntil within Timeout.
Parameters
| Name | Type | Description |
|---|---|---|
url |
string | |
options |
GotoOptions | |
cancellationToken |
CancellationToken |
Returns: Task
Locator(string)
Section titled “Locator(string)”public Locator Locator(string selector)Creates a web-only locator from a CSS or XPath selector, for a control with no accessible name. Same polling and strictness as any
locator. A selector that captures with * before its last part (*css=article >> text=Hello) is refused with
INVALID_LOCATOR when the locator resolves: narrow with Filter(Locator) instead. Upstream’s browser.locator.
Parameters
| Name | Type | Description |
|---|---|---|
selector |
string |
Returns: Locator
Exceptions
| Type | Condition |
|---|---|
| TestException | INVALID_LOCATOR: <code class=“paramref”>selector</code> is empty. |
OnDialogAsync(DialogHandler, CancellationToken)
Section titled “OnDialogAsync(DialogHandler, CancellationToken)”public Task<Func<Task>> OnDialogAsync(DialogHandler handler, CancellationToken cancellationToken = default)Registers a handler for native dialogs, of every tab, for the rest of the attempt, and returns its unsubscribe. The newest registration answers. A dialog with no handler fails the next step and is dismissed; a handler that returns without calling AcceptAsync(string) or DismissAsync(), or throws, fails the next step with that error, and its dialog is dismissed. Pass Accept or Dismiss to answer them all alike.
Parameters
| Name | Type | Description |
|---|---|---|
handler |
DialogHandler | |
cancellationToken |
CancellationToken |
Returns: Task<Func<Task>>
OnDialogAsync(Func<Dialog, Task>, CancellationToken)
Section titled “OnDialogAsync(Func<Dialog, Task>, CancellationToken)”public Task<Func<Task>> OnDialogAsync(Func<Dialog, Task> handler, CancellationToken cancellationToken = default)Registers a handler that runs <code class=“paramref”>handler</code> for each dialog. See CancellationToken).
Parameters
| Name | Type | Description |
|---|---|---|
handler |
Func<Dialog, Task> | |
cancellationToken |
CancellationToken |
Returns: Task<Func<Task>>
ReloadAsync(CancellationToken)
Section titled “ReloadAsync(CancellationToken)”public Task ReloadAsync(CancellationToken cancellationToken = default)Reloads the current document.
Parameters
| Name | Type | Description |
|---|---|---|
cancellationToken |
CancellationToken |
Returns: Task
RouteAsync(string, Func<WebRoute, Task>, CancellationToken)
Section titled “RouteAsync(string, Func<WebRoute, Task>, CancellationToken)”public Task RouteAsync(string pattern, Func<WebRoute, Task> handler, CancellationToken cancellationToken = default)Adds a network route for the rest of the attempt, matching a complete URL with
the glob <code class=“paramref”>pattern</code> that CancellationToken)
takes. The route registered last runs first. <code class=“paramref”>handler</code> must take
exactly one decision on the WebRoute. A handler that takes none,
takes two, or throws fails the next step with that error, and an undecided
request is aborted.
Parameters
| Name | Type | Description |
|---|---|---|
pattern |
string | |
handler |
Func<WebRoute, Task> | |
cancellationToken |
CancellationToken |
Returns: Task
RouteAsync(Regex, Func<WebRoute, Task>, CancellationToken)
Section titled “RouteAsync(Regex, Func<WebRoute, Task>, CancellationToken)”public Task RouteAsync(Regex pattern, Func<WebRoute, Task> handler, CancellationToken cancellationToken = default)Adds a network route for the URLs <code class=“paramref”>pattern</code> matches. See CancellationToken).
Parameters
| Name | Type | Description |
|---|---|---|
pattern |
Regex | |
handler |
Func<WebRoute, Task> | |
cancellationToken |
CancellationToken |
Returns: Task
SetCookiesAsync(IReadOnlyList<BrowserCookie>, CancellationToken)
Section titled “SetCookiesAsync(IReadOnlyList<BrowserCookie>, CancellationToken)”public Task SetCookiesAsync(IReadOnlyList<BrowserCookie> cookies, CancellationToken cancellationToken = default)Sets cookies. Each target URL, or the origin a domain cookie is sent to, must pass the URL rule. A relative url resolves against the base URL.
A cookie URL that does not parse, or uses a scheme other than http: or https: (about:blank included),
is POLICY_DENIED.
Parameters
| Name | Type | Description |
|---|---|---|
cookies |
IReadOnlyList<BrowserCookie> | |
cancellationToken |
CancellationToken |
Returns: Task
SetViewportAsync(int, int, CancellationToken)
Section titled “SetViewportAsync(int, int, CancellationToken)”public Task SetViewportAsync(int width, int height, CancellationToken cancellationToken = default)Sets the viewport size for the rest of the attempt.
Parameters
| Name | Type | Description |
|---|---|---|
width |
int | |
height |
int | |
cancellationToken |
CancellationToken |
Returns: Task
TitleAsync(CancellationToken)
Section titled “TitleAsync(CancellationToken)”public Task<string> TitleAsync(CancellationToken cancellationToken = default)Returns the current title. A page that does not answer within the action timeout fails with OPERATION_TIMEOUT.
Parameters
| Name | Type | Description |
|---|---|---|
cancellationToken |
CancellationToken |
Returns: Task<string>
UnrouteAllAsync(CancellationToken)
Section titled “UnrouteAllAsync(CancellationToken)”public Task UnrouteAllAsync(CancellationToken cancellationToken = default)Removes every route added through this browser. The configured site headers stay.
Parameters
| Name | Type | Description |
|---|---|---|
cancellationToken |
CancellationToken |
Returns: Task
UnrouteAsync(string, CancellationToken)
Section titled “UnrouteAsync(string, CancellationToken)”public Task UnrouteAsync(string pattern, CancellationToken cancellationToken = default)Removes every route added with the same glob.
Parameters
| Name | Type | Description |
|---|---|---|
pattern |
string | |
cancellationToken |
CancellationToken |
Returns: Task
UnrouteAsync(Regex, CancellationToken)
Section titled “UnrouteAsync(Regex, CancellationToken)”public Task UnrouteAsync(Regex pattern, CancellationToken cancellationToken = default)Removes every route added with a regex of the same source and options.
Parameters
| Name | Type | Description |
|---|---|---|
pattern |
Regex | |
cancellationToken |
CancellationToken |
Returns: Task
UrlAsync(CancellationToken)
Section titled “UrlAsync(CancellationToken)”public Task<string> UrlAsync(CancellationToken cancellationToken = default)Returns the current URL.
Parameters
| Name | Type | Description |
|---|---|---|
cancellationToken |
CancellationToken |
Returns: Task<string>
WaitForDownloadAsync(Func<Task>, TimeSpan?, CancellationToken)
Section titled “WaitForDownloadAsync(Func<Task>, TimeSpan?, CancellationToken)”public Task<BrowserDownload> WaitForDownloadAsync(Func<Task> trigger, TimeSpan? timeout = null, CancellationToken cancellationToken = default)Runs <code class=“paramref”>trigger</code> and waits for the download it starts, within <code class=“paramref”>timeout</code> (the action timeout by
default). The file is kept under the attempt’s downloads artifact folder, as an artifact of this step. A trigger that
throws fails the call with its own error, and one that starts no download fails with ACTION_FAILED, naming the wait and
how long the trigger took.
Parameters
| Name | Type | Description |
|---|---|---|
trigger |
Func<Task> | |
timeout |
TimeSpan? | |
cancellationToken |
CancellationToken |
Returns: Task<BrowserDownload>
WaitForResponseAsync(string, TimeSpan?, CancellationToken)
Section titled “WaitForResponseAsync(string, TimeSpan?, CancellationToken)”public Task<WebResponse> WaitForResponseAsync(string pattern, TimeSpan? timeout = null, CancellationToken cancellationToken = default)Waits for a response whose complete URL matches the glob <code class=“paramref”>pattern</code>:
* matches within one path segment, ** crosses /, ?
matches one character, and \ escapes the next one. The timeout bounds
the match only, and defaults to the action timeout.
Parameters
| Name | Type | Description |
|---|---|---|
pattern |
string | |
timeout |
TimeSpan? | |
cancellationToken |
CancellationToken |
Returns: Task<WebResponse>
WaitForResponseAsync(Regex, TimeSpan?, CancellationToken)
Section titled “WaitForResponseAsync(Regex, TimeSpan?, CancellationToken)”public Task<WebResponse> WaitForResponseAsync(Regex pattern, TimeSpan? timeout = null, CancellationToken cancellationToken = default)Waits for a response whose URL matches <code class=“paramref”>pattern</code>. The timeout bounds the match only, and defaults to the action timeout.
Parameters
| Name | Type | Description |
|---|---|---|
pattern |
Regex | |
timeout |
TimeSpan? | |
cancellationToken |
CancellationToken |
Returns: Task<WebResponse>
WaitForURLAsync(string, TimeSpan?, CancellationToken)
Section titled “WaitForURLAsync(string, TimeSpan?, CancellationToken)”public Task WaitForURLAsync(string url, TimeSpan? timeout = null, CancellationToken cancellationToken = default)Waits until the current URL equals <code class=“paramref”>url</code>, resolved
against the base URL, as CancellationToken).
The default timeout is the assertion timeout.
Parameters
| Name | Type | Description |
|---|---|---|
url |
string | |
timeout |
TimeSpan? | |
cancellationToken |
CancellationToken |
Returns: Task
WaitForURLAsync(Regex, TimeSpan?, CancellationToken)
Section titled “WaitForURLAsync(Regex, TimeSpan?, CancellationToken)”public Task WaitForURLAsync(Regex pattern, TimeSpan? timeout = null, CancellationToken cancellationToken = default)Waits until the current URL matches <code class=“paramref”>pattern</code>. The default timeout is the assertion timeout.
Parameters
| Name | Type | Description |
|---|---|---|
pattern |
Regex | |
timeout |
TimeSpan? | |
cancellationToken |
CancellationToken |
Returns: Task