Retrofitting Existing Code

The HTML element wrapper control suite was first introduced with RC0. If you've already been using Telerik Testing Framework for a while then, you will have a bunch of test code already written and now you'd like to start taking advantage of this new set of controls. There are a couple of features included in the control suite that help to make it easier to retrofit the new control suite into existing code.

 

The first feature is to use the HTML wrapper class's constructor passing in the existing element object from you current code. For example:

 

C#

// The first line is a line of code in your existing test case.
Element myButtonElement= Find.ById("htmlbutton");
// Add this line to your code to start using the HTML element wrapper class instead.
HtmlButton buttonClass = new HtmlButton(myButtonElement);

 

Visual Basic

' The first line is a line of code in your existing test case.
Dim myButtonElement As Element = Find.ById("htmlbutton")
' Add this line to your code to start using the HTML element wrapper class instead.
Dim buttonClass As HtmlButton = New HtmlButton(myButtonElement)

 

The next feature is to use the AssignElement() method. Using this method you can wrap any existing element object into one of the new HTML wrapper classes. For example:

 

C#

// The first line is a line of code in your existing test case.
Element myHtmlButtonElement = Find.ById("htmlbutton");
// Create a new control instance and assign the existing element to it.
HtmlButton buttonClass = new HtmlButton();
buttonClass.AssignElement(myHtmlButtonElement);

 

Visual Basic

' The first line is a line of code in your existing test case.
Dim myHtmlButtonElement2 As Element = Find.ById("htmlbutton")
' Create a new control instance and assign the existing element to it.
Dim buttonObj2 As HtmlButton = New HtmlButton()
buttonObj2.AssignElement(myHtmlButtonElement2)

 

 The last advanced feature is the .As<TControl> construct. The .As<TControl> construct acts like a typecast converting your plain element object into the typecast HTML element wrapper object. For example:

  

C#

// The first line is a line of code in your existing test case.
Element myHtmlButtonElement3 = Find.ById("htmlbutton");
// Make a comparison using the .As<TControl> construct.
Assert.IsTrue(myHtmlButtonElement3.As<HtmlButton>().Value.Equals("Html Button", StringComparison.OrdinalIgnoreCase));

 

Visual Basic

' The first line is a line of code in your existing test case.
Dim myHtmlButtonElement3 As Element = Find.ById("htmlbutton")
' Make a comparison using the .As<TControl> construct.
Assert.IsTrue(myHtmlButtonElement3.As(Of HtmlButton)().Value.Equals("Html Button", StringComparison.OrdinalIgnoreCase))