C# Class NUnit.Extensions.Asp.HtmlTagTester

An HTML tag. This class performs some of the magic that allows NUnitAsp to construct testers before pages are loaded and to have testers change as the current page changes.

When using the methods on this class, check the API documentation before caching the results. The API of this class may change in future releases.

Inheritance: ControlTester
Datei anzeigen Open project: vcsjones/NUnitAsp Class Usage Examples

Private Properties

Property Type Description
ChildrenByXPath NUnit.Extensions.Asp.HtmlTagTester[]
HtmlTagTester System
HtmlTagTester System

Public Methods

Method Description
Attribute ( string name ) : string

Returns the value of an attribute on this tag or throws an exception if the attribute isn't present.

AttributeAsIntWithNegOneDefault ( string name ) : int

Returns an attribute as an integer, or -1 if the attribute isn't present. Throws an exception if the attribute isn't an integer.

Child ( string tag ) : HtmlTagTester

Returns the only child (of a particular type) of this tag. If this tag has more that one child of the requested type, or if it has no children of the requested type, this method will throw an exception. Don't cache the results of this call.

Children ( string tag ) : NUnit.Extensions.Asp.HtmlTagTester[]

Returns the immediate children of this tag that match a particular type (such as <tr>). Does not return "grand-children" -- i.e., calling table.Children("tr") will work, but calling table.Children("td") will typically return nothing because the 'td' tags are nested inside 'tr' tags.

Don't cache the results of this call.

ChildrenByXPath ( string xpath ) : NUnit.Extensions.Asp.HtmlTagTester[]

Returns the tags that match an XPath expression, starting from this tag (node). Make sure that the result of your expression is a set of tags.

Don't cache the results of this call.

HasAttribute ( string name ) : bool

Returns true if this tag has the specified attribute.

HasChildren ( string tag ) : bool

Returns 'true' if this tag has any immediate children that match a particular type (such as <tr>. Does not check "grand-children" -- i.e., calling table.HasChildren("tr") will usually return true and calling table.HasChildren("td") will usually return false.

HtmlTagTester ( string htmlId ) : System

Create a tester for an HTML tag. Use this constructor for testing most tags.

HtmlTagTester ( string aspId, Tester container ) : System

Create a tester for a server-side HTML control or a tag that's on a page with multiple forms. Use this constructor when the HTML tag you are testing has the "runat='server'" attribute. Also use this tester when using the non-default webform or HttpClient.

HtmlTagTester ( string xpath, string description ) : System

Create a tester for an HTML tag using an XPath description.

HtmlTagTester ( string xpath, string description, Tester container ) : System

Create a tester for an HTML tag that's on a page with multiple forms using an XPath description.

OptionalAttribute ( string name ) : string

Returns the value of an attribute on this tag or null if the attribute isn't present.

TestInstance ( string htmlPage, string xpath ) : HtmlTagTester

For NUnitAsp's test suite only.

TestInstance ( string htmlPage, string id, string description ) : HtmlTagTester

For NUnitAsp's test suite only.

Private Methods

Method Description
ChildrenByXPath ( string xpath, string description ) : NUnit.Extensions.Asp.HtmlTagTester[]
HtmlTagTester ( ) : System
HtmlTagTester ( XmlElement element, string description ) : System

A static HTML tag constructed for temporary use. It will not reflect the page currently loaded by the browser and shouldn't be cached.

Method Details

Attribute() public method

Returns the value of an attribute on this tag or throws an exception if the attribute isn't present.
public Attribute ( string name ) : string
name string The name of the attribute.
return string

AttributeAsIntWithNegOneDefault() public method

Returns an attribute as an integer, or -1 if the attribute isn't present. Throws an exception if the attribute isn't an integer.
public AttributeAsIntWithNegOneDefault ( string name ) : int
name string
return int

Child() public method

Returns the only child (of a particular type) of this tag. If this tag has more that one child of the requested type, or if it has no children of the requested type, this method will throw an exception. Don't cache the results of this call.
public Child ( string tag ) : HtmlTagTester
tag string The type of tag to look for. Don't include angle brackets.
return HtmlTagTester

Children() public method

Returns the immediate children of this tag that match a particular type (such as <tr>). Does not return "grand-children" -- i.e., calling table.Children("tr") will work, but calling table.Children("td") will typically return nothing because the 'td' tags are nested inside 'tr' tags.

Don't cache the results of this call.

public Children ( string tag ) : NUnit.Extensions.Asp.HtmlTagTester[]
tag string The type of tag to return. Don't include angle brackets.
return NUnit.Extensions.Asp.HtmlTagTester[]

ChildrenByXPath() public method

Returns the tags that match an XPath expression, starting from this tag (node). Make sure that the result of your expression is a set of tags.

Don't cache the results of this call.

public ChildrenByXPath ( string xpath ) : NUnit.Extensions.Asp.HtmlTagTester[]
xpath string The XPath expression to match.
return NUnit.Extensions.Asp.HtmlTagTester[]

HasAttribute() public method

Returns true if this tag has the specified attribute.
public HasAttribute ( string name ) : bool
name string The name of the attribute.
return bool

HasChildren() public method

Returns 'true' if this tag has any immediate children that match a particular type (such as <tr>. Does not check "grand-children" -- i.e., calling table.HasChildren("tr") will usually return true and calling table.HasChildren("td") will usually return false.
public HasChildren ( string tag ) : bool
tag string The type of tag to look for. Don't include angle brackets.
return bool

HtmlTagTester() public method

Create a tester for an HTML tag. Use this constructor for testing most tags.
public HtmlTagTester ( string htmlId ) : System
htmlId string The ID of the control to test (look in the /// page's ASP.NET source code for the ID).
return System

HtmlTagTester() public method

Create a tester for a server-side HTML control or a tag that's on a page with multiple forms. Use this constructor when the HTML tag you are testing has the "runat='server'" attribute. Also use this tester when using the non-default webform or HttpClient.
public HtmlTagTester ( string aspId, Tester container ) : System
aspId string The ID of the control to test (look in the /// page's ASP.NET source code for the ID).
container Tester A tester for the control's container. /// (In the page's ASP.NET source code, look for the tag that the /// control is nested in. That's probably the control's /// container.) If testing a page with multiple forms or a non-default /// HttpClient, pass in the WebFormTester for the form this tag is within.
return System

HtmlTagTester() public method

Create a tester for an HTML tag using an XPath description.
public HtmlTagTester ( string xpath, string description ) : System
xpath string The XPath description of the tag.
description string A human-readable description of this tag (for error reporting).
return System

HtmlTagTester() public method

Create a tester for an HTML tag that's on a page with multiple forms using an XPath description.
public HtmlTagTester ( string xpath, string description, Tester container ) : System
xpath string The XPath description of the tag.
description string A human-readable description of this tag (for error reporting).
container Tester A tester for the control's container. A WebFormTester /// will usually be most appropriate.
return System

OptionalAttribute() public method

Returns the value of an attribute on this tag or null if the attribute isn't present.
public OptionalAttribute ( string name ) : string
name string The name of the attribute.
return string

TestInstance() public static method

For NUnitAsp's test suite only.
public static TestInstance ( string htmlPage, string xpath ) : HtmlTagTester
htmlPage string
xpath string
return HtmlTagTester

TestInstance() public static method

For NUnitAsp's test suite only.
public static TestInstance ( string htmlPage, string id, string description ) : HtmlTagTester
htmlPage string
id string
description string
return HtmlTagTester