Automated testing tools:Selenium & Watir
When should use automation?
What is advantageous for automated testing? When should one decide to automate test cases?
For the short term project,manual testing may be more effective. If an application has a very tight deadline, there is currently no test automation available,then manual testing is the best solution.
However, automation has specific advantages for improving the long-term efficiency of a software team’s testing processes.As we can save the time special for the regression test.What is more,it is trivial for the tester if repeat the same test case.
Selenium
Selenium IDE is a plug-in for FireFox,and isn't available for other browser.
It provides an easy-to-use interface for developing and running individual test cases or entire test suites.
Selenium-IDE has a recording feature,then can export the code in several kinds of language.
Right now,give a example for how to use it.
Suppose we want to login Gmail:
Open the FireFox browser,click the "Tools" tab,then you can see the "Selenium IDE" is in the list,click it and will pop up a window as following:
Then back to the FireFox browser,open google home page and click the "Gmail" link,then fill info and press "Sign in" button.
Turn to the Selenium IDE again,all the actions are recorded,see the following screenshot:
Click the red round button in the upper right corner to stop the record.The browser will execute the action what you did just now when hit the green triangle button.
Selenium IDE can only run the test in FireFox.Obviously,this is not enough.So we must mention Selenium RC.
We can export the code and apply the test in others browser through Selenium RC.
It is simple to export the code in Selenium IDE,view the picture:
Usually,the exported code isn't perfect.Luckily,Selenium-RC allows the test automation developer to use a programming language for maximum flexibility and extensibility in developing test logic.
It provides an API and library for each of its supported languages: HTML, Java, C#, Perl, PHP, Python, and Ruby. This ability to use Selenium-RC with a high-level programming language to develop test cases also allows the automated testing to be integrated with a project’s automated build environment.
Contain three parts:Command,Target and Value
Just give the simple explanation here
Command:What you want to do for the browser.Such as,"click" a link,"fill" the textarea and so on.
Target:Tell the browser which element you want to execute the command.
Value:The value that you want to fill or expect.Sometimes it is blank.It depends what kind of command is used.
Watir:
Watir is an open-source library for automating web browsers.
It is a family of Ruby libraries but it supports your app no matter what technology it is developed in.
It drives browsers the same way people do. Watir also checks results, such as whether expected text appears on the page.
Watir supports multiple browsers on different platforms.
Windows 2000/2003/XP/Vista/7 : IE6,IE7,IE8 and FireFox
Mac:FireFox and Safari
Ubuntu:FireFox
Install watir on different system is not the same.I just describe how to install it on Mac for Safari.
You have to install Ruby first,we recommend using Ruby 1.8.6 on all platforms.
The type the following commands in Terminal:
$ sudo gem update --system
$ sudo gem install rb-appscript
$ sudo gem install safariwatir
A moment later,the following info appears and indicates the Safariwatir is installed successfully.
$ sudo gem install safariwatir
Successfully installed safariwatir-0.3.7
1 gem installed
Installing ri documentation for safariwatir-0.3.7...
Installing RDoc documentation for safariwatir-0.3.7...
We also choose the Login Gmail as example so that it is easy to compare what is different between Watir and Selenium.
Open your Terminal and start irb.
$ irb
Before going to the Google,you have to let Ruby know you want to use SafariWatir,so please type:
irb(main):001:0> require "rubygems"
=> true
irb(main):002:0> require "safariwatir"
=> true
Then start the browser
irb(main):003:0> safari=Watir::Sfari.new
=> #, @app=app("/Applications/Safari.app"), @document=app("/Applications/Safari.app").documents[1]>>
Go to Google:
irb(main):004:0> safari.goto "http://www.google.com"
=> nil
Click the "Gmail" link in the upper left corner:
irb(main):005:0> safari.link(:text,"Gmail").click
=> nil
After flowing to the login page,you can fill personal info and hit "Sign in" button to login.
To do this, we have to find out some attribute of text field, like id or name, so Safariwatir can find it on the page. We will use Firebug for the first time.
irb(main):006:0> safari.text_field(:id,"Email").set("ruby@gmail.com")
=> :missing_value
irb(main):007:0> safari.text_field(:id,"Passwd").set("ruby")
=> :missing_value
irb(main):008:0> safari.button(:value,"Sign in").click
=> nil
If the username and password are correct,you should login successfully.
Compare
Selenium IED can record the acitons and export the code,so can save lots of time for the script developer.Watir doesn't have this tools,all the codes have to be typed by hand.
Mac OS X:
Developers still need to strive for Safariwatir and Firewatir,as lots of commands that works fine in Windows cannot apply in Mac.What is more,performance isn’t stable.
However,Selenium can resolve all the issue that watir is unable to deal with.
So watir is not good as Selenium on Mac.
Windows:
Use selenium to test IE is not the same as FireFox in Mac.Especially for the locator,running the script will be very slow if the locator isn't suitable.
Originally developed watir is to apply on IE.Until now,it is perfect.

