Good part of selenium is that the selenium tests can be written in multiple programming languages like c#, Java, Perl, PHP, Ruby etc. I normally hear saying that “This Java project, so we can write tests in Java as well”. The only advantage I see with this is that you can get help from development team incase you are stuck somewhere. But if you are good at c# or any other language it should not be an hindrance. Test framework will be different that coding framework unless you want to integrate it.
I covered Java and C# in most of my previous posts. Here I will be using Ruby to write the Selenium tests.
A simple Ruby Test
require "selenium-webdriver" driver = Selenium::WebDriver.for :firefox driver.navigate.to "http://www.google.com" element = driver.find_element(:name, 'q') element.send_keys "Hello Selenium WebDriver!" element.submit
require “selenium-webdriver” – This is similar to import in Java and using in c#
The above example is without using any Test framework. In Ruby you can use Test Framework as you do with C# ( NUNIT test framework) and Java( JUNIT or TestNG framework).
In Ruby you can use minitest or BDD framework RSpec or Cucumber
Structure of RSpec test
load File.dirname(__FILE__) + '/test_helper.rb' #'describe' marks the a test group describe "Selenium Ruby Tests" do include TestHelper # 'it' marks the start of a test case, ends with the matching 'end' it "Start Chrome" do browser = Selenium::WebDriver.for(:chrome) browser.navigate.to(site_url) sleep 1 browser.quit end it "Start FireFox" do browser = Selenium::WebDriver.for(:firefox) browser.navigate.to(site_url) sleep 1 browser.quit end it "Start IE" do browser = Selenium::WebDriver.for(:ie) browser.navigate.to(site_url) sleep 1 browser.quit end end
For more information on RSPec click here .