Today was my first attempt at writing tests for RadControls with Watir and was surprised how easy it is.
I found over the internet a good article on how to test ASP.NET applications using Watir and also referred 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!

Elena, Telerik


Related Posts

Comments

Comments are disabled in preview mode.