Watir - Open Source Web Testing tool

What do you mean by Watir?

Web Application Testing in Ruby (Watir) is an open source testing tool. It is one of the popular open source testing tools. Lets us now have a look at its features, advantages, disadvantages and its comparison with Selenium.

Features of Watir QA testing tool

  • The test scripts are written in Ruby language.
  • It supports multiple domains and has a test recorder.
  • It can find elements by its name, index, ID or value.
  • WatirWebDriver supports browsers like Chrome, Firefox and Safari with help of ChromeWatir, FirefoxWatir and SafariWatir respectively.

Watir’s advantages
  • It is very easy to learn.
  • It is very easy to debug
Watir’s disadvantages
  • To use Watir you need to learn Ruby language because it supports no other language.

Comparison of Watir and Selenium

Selenium
  • Selenium supports multiple languages.
  • It supports multiple browsers.
  • In order to install Selenium IDE, we need to first install Firefox because Selenium IDE is a Firefox plugin.

Watir
  • Watir supports only Ruby language.
  • WatirWebDriver supports multiple browsers like IE, Chrome, Safari, Firefox browser and Opera.

How to install Watir?

The installation process consists of two steps. First install Ruby and then Watir. Ruby installation on Windows
Before installing Ruby on your machine it’s always better to check whether you have already installed it. You can check this by running the given below command from your command prompt.
ruby– v
Note: If Ruby is installed on your machine, then its version will be displayed. If not then a message will be displayed stating that it is not a recognized command.

The steps for installing Ruby on Windows are as follows.
  • Install the latest version of Ruby using RubyInstaller. It is an easy way to install Ruby. Initially Ruby was installed by using one-click installer but now you can prefer RubyInstaller.
    http://rubyinstaller.org/
  • Open the above link and then click on “Downloads’.The downloads page will be opened http://rubyinstaller.org/downloads/
  • Click on the latest version of Ruby and run the installer. Follow the steps that are shown on the screen.
  • Click on your Start menu and check which entries have been created after installing Ruby.
  • You can also verify the installed Ruby version with the help of the command ruby –v
  • Once you have installed Ruby, you can download an open source editor to write programs in Ruby. There are many open source editors available. For example Notepad++. You can download the one you mostly prefer.
  • Link to download Notepad++ https://notepad-plus-plus.org/

Updating RubyGems
RubyGems are softwares written in Ruby. They are also called gems.It is very important to update RubyGems because the installation of Ruby may not contain the latest version of RubyGems.

Syntax to find version of gems (run this command from command prompt)
gem-v


Syntax to update RubyGems
gem update --system
Watir Installation
  • Open the Command Prompt
  • Run this command to install Watir
    gem install watir
  • Please note that if you are installing from behind a proxy, add this command at the end after any gem update or gem install.
    -p http://name_of_your_proxyserver:-port_of_your_proxyserver

How to create a Watir script?

The steps are as follows
  • Open an editor. Write the below code in it.
    require watir # load the watir library
    browser = Watir::Browser.new
    browser = Watir::Browser.start(“http://ianswer4u.com”)
  • Note - # is a comment. The text followed after this symbol is ignored.
  • Save it as samplefile.rb (Here rb is the extension used for Ruby files)
How to run the script?
  • Open the command prompt window and run the Watir test script.
    ruby C:\samplefile.rb
  • After you execute the above command an IE browser will be opened with the specified URL.

Watir Syntax

The syntax used in Watir is as follows.
  • To load library
    requirewatir
  • To open a browser and a specified URL
    browser=Watir::Browser.new
    browser=Watir::Browser.start(“http://ianswer4u.com”)
  • With help of goto syntax we can open a specified URL
    . browser.goto(“http://ianswer4u.com”)
  • To close the browser browser.close
  • To access elements
    • Buttons
      p=browser.button(:value, “Submit Form”)
    • Text area or text box
      b=browser.text_field(:name, “customer_firstname”)
    • Checkbox
      cb=browser.checkbox(:name, “enabled”)
    • Radio button
      rb=browser.radio(:name, “select activity type”)

Read More:
Windmill - Free Web Testing software and Windmill V/s Selenium
Difference between method Overloading and Overriding in OOPs
Difference between Abstraction and Encapsulation
Testing and Debugging : What, Who does it, Differences

Copyright © ianswer4u.com

0 Reactions:

Post a Comment