Thursday, April 10, 2014

0 How to add Watir-Webdriver support in your scripts


First of all you need to install Watir-Webdriver gem on your machine. It’s pretty simple.

Installing watir-webdriver  gem
  • Open command prompt.
  • Type “gem install watir-webdriver”
  • You should see a confirmation message that it is installed. 
Note: If you don’t have selenium-webdriver gem already installed, let me tell you, water-webdriver has selenium-webdriver as a dependent gem.  All the dependent gems for water-webdriver gem would also get installed automatically when you install watir-webdriver.  Remember? In the tutorial Selenium History, we have seen that water-webdriver implements selenium-webdriver. This is the reason why watir-webdriver is dependent on selenium-webdriver.


 
Steps to include the support for watir-webdriver in you scripts
1. Open Aptana Studio.
2. Create a new project if you don’t have one already
a.      Right click on left hand pane of Aptana
b.      Move cursor over “New”
c.      Move cursor over “Ruby Project”
d.      Select “Default Project” from New Project window. Click Next button.
e.      Let the defaults stay for all the fields but enter a suitable project name in Name filed. Click Finish button.




  
3. Create a new ruby file
a.      Right click on left hand pane of Aptana
b.      Move cursor over “New From Template ”
c.      Move cursor over “Ruby”
d.      Move cursor over “Blank File”
e.      Enter a suitable name to your script. Make sure you have “.rb” as extension while adding the name to the script. Click finish.


4. Open script that you have just created from left hand pane.

5. Type the following line of code on top of your script
require “watir-webdriver”

Note: In ruby if we install a gem(library), we can add it to any of our scripts using “require” keyword followed by gem(library) name in quotes.




6.  Now to verify that watir-webdriver is added to your script, just click on run button on Aptana Studio tool panel.



If you see any errors in console, this would mean you did something wrong while configuring or installing watir-webdriver.

7. You don’t believe if technique mention in step 6 is working or not, do you ?
OK let’s clarify our doubt.
Type ‘require howdy’ and click on play button. You would see some errors in console. Now you can confidently believe that technique at step 6 is working and is a proof that watir-webdriver is successfully added to script.


That's all for this session. See you again in next session. 

Happy Testing :) :)
Shiva Krishna Imminni

To sponsor my work and help maintain this site please contact me.

Sunday, November 17, 2013

0 Required installation and setup on your computer

Required Softwares to run Ruby scripts (for selenium automation) on windows7
  1. Ruby 1.9.3 Installation
  2. Ruby Devkit Installation
  3. Installing AutoIt and registering AutoIt DLLs
  4. Aptana Studio


1.      Ruby 1.9.3 Installation
For writing scripts in ruby you have to first install ruby on your windows system. You can install latest version of Ruby from its home page but we recommend to go for Ruby 1.9.3 as it is mostly supported and compatible version at the time of writing this article. You can always download the older versions of Ruby from ruby website. You can download the ruby files as an archive but we recommend to download the installer when you are installing ruby on windows as it is easy way of installing Ruby.
You can download Ruby installer for windows from here. Again, we recommend to go for Ruby 1.9.3.

Installation:
1.1. After downloading Ruby1.9.3 installer, double click on ruby installer file (.exe) or executable and accept the download confirmation box (if appear) by hitting “Yes” button.
1.2.  Select the following three options as shown in the figure below and proceed with the installation by clicking on Install button.

Click FINISH button after installation completes.
1.3. After the installation completes check if Ruby is installed. 
Open command prompt.
type: ruby --version  and press enter. 
If ruby is installed successfully it’ll display the version number when you type “ruby --version” at command prompt.

2.      Ruby DevKit Installation

What is DevKit?
DevKit is Development Toolkit for ruby installer that makes it easy to build and use native C/C++ extensions. Some of the ruby libraries/gems makes use of functions written in a different language outside ruby like C/C++. For such gems to be installed on your machine first you would need DevKit support on your PC. Since we might come across such gems, we added this step to install Ruby DevKit in our tutorials. 

DevKit Installation
2.1. Download DevKit from here.
NOTE: Please download DevKit specific to the Ruby version you installed on your system.

2.2. After downloading DevKit place it in a separate folder named "DevKit" under ruby installation directory “C:\Ruby193”.
2.3. Unzip or extract DevKit file using software like WinZip. 
      After extracting the files run the following commands at command prompt:

Navigate to the location where you placed the extracted file 
C:\Ruby193\DevKit>ruby dk.rb init
After running the above command a file will be created named – “config.yml”.

Now run:
C:\Ruby193\DevKit>ruby dk.rb install

After running the above commands DevKit path will be set.
For more details on Devkit installation refer this page.

3.      Installing AutoIt and registering AutoIt DLLs
AutoIt v3 is a freeware BASIC-like scripting language designed for automating the Windows GUI and general scripting. It uses a combination of simulated keystrokes, mouse movement and window/control manipulation in order to automate tasks in a way not possible or reliable with other languages (e.g. VBScript and SendKeys). AutoIt is also very small, self-contained and will run on all versions of Windows out-of-the-box with no annoying “runtimes” required!

Refer http://www.autoitscript.com/site/autoit/ for AutoIt installation.
After installing AutoIt, set the path environment variable to “C:\Program Files (x86)\AutoIt3\AutoItX” (For 64 bit windows version) or “C:\ProgramFiles\AutoIt3\AutoItX” (For 32 bit windows version).
  
4.      Installing APTANA STUDIO 

Aptana is open source development tool. It allows you to develop and test entire application at one place. It supports various languages such as HTML5, CSS3, JavaScript, Ruby, Rails, PHP and Python. We are interested in writing our automation scripts in Ruby using Aptana Studio as IDE.

To download installer for Aptana Studio click here.

After downloading Aptana Studio3 installer, just like ant other windows installer, with the default options selected finish installing the software.

Get Started: Reference to Ruby tutorials
      Below are some of the references to pages where you can learn Ruby. Note that, to follow with rest of the tutorials on webdriver you are expected to have basic knowledge of Ruby programming language. So please do that before reading any further on Selenium-Webdriver.
o   https://github.com/bbatsov/ruby-style-guide (For Ruby General Conventions)

Wednesday, November 13, 2013

0 Selenium History

Sources:

The goal of this tutorial is to explain what comprises and defines Selenium. For this we need to look at some of its history and its architecture too. In fact its history is nothing but understanding how it has evolved (architecture) with time and who helped it in its evolution. To be frank with you, to be a Selenium developer it is enough to go through current Selenium WebDriver 2.0 API but we would cover this anyway in our tutorials because we want to pay respect to super heroes who created this awesome tool for us to help in automation and their story be told.

Selenium originally created by Jason Huggins in 2004. Along with contributions from ThoughtWorks engineers and others who are interested in this technology, he released it as an open source under Apache 2.0 license.

Selenium in general is a suite of 3 tools: Selenium IDE, Selenium WebDriver and finally Selenium Grid.

Selenium Core and Selenium IDE

Jason Huggins started Selenium project in 2004 while working at ThoughtWorks on one of their in-house application “Time and Expenses” system.  He wrote Selenium core in JavaScript.  Most of the browsers support JavaScript so this worked as a miracle and he was able to automate testing of his application on almost all browsers. Knowing this, his work was much appreciated and the word is spread about his work.

Using Selenium core automation was pretty easy to learn even for a non-programmer because it followed a table like syntax. This table operates over the raw Java Script. This table based approach is also called as keyword based approach.

Below we have given an example for Keyword or tabled based programming





Column 1 – ‘type’ is the command (the keyword for expected operation)
Column 2 – ‘//div[@id=’welcome text’] ‘ is the element identifier
Column 3 – ‘Howdy!!’ is an optional value.

So a user has to remember a bunch of keywords and pass the element locator to perform some action (automated), that's it. This keyword based approach became popular as Selenese.

This seems to pretty easy right? But developers and users of Selenium Core found problems in this design; they realized that maintaining a project even of an average size is difficult. Below are some of those problems,
  • Since selenium core is purely written in Selenium, it forced the developers with no option than hosting Selenium Core and tests on server. This is to avoid breaking browser’s security.
  • Giving access to server to host their test is not practical in real time.

In 2006, Shinya Kasatani of Japan became interested in Selenium, and using Firefox extension, he developed a complete integrated development environment-IDE, that’s where the name Selenium IDE originated from. It is a wrapper around Selenium core and using this tool one could record, edit and debug tests.
Please find Selenium IDE tutorials àhereß

Selenium RC – Remote control

A Selenium Remote Control is a server, written in Java, which accepts command for the browser via HTTP. This made it possible to write automation for a web application in any programming language that is capable of doing an http request.  This means you would write automation in your favorite programming language and kick of an automation run remotely. This is how Selenium RC – Remote Control got it's name. Note Selenium RC still uses table/keyword based approach internally. Http proxy internally converts these http requests into appropriate Selenese commands.

WebDriver
Yes, I did not call it Selenium-WebDriver. There is a reason for it. WebDriver is not a part of Selenium initially. WebDriver is another automation framework being developed at the same time frame where Selenium-RC was taking shape. This was developed with intention that tests should be independent of underlying technology. In case of Selenium RC this is not the case. They are dependent on JavaScript support for browser.  To eliminate this dependency Selenium WebDriver was developed to make use of browser native language.

Differences between Selenium RC and WebDriver
Selenium RC
WebDriver
Uses Selenium Core which makes extensive use of JavaScript
Communicates with a browser using browser native language.
Keyword based API
Object based API
Supports wide range of languages. Thanks to the idea of http requests.
Supports only Java
Need a server to run the test.
We don’t need a server her.

Selenium WebDriver

Selenium WebDriver = Selenium (RC) + WebDriver. 

Yes you guessed it right; Selenium WebDriver came into existence after mixing two different projects. In 2009, an announcement was made that Selenium RC and WebDriver would merge which eventually called as Selenium WebDriver. This implementation is done by using a browser specific browser-driver. Server is no long required here.

Selenium WebDriver is also known as Selenium 2.0 while Selenium RC is known as Selenium 1.0
Selenium 1.0 provides rich set of API calls for different browsers. On the other hand Selenium 2.0 aims at providing building blocks on which developers can create their own implementation. Consider Selenium 2.0 as a specification which is followed by developers of Selenium drivers. One such project is Watir-WebDriver in ruby, which implements the Watir API as a wrapper for Selenium-WebDriver  in ruby.




0 What languages are supported by Selenium and Why did we chose Ruby ?

Selenium is supported by major programming languages. This include: C#, Java, Perl, PHP, Python, Ruby. More details on support for Selenium can be found here.

We have chosen Ruby for this tutorials for following reasons:
  • Scripting languages are more convenient to work.
  • Learning curve for Ruby is small.
  • We have not chosen Python, because it is very strict on indentation and structure of program.
  • We have not chosen Java, because the learning curve is large. 
  • We wanted something that is easy to learn even for a person from a non-programming background.

0 What are available options in ruby in support of Selenium?

There are various drivers in ruby that provides implementation for Selenium WebDriver specification.
This includes: 
  1. Selenium-WebDirver     
  2. Watir-WebDriver     
  3. Capybara
  4. PantomJS and probably many more...

We would be using Watir-WebDriver in our examples. Once Watir-WebDriver is learned, the rest of the WebDrivers implementations should not be difficult for you to explore and find out. 


See what Wikipedia has to say about Watir Webdriver:
A must read article. I liked the author’s explanation on differences between the options we have mentioned above for Selenium automation in ruby:  ->>Find Here<<-

 

QuestionSelenium Copyright @Shiva Krishna