Explaining how the real world works!     RSS Feed The Automated Tester on Twitter The Automated Tester on LinkedIn The AutomatedTester on github

Selenium Two Tutorial using IronRuby and InternetExplorerDriver

Mon 11 Jan 2010

This tutorial is to show how to use the .NET Selenium 2 with dynamic languages that run on the .NET Common Language Runtime. This tutorial uses IronRuby.

To complete this tutorial you will need to have IronRuby installed. You will need to install it to C:\IronRuby\ to so we can use the Gem application later on. You will also need to download the .NET Bindings from Google Code

This tutorial will not be using the Remote Driver and it will be using the InternetExplorerDriver as this is the only complete browser at the moment that doesn't need to be built from the Repository.

  1. Lets start by creating a directory that will hold the IronRuby script. Lets call it SeleniumTwoExampleRuby
  2. Copy the WebDriver.Common.dll, WebDriver.IE.dll and InternetExplorerDriver.dll files into the newly created directory in the step above. I have only managed to get this to work with the Win32 version so only work with that.
  3. Now to make sure that we have a test framework to use. We can download the Test-Unit Gem. Open a Command Prompt, making sure you running as Administrator if on Windows Vista or Windows 7, and run the command igem install test-unit.
  4. We are now ready to have our write our first test!Copy the code below into a Ruby IDE or Notepad. Save the file as test_google.rb
    #Check this is being run in IronRuby
    have_ironruby = defined?(RUBY_ENGINE) && RUBY_ENGINE == "ironruby" 
    if !(have_ironruby)
      puts "This needs to be run with IronRuby"
      exit 1
    require "WebDriver.Common.dll"
    require "WebDriver.IE.dll"
    require "test/unit"
    include OpenQA::Selenium
    include OpenQA::Selenium::IE
    class SeleniumTwoExample < Test::Unit::TestCase
      def setup
        $driver ||= InternetExplorerDriver.new 
      def teardown
      def test_Google_For_The_Automated_Tester
    	#Navigate to Google
        $driver.Navigate.GoToUrl "http://www.google.com"
        #Create a WebElement Object to work against
    	query_box = $driver.find_element By.name "q"
    	query_box.send_keys "The Automated Tester"
    	#Check the value of the title
        assert_match /^The Automated Tester/, $driver.title
        # or
        assert $driver.title.include?("The Automated Tester") 
  5. Now you have a test that launch a browser and do a search on Google for you. In a command prompt run ir test_google.rb

Now you have created your first test that uses WebDriver

Thanks to Jari Bakken for helping me with this IronRuby example

    Area: tutorials

blog comments powered by Disqus