Class
Browser

Class represents a browser instance managed by the Manager. This object exposes all the browser specific information and methods to automate the underlying browser that this instance represents.

Definition

Namespace:ArtOfTest.WebAii.Core

Assembly:ArtOfTest.WebAii.dll

Syntax:

cs-api-definition
public class Browser : IAutomationHost, ISupportSearchHost, IAnnotationHost

Inheritance: objectBrowser

Derived Classes: AspNetHostBrowser

Implements: IAnnotationHostIAutomationHostISupportSearchHost

Properties

Actions

Gets the Actions object that can be used to perform different actions against the loaded document in the browser.

Declaration

cs-api-definition
public Actions Actions { get; }

Property Value

Actions

Annotator

Gets the Annotator object associated with this browser.

Declaration

cs-api-definition
public Annotator Annotator { get; }

Property Value

Annotator

Implements IAnnotationHost.Annotator

AutoDomRefresh

Gets/Sets whether to automatically refresh the DOM tree after each browser command.

Declaration

cs-api-definition
public bool AutoDomRefresh { get; set; }

Property Value

bool

AutoWaitUntilReady

Gets/Sets whether to automatically wait until browser is ready after each browser command.

Declaration

cs-api-definition
public bool AutoWaitUntilReady { get; set; }

Property Value

bool

BrowserType

Gets the browser type (i.e. IE/FireFox ...etc)

Declaration

cs-api-definition
public BrowserType BrowserType { get; }

Property Value

BrowserType

ClientId

The unique ID for this browser that the manager identifies it with.

Declaration

cs-api-definition
public string ClientId { get; }

Property Value

string

CommandTimeOut

Gets/Sets the max wait time in milliseconds that the browser will wait for a command to process before it times out.

Declaration

cs-api-definition
public int CommandTimeOut { get; set; }

Property Value

int

ContentRectangle

Gets the rectangle of the content window or element

Declaration

cs-api-definition
public virtual Rectangle ContentRectangle { get; }

Property Value

Rectangle

ContentWindow

Gets the container window of the browser that contains the actual content of the page. (Excludes the browser toolbars, buttons ...etc.)

Declaration

cs-api-definition
public virtual Window ContentWindow { get; }

Property Value

Window

Implements IAnnotationHost.ContentWindow

Remarks

For Firefox 4, the ContentWindow returns the same Window as the Window property. Firefox 4 does not have separate Win32 windows for its chrome and its content.

Cookies

Gets the cookies manager associated with this browser that allows you to retrieve, delete and add cookies.

Declaration

cs-api-definition
public CookiesManager Cookies { get; }

Property Value

CookiesManager

CreationTime

The UTC time this instance was instantiated.

Declaration

cs-api-definition
public DateTime CreationTime { get; }

Property Value

DateTime

Desktop

Desktop object that draws its annotations in this browser

Declaration

cs-api-definition
public Desktop Desktop { get; }

Property Value

Desktop

DomTree

Gets the DOM Tree representation of the currently loaded document.

Declaration

cs-api-definition
public HtmlTreeBuilder DomTree { get; }

Property Value

HtmlTreeBuilder

Find

Gets the Find objects used to provide a rich set of methods to help identify elements in the Dom tree associated with this browser object.

Declaration

cs-api-definition
public Find Find { get; }

Property Value

Find

FrameElement

Gets the Element object for the frame element represented by this Browser object, if this Browser represents a frame. If this Browser does not represent a frame, FrameElement is null.

Declaration

cs-api-definition
public Element FrameElement { get; }

Property Value

Element

FrameInfo

Gets the frame information if IsFrame = true else will return null. FrameInfo contains frame index and frame name.

Declaration

cs-api-definition
public FrameInfo FrameInfo { get; }

Property Value

FrameInfo

Frames

List of child frames contained in this instance

Declaration

cs-api-definition
public virtual FramesCollection Frames { get; }

Property Value

FramesCollection

FriendlyName

Get a friendly name for this browser instance.

Declaration

cs-api-definition
public string FriendlyName { get; }

Property Value

string

A string representing the friendly name for this browser. Used for display in Elements Explorer.

Implements IAutomationHost.FriendlyName

IsConnected

Gets whether the browser is connected to manager of not.

Declaration

cs-api-definition
public virtual bool IsConnected { get; }

Property Value

bool

Remarks

This property performs a two way communication check between the manager and the actual browser.

IsFrame

Gets whether this instance represents a frame or not.

Declaration

cs-api-definition
public bool IsFrame { get; }

Property Value

bool

IsIEDialog

Gets whether this instance is an IE dialog (Modal/Modeless)

Declaration

cs-api-definition
public bool IsIEDialog { get; }

Property Value

bool

IsUILess

Whether this browser is UI less browser. (i.e. a raw http request/response browser)

Declaration

cs-api-definition
public bool IsUILess { get; }

Property Value

bool

Manager

The manager of this browser object.

Declaration

cs-api-definition
public Manager Manager { get; }

Property Value

Manager

Implements IAnnotationHost.Manager

NativeInstance

The native instance of this browser object (if available), otherwise null

Declaration

cs-api-definition
public virtual object NativeInstance { get; }

Property Value

object

PageTitle

Gets the page title if one exists. (text content of the 'title' tags)

Declaration

cs-api-definition
public string PageTitle { get; }

Property Value

string

QueryString

Gets a parsed name/value collection of the query string.

Declaration

cs-api-definition
public NameValueCollection QueryString { get; }

Property Value

NameValueCollection

Regions

Gets a dictionary of all identified test regions in the currently loaded document.

Declaration

cs-api-definition
public TestRegionCollection Regions { get; }

Property Value

TestRegionCollection

StateHashCode

Get the state hash code.

Declaration

cs-api-definition
public string StateHashCode { get; }

Property Value

string

Implements IAutomationHost.StateHashCode

TechnologyType

Get the technology type

Declaration

cs-api-definition
public TechnologyType TechnologyType { get; }

Property Value

TechnologyType

Implements IAutomationHost.TechnologyType

UniqueId

Gets a unique id that identifies this browser instance.

Declaration

cs-api-definition
public string UniqueId { get; }

Property Value

string

Implements IAutomationHost.UniqueId

Url

Gets the current page URL. This property is refreshed when calling RefreshDOMTree().

Declaration

cs-api-definition
public virtual string Url { get; }

Property Value

string

Version

The browser version for this browser type.

Declaration

cs-api-definition
public string Version { get; }

Property Value

string

ViewSourceString

Gets the source of the page currently loaded in the browser. This is the string that the framework used to build the DOM.

Declaration

cs-api-definition
public string ViewSourceString { get; }

Property Value

string

Window

Gets the Win32 window object representing the actual browser window.

Declaration

cs-api-definition
public virtual Window Window { get; }

Property Value

Window

Implements IAnnotationHost.Window

Methods

Capture()

Capture the image of this browser

Declaration

cs-api-definition
public Bitmap Capture()

Returns

Bitmap

Implements IAutomationHost.Capture()

ClearCache(BrowserCacheType)

Clear the cache of a certain category.

Declaration

cs-api-definition
public void ClearCache(BrowserCacheType cacheType)

Parameters

cacheType

BrowserCacheType

The cache category

Close()

Closes a browser window.

Declaration

cs-api-definition
public virtual void Close()

Close(int)

Closes a browser window with a custom wait to close timeout.

Declaration

cs-api-definition
public virtual void Close(int waitToCloseTimeout)

Parameters

waitToCloseTimeout

int

The timeout in milliseconds to wait for the browser to close.

Remarks

This function will disconnect the browser from the manager first and then close its window. It will also perform a wait until the browser window is no longer visible. The time out for the wait is the same as the ExecuteCommandTimeout.

ContainsPoint(Point)

True/False whether a specific point falls within this browser/frame rendering region

Declaration

cs-api-definition
public virtual bool ContainsPoint(Point point)

Parameters

point

Point

The point to check.

Returns

bool

True/False whether the point is within the browser window.

ContainsRectangle(Rectangle)

True/False whether a specific rectangle falls within this browser/frame rendering region

Declaration

cs-api-definition
public virtual bool ContainsRectangle(Rectangle rectangle)

Parameters

rectangle

Rectangle

The rectangle to check.

Returns

bool

True/False whether the rectangle is within the browser window.

ContainsText(string)

True/False whether the 'text' is contained within the page currently loaded. Not case sensitive.

Declaration

cs-api-definition
public virtual bool ContainsText(string text)

Parameters

text

string

The text string.

Returns

bool

True/False whether the text is contained.

ExecuteCommand(BrowserCommand)

Executes a command against this browser instance.

Declaration

cs-api-definition
public virtual BrowserCommand ExecuteCommand(BrowserCommand request)

Parameters

request

BrowserCommand

Returns

BrowserCommand

Remarks

If the request requires a specific response data, then the callers of this function should check the BrowserCommand.Response property for any responses from the browser. This method uses the browser's AutoDOMRefresh and AutoWaitUntilReady values to configure whether the browser should refresh the DOM or wait until the browser is ready after the command is executed.

ExecuteCommand(BrowserCommand, bool, bool)

Executes a command against this browser instance.

Declaration

cs-api-definition
public virtual BrowserCommand ExecuteCommand(BrowserCommand request, bool performDomRefresh, bool waitUntilReady)

Parameters

request

BrowserCommand

The command request to perform.

performDomRefresh

bool

True/False whether to refresh the DOM after the command.

waitUntilReady

bool

True/False whether to wait for the browser to be ready after the command.

Returns

BrowserCommand

A response to the request.

Remarks

If the request requires a specific response data, then the callers of this function should check the BrowserCommand.Response property for any responses from the browser.

GetChildHosts()

Get all containing child hosts. For Browser, this will return a list of all Frames (if any, excluding for Chrome, Firefox and EdgeChromium)

Declaration

cs-api-definition
public IAutomationHost[] GetChildHosts()

Returns

IAutomationHost[]

The list of automation hosts contained in this browser instance

Implements IAutomationHost.GetChildHosts()

GetHostRoot()

Get the root element of the DomTree

Declaration

cs-api-definition
public ITargetElement GetHostRoot()

Returns

ITargetElement

The root element of the DOM tree.

Implements IAutomationHost.GetHostRoot()

GetSelectedText()

Gets the text currently selected by the user in the browser window

Declaration

cs-api-definition
public virtual string GetSelectedText()

Returns

string

The selected text

GoBack()

Simulates a go back browser action.

Declaration

cs-api-definition
public virtual void GoBack()

GoForward()

Simulates a go forward browser action.

Declaration

cs-api-definition
public virtual void GoForward()

IsReady()

Gets whether the browser is ready or not.

Declaration

cs-api-definition
public virtual bool IsReady()

Returns

bool

LocateAllInHost(string[])

Locates all elements contained in the browser's DOM matching the specified find expression.

Declaration

cs-api-definition
public IList<ITargetElement> LocateAllInHost(string[] expression)

Parameters

expression

string[]

Array of find expressions to use to locate the elements.

Returns

IList<ITargetElement>

A list of elements matching the find expression.

Implements ISupportSearchHost.LocateAllInHost(string[])

LocateInHost(string[])

Locate an element in the host using an expression.

Declaration

cs-api-definition
public ITargetElement LocateInHost(string[] expression)

Parameters

expression

string[]

Array of find expressions to use to locate the target element.

Returns

ITargetElement

The target element if found. 'null' if not found.

Implements ISupportSearchHost.LocateInHost(string[])

NavigateTo(Uri, bool)

Navigate the browser to a specific url.

Declaration

cs-api-definition
public virtual void NavigateTo(Uri uri, bool useDecodedUrl = true)

Parameters

uri

Uri

The uri object that describes the Url.

useDecodedUrl

bool

Decode the url before navigate to it

NavigateTo(string, bool)

Navigate the browser to a specific url and then enable the script logging.

Declaration

cs-api-definition
public virtual void NavigateTo(string url, bool useDecodedUrl = true)

Parameters

url

string

The url to navigate to.

useDecodedUrl

bool

Decode the url before navigate to it

PrepareFrameForClosing()

Used to disable the AutoRefreshDom and WaitUntilReady of a frame preparing it to be closed on next action and no longer pulled by the framework.

Declaration

cs-api-definition
public virtual void PrepareFrameForClosing()

Refresh()

Simulates a browser Refresh.

Declaration

cs-api-definition
public virtual void Refresh()

RefreshDomTree()

Force a refresh of the DOM tree from the current document.

Declaration

cs-api-definition
public virtual bool RefreshDomTree()

Returns

bool

ResizeContent(Rectangle)

Resize the browser window content to the specified window rectangle. This function will handle the padding between the outer browser window and the content window. If the new rectangle will not fit within the bounds of the screen, this method will try to approximate the requested size within the bounds of the screen.

Declaration

cs-api-definition
public virtual void ResizeContent(Rectangle rectangle)

Parameters

rectangle

Rectangle

The desired rectangle for the content window

ResizeContent(int, int, int, int)

Resize the browser window content to the specified window rectangle. This function will handle the padding between the outer browser window and the content window.

Declaration

cs-api-definition
public virtual void ResizeContent(int x, int y, int width, int height)

Parameters

x

int

Desired x

y

int

Desired y

width

int

Desired width

height

int

Desired height

ScrollBy(int, int)

Scroll this window by offset x horizontally and y vertically.

Declaration

cs-api-definition
public virtual void ScrollBy(int x, int y)

Parameters

x

int

The x offset.(negative for scroll left)

y

int

The y offset.(negative for scroll up)

Stop()

Simulate a stop navigation browser action.

Declaration

cs-api-definition
public virtual void Stop()

ToggleFullScreen()

Toggle the browser in and out of Full Screen (F11)

Declaration

cs-api-definition
public virtual void ToggleFullScreen()

TranslateBrowserOffset(BrowserType, BrowserType, Point)

Translates an offset from one browser to another. Useful because offset values recorded in Internet Explorer are typically two pixels different from offset values for the same relative point in other browsers.

Declaration

cs-api-definition
public static Point TranslateBrowserOffset(BrowserType sourceBrowser, BrowserType destinationBrowser, Point sourceOffset)

Parameters

sourceBrowser

BrowserType

The BrowserType the offset was originally intended for

destinationBrowser

BrowserType

The BrowserType to translate the offset to

sourceOffset

Point

The original offset value

Returns

Point

A translated offset value. The offset is translated two pixels left and up when translating from Internet Explorer to any other browser, and translated two pixels down and right when translating from any other browser to Internet Explorer.

UpdateDomTree(string)

Parse and update the DomTree

Declaration

cs-api-definition
protected virtual bool UpdateDomTree(string domString)

Parameters

domString

string

Returns

bool

Ensures that any links between hosts are up-to-date (Infrastructure use only)

Declaration

cs-api-definition
public void UpdateInterHostLinks()

Implements IAutomationHost.UpdateInterHostLinks()

WaitForAjax(int)

Wait for any active AJAX requests to complete.

Declaration

cs-api-definition
public void WaitForAjax(int timeout)

Parameters

timeout

int

WaitForElement(HtmlFindExpression, int, bool)

Wait for an element to exist. If it exists, return the Element object, else will throw a Timeout Exception.

Declaration

cs-api-definition
public Element WaitForElement(HtmlFindExpression expression, int timeout, bool invertCondition)

Parameters

expression

HtmlFindExpression

The HtmlFindExpression

timeout

int

The timeout to use. (msec)

invertCondition

bool

Set to true to wait for element to not exist.

Returns

Element

The fully initialized found Element.

Remarks

This method replaces the Actions.WaitForElement() and supports HtmlFindExpressions

WaitForElement(int, params string[])

Wait for an element to exist. If it exists, return the Element object, else will throw a Timeout Exception.

Declaration

cs-api-definition
public Element WaitForElement(int timeout, params string[] findClauses)

Parameters

timeout

int

The timeout to use (msec)

findClauses

string[]

The Find Expression clauses

Returns

Element

The fully initialized found Element.

Remarks

This method replaces the Actions.WaitForElement() and supports HtmlFindExpressions

WaitForFrame(FrameInfo)

Wait for a frame to exist. Uses the Settings.ClientReadyTimeout as the timeout

Declaration

cs-api-definition
public Browser WaitForFrame(FrameInfo frameInfo)

Parameters

frameInfo

FrameInfo

The FrameInfo structure containing the frame details (id or name or src). Index is not needed.

Returns

Browser

The Browser object representing the frame, else will throw an exception.

WaitForFrame(FrameInfo, int)

Wait for a frame to exist.

Declaration

cs-api-definition
public Browser WaitForFrame(FrameInfo frameInfo, int timeout)

Parameters

frameInfo

FrameInfo

The FrameInfo structure containing the frame details (id or name or src). Index is not needed.

timeout

int

The timeout to use for the wait.

Returns

Browser

The Browser object representing the frame, else will throw an exception.

WaitForUrl(string, bool, int)

Wait for a specific url to be set. This can be used to wait for browser redirects on certain sites.

Declaration

cs-api-definition
public virtual void WaitForUrl(string url, bool isPartial, int timeout)

Parameters

url

string

The url to wait for.

isPartial

bool

True/False whether to use partial comparison.

timeout

int

The timeout in milli-seconds to use.

WaitUntilReady()

Waits for the browser until its ready

Declaration

cs-api-definition
public virtual void WaitUntilReady()

Remarks

This method uses the Manager.Settings.ClientReadyTimeout as the timeout.

Events

AfterCommandExecuted

Event occurs after the command is executed and the response is available.

Declaration

cs-api-definition
public event EventHandler<BrowserCommandEventArgs> AfterCommandExecuted

Event Value

EventHandler<BrowserCommandEventArgs>

BeforeCommandExecuted

Event occurs before a command is pushed to the browser.

Declaration

cs-api-definition
public event EventHandler<BrowserCommandEventArgs> BeforeCommandExecuted

Event Value

EventHandler<BrowserCommandEventArgs>

Closing

Event occurs when the browser is about to close. [Browser.Close()] is called.

Declaration

cs-api-definition
public event EventHandler Closing

Event Value

EventHandler

DomRefreshed

Event occurs after the DomTree is rebuilt (either after a command is executed or when RefreshDom is called)

Declaration

cs-api-definition
public event EventHandler DomRefreshed

Event Value

EventHandler

Extension Methods