Testing RadControls for ASP.NET Ajax with Watir - How easy it is

Posted by: the telerik blogs, on 07 Nov 2008 | View original | Bookmarked: 0 time(s)

Today was my first attempt at writing tests for RadControls with Watir and was surprised how easy it is.
I found over the intenet a good article on how to test ASP.NET applications using Watir and also refered to the Hristo Deshev's blog post about Automating Complex JavaScript-rich Controls with Watir.
If you use the approach described in it and create a watir_telerik_extensions.rb file, you will be able to create tests very quickly. See below a few tests about RadMenu, RadComboBox and RadTreeView which I have created in minutes:

1. This is a RadComboBox test which opens the drop down and verifies whether it is opened:

---------------------------------------------------------------------------------------------
require 'rubygems'
require 'watir'
require 'test/unit'
require 'watir_telerik_extenstions'

include Watir

class ComboTest < Test::Unit::TestCase
def setup
@ie = IE.new
@ie.goto "http://demos.telerik.com/aspnet/prometheus/ComboBox/Examples/Functionality/FilteringCombo/DefaultCS.aspx"
end

def test_DropDown
@ie.execute_script "$find('RadComboBox1').showDropDown()"
@ie.execute_script "window.Result = $find('RadComboBox1').get_dropDownVisible()"

assert_equal true, @ie.window.Result
end

def teardown
@ie.close
end
end
---------------------------------------------------------------------------------------------

2. See below another test which is for RadMenu. It opens the first RadMenu item and verifies its text:
---------------------------------------------------------------------------------------------
require 'rubygems'
require 'watir'
require 'test/unit'
require 'watir_telerik_extenstions'

include Watir

class MenuTest < Test::Unit::TestCase
def setup
@ie = IE.new
@ie.goto "http://demos.telerik.com/aspnet/prometheus/Menu/Examples/Default/DefaultCS.aspx"
end

def test_open_item
@ie.execute_script "$find('RadMenu1').get_items().getItem(0).open()"
@ie.execute_script "window.Result = $find('RadMenu1').get_openedItem().get_text()"
assert_equal "File", @ie.window.Result
end

def teardown
@ie.close
end
end

---------------------------------------------------------------------------------------------

3. This test for RadTreeView selects the first node and verifies its text:
---------------------------------------------------------------------------------------------
require 'rubygems'
require 'watir'
require 'test/unit'
require 'watir_telerik_extenstions'

include Watir

class TreeViewTest < Test::Unit::TestCase
def setup
@ie = IE.new
@ie.goto "http://demos.telerik.com/aspnet/prometheus/TreeView/Examples/Programming/XmlFile/DefaultCS.aspx"
end

def test_select
@ie.execute_script "$find('RadTreeView1').get_nodes().getNode(0).select()"
@ie.execute_script "window.Result = $find('RadTreeView1').get_selectedNode().get_text()"

assert_equal "Books", @ie.window.Result
end

def teardown
@ie.close
end
end

---------------------------------------------------------------------------------------------

Enjoy!

Advertisement
Free Agile Project Management Tool from Telerik
TeamPulse Community Edition helps your team effectively capture requirements, manage project plans, assign and track work, and most importantly, be continually connected with each other.
Category: ASP.NET | Other Posts: View all posts by this blogger | Report as irrelevant | View bloggers stats | Views: 1251 | Hits: 8

Similar Posts

  • Telerik Introduces Free Web Testing Framework for ASP.NET AJAX and Silverlight more
  • Teleriks Q2 2009 Release Expands All-in-one .NET Offering more
  • AJAX >> Using AJAX to load a usercontrol that has refers to a custom css file more
  • Error: A ScriptManager is required on the page to use ASP.NET AJAX Script Components... more
  • How to... use Class Libraries with ASP.NET AJAX like AjaxPro more
  • SliderExtender layout and custom appearance more
  • Authentication and Session more
  • Difference between our two AJAX books more
  • RadControls in Safari for Windows more
  • New Best Practice: Ajaxifying UserControls more

News Categories

.NET | Agile | Ajax | Architecture | ASP.NET | BizTalk | C# | Certification | Data | DataGrid | DataSet | Debugger | DotNetNuke | Events | GridView | IIS | Indigo | JavaScript | Mobile | Mono | Patterns and Practices | Performance | Podcast | Refactor | Regex | Security | Sharepoint | Silverlight | Smart Client Applications | Software | SQL | VB.NET | Visual Studio | W3 | WCF | WinFx | WPF | WSE | XAML | XLinq | XML | XSD