Table of Contents

Interface IBrowser

A tab in an open Web browser.

Namespace: HP.LFT.SDK.Web
Assembly: HP.LFT.SDK.dll
Syntax
public interface IBrowser : ITestObject, IWebDescriber, ITestObjectDescriber, ILocationInfoProvider
Remarks

To open a new browser tab, use: Launch(BrowserType).

To access a browser that is already open, use: Attach(BrowserDescription)

.

Properties

NumberOfTabs

The number of currently open tabs in the browser.

Declaration
uint NumberOfTabs { get; }
Property Value
Type Description
uint

OpenTitle

The browser's initial title when first opened.

Declaration
string OpenTitle { get; }
Property Value
Type Description
string

OpenUrl

The URL from which the browser is opened.

Declaration
string OpenUrl { get; }
Property Value
Type Description
string

Page

A test object representing the top-level document in the tab.

Declaration
IPage Page { get; }
Property Value
Type Description
IPage

Title

The browser title.

Declaration
string Title { get; }
Property Value
Type Description
string

URL

The browser URL.

Declaration
string URL { get; }
Property Value
Type Description
string

Version

Data regarding the browser version and type.

Declaration
BrowserVersion Version { get; }
Property Value
Type Description
BrowserVersion

Methods

Activate(bool)

Activates the tab of the browser in the window group and if the 'setFocus' parameter is true it clicks on it (windows only). If the 'setFocus' parameter is set on an unsupported OS, an error of type 'unexpectedParameterException' is returned.

Declaration
void Activate(bool setFocus = true)
Parameters
Type Name Description
bool setFocus

Decides to click or not the browser after it is activated. Default value: true

Back()

Navigates to the previous page in the browser history list.

Declaration
void Back()
Remarks

This method is identical to clicking the browser's Back button.

ClearCache()

Clears the browser cache.

Declaration
void ClearCache()
Remarks

This method does not clear the browser's cookies. Use DeleteCookies() to delete the cookies.

Close()

Closes the browser window (or tab) that this test object represents.

Declaration
void Close()
Remarks

Use the CloseAllTabs() method to close the currently open tab, all sibling tabs, and the parent browser window.

CloseAllTabs()

Closes all tabs (if any) and closes the browser window.

Declaration
void CloseAllTabs()
Remarks

Use the Close() method to close only the currently open tab.

Limitation: Your Internet Explorer (IE) browser must be configured to "Always close all tabs". To do this, open two or more tabs in IE. Then close IE. In the message box that pops up, select the "Always close all tabs" option.

Note: This method is not supported on Chrome. Use the Close method instead.

DeleteCookies()

Deletes all cookies from the browser.

Declaration
void DeleteCookies()
Remarks

This method does not clear the browser's cache. Use ClearCache() clear the cache.

DeleteCookies(string)

Deletes only cookies that originated from the browser source.

Declaration
void DeleteCookies(string fromSource)
Parameters
Type Name Description
string fromSource

The full or partial domain of the source. For example, entering MySite.com or MySite.net clears cookies only from the specified site, whereas entering MySite clears cookies from all related domains.

Describe<TChild>(IDescription)

Describes a child test object.

Declaration
TChild Describe<TChild>(IDescription description) where TChild : class, ITestObject
Parameters
Type Name Description
IDescription description

The child test object description.

Returns
Type Description
TChild

The requested child test object with its description.

Type Parameters
Name Description
TChild

The child test object type.

Remarks

The current instance test object is the parent of the returned test object. This test object is searched for only when an operation on this test object is invoked. This means that if the test object is not found in the application, this command will still succeed. In this case, an exception is thrown only when an operation is invoked.

Describe<TChild>(CSSDescription)

Describes a child test object using the provided CSS selector.

Declaration
TChild Describe<TChild>(CSSDescription cssSelector) where TChild : class, IWebElement
Parameters
Type Name Description
CSSDescription cssSelector

The CSS selector query used to find the child test object

Returns
Type Description
TChild

The requested child test object with its description

Type Parameters
Name Description
TChild

The child test object type

Remarks

The current instance test object is the parent of the returned test object. This test object is searched for only when an operation on this test object is invoked. This means that if the test object is not found in the application, this command will still succeed. In this case, an exception is thrown only when an operation is invoked.

Describe<TChild>(XPathDescription)

Describes a child test object using the provided XPath.

Declaration
TChild Describe<TChild>(XPathDescription xpath) where TChild : class, IWebElement
Parameters
Type Name Description
XPathDescription xpath

The XPath used to find the child test object.

Returns
Type Description
TChild

The requested child test object with its description.

Type Parameters
Name Description
TChild

The child test object type.

Remarks

The current instance test object is the parent of the returned test object. This test object is searched for only when an operation on this test object is invoked. This means that if the test object is not found in the application, this command will still succeed. In this case, an exception is thrown only when an operation is invoked.

EmbedScript(string)

Runs this JavaScript each time a page or frame loads or refreshes in the browser.

Declaration
void EmbedScript(string script)
Parameters
Type Name Description
string script

The full content of the JavaScript to embed.

Remarks

- The script remains embedded until you close the browser, or until the run session ends.

- Using this method to perform alert operations may result in unexpected behavior.

- To run this method, the security settings in your Web browser must be set to allow active scripting. Otherwise, steps using this method will fail.

Forward()

Navigates to the next page in the browser history list.

Declaration
void Forward()
Remarks

This method is identical to clicking the browser's Forward button.

FullScreen()

Toggles the browser between full-screen mode and normal mode

Declaration
void FullScreen()

FullScreen(FullScreenMode)

Controls the browser's full screen mode.

Declaration
void FullScreen(FullScreenMode mode)
Parameters
Type Name Description
FullScreenMode mode

Indicates whether to set the browser to full screen or normal mode. Possible values: FullScreenMode

GetDialogText()

Returns the text displayed in a browser message box, such as an alert, confirmation, or prompt.

Declaration
string GetDialogText()
Returns
Type Description
string

GetSiblingTabs()

Returns a collection of tabs (Browser objects) that are siblings to the current tab (tabs located in the same window)

Declaration
IBrowser[] GetSiblingTabs()
Returns
Type Description
IBrowser[]

The collection of sibling tabs as Browsers

HandleDialog(DialogButton)

Clicks a button on the alert, confirmation, or prompt message box.

Declaration
void HandleDialog(DialogButton button = DialogButton.Ok)
Parameters
Type Name Description
DialogButton button

The button to click. Default: OK

HandleDialog(string)

Enters text in the browser's prompt message box and clicks the OK button.

Declaration
void HandleDialog(string text)
Parameters
Type Name Description
string text

The text to enter in the edit field.

HasDialog()

Indicates whether the browser message box is currently open.

Declaration
bool HasDialog()
Returns
Type Description
bool

Navigate(string)

Opens the specified URL in the browser.

Declaration
void Navigate(string url)
Parameters
Type Name Description
string url

The URL to open.

OpenNewTab()

Opens a new tab in the browser window.

Declaration
void OpenNewTab()

Refresh()

Refreshes the current page.

Declaration
void Refresh()
Remarks

This method is identical to clicking the browser's Refresh button.

ResizeTo(Size)

Resizes the browser window to a specific size.

Declaration
void ResizeTo(Size size)
Parameters
Type Name Description
Size size

The browser window size in pixels.

ResizeTo(uint, uint)

Resizes the browser window to specific dimensions.

Declaration
void ResizeTo(uint width, uint height)
Parameters
Type Name Description
uint width

The width of the browser window.

uint height

The height of the browser window.

Sync()

Waits for the browser to complete the current navigation.

Declaration
void Sync()
Remarks

You can use this method to instruct your test to wait until the browser is loaded.

Extension Methods

TestObjectExtensions.WaitUntilExists<T>(T)
TestObjectExtensions.WaitUntilExists<T>(T, int)
TestObjectExtensions.WaitUntil<T>(T, Func<T, bool>)
TestObjectExtensions.WaitUntil<T>(T, Func<T, bool>, int)