Professional Documents
Culture Documents
Author:
Divya Peddi & Nivetha Padmanaban
Version: 1.0
Page 2
Version: 1.0
Introduction:
As application and domain becomes more complex, it becomes necessary to have an
effective regression suite to evolve the application. Most of the time, buying a commercial
tool may not be affordable for all companies. It is very dangerous to skip automation in
such cases. Open source tools help to take advantage of automation with no cost.
An important factor in automation is the choice of testing tool. A Test Manager may prefer
to have the option of working with an open source tool in order to contain project cost. This
paper elaborates on an open source tool called Sahi.
About Sahi:
Sahi is an open source automation and testing tool for web applications, with the facility to
record and playback scripts. Developed in java and JavaScript, this tool uses simple
JavaScript to execute events on the browser.
Sahi runs as a proxy server and the browser needs to use the sahi server as its proxy. Sahi
then injects javascript so that it can access elements in the webpage. This makes the tool
independent of the website/ web application.
Some of the features that sets Sahi apart from other tools are Ant support for playback of suites of tests
Suites can run in multiple threads thus reducing the test execution time
External Proxy, HTTP and HTTPS support
AJAX support
Good Database and file support.
Simple APIs
Easily editable scripts (text files) version friendly artifacts
Logging/reports
Tests do not need the browser window to be in focus
Supports javascript.
Editor support Jedit has supporting sahi.xml
Active community support
Page 3
Version: 1.0
Getting Started:
Initial Setup 1) Download and Install sahi from sourceforge.
2) Start the sahi proxy.
3) Configure the browser to use the sahi proxy.
Create scripts
Scripts can be created either using the Recording facility of the controller or they can be
directly written using any editor.
Controller Screenshots
Controller can be launched by ctrl+alt+dblclick on the browser window. Controller has very
powerful features like:
Page 4
Version: 1.0
APIs:
There are two kinds functions :
a) Normal Functions These are the functions which are primarily used to access
the elements on the web page.
Ex _button, _cell, _textbox
Some other examples which are not for accessing elements on the web page
_getText , _getGlobal
b) Scheduler Functions These are the functions that schedule the action for later
execution with a delay when its time comes. All actions should be performed using
them.
Ex - _assertEqual, _click, _rightClick
Example of API usages
Page 5
Version: 1.0
_click(_image("Inbox"))
_assertEqual(text message, _getText(_byId(mail_text))
Sahi Scripting:
Sahi script is based on javascript. So, sahi script automatically inherits the power of
javascript, like functions, variables, loops, conditional statements etc.
function getTextMessage()
{
return
(_byId(mail_text).value.replace(/\r/g,"").replace(/\n/g,""));
}
_assertTrue(getTextMessage().indexOf("---------- Forwarded message
----------") != -1);
Database support:
Sahi supports database connectivity, where script can connect to database during runtime
to execute any queries.
var db = _getDB("oracle.jdbc.driver.OracleDriver",
"jdbc:oracle:thin:@dbserver:1521:sid",
"username", "password")
var $rs = db.select("select * from User");
where $rs gets an 2 dimensional array of values and can be verified
as
_assertEqual("1", $rs[0]["ID"]);
_assertEqual("Kamlesh", $rs[0]["NAME"]);
_assertEqual("28", $rs[0]["AGE"]);
File Access:
Files can be accessed through provided APIs.
_readFile("filePath");
which returns the full file in single string and .split function can be used to read line by line.
For ex.
_readFile("filePath").split("\n");
where split is an javascript function.
Execute API:
Any DOS/Unix commands can be executed. For ex.
_execute("mkdir abc") - This invokes the call and returns immediately.
_execute("mkdir abc", true); - This invokes the call and waits till mkdir is done.
Page 6
Version: 1.0
Ant Integration:
Sahi has ant integration. By including a small snippet of code in build.xml file, it is possible
to run a suite of sahi tests. Ant integration offers several advantages
1. Facilitates running of functional tests as part of cruise control - This spares the QA of the
burden of having to explicitly run the tests. The QA just needs to keep a tab on the build
status and analyze the results in case of a failure.
2. Facilitates parallel execution of the tests - This opens multiple browser windows,
executes sahi scripts, and logs the results. This considerably reduces the execution time of
the suite and reduces the turnaround time of testing.
Page 7
Version: 1.0
Reporting
Two-level reports will be generated. First level is consolidated report as shown in the below
screenshot, where report just says the script name and its result. Sahi follows the color
code (green for pass and red for fail) for reporting which helps to locate the failed script
easily.
Page 8
Version: 1.0
Second level of reporting is the detailed report, which shows the detailed script. This report
shows the each line of the script and follows color code for asserts as shown in the below
snapshot.
Conclusion:
Sahi is one of the open source testing tool for web applications available in the market and
because of all above features, sahi is stands out from other open source tools. Sahi has
very active community and discussion forum. It is easy to adopt Sahi as it uses javascript,
the most common scripting language.
References:
http://sahi.co.in/
http://sourceforge.net/projects/sahi/
http://sourceforge.net/forum/?group_id=151639
Page 9
Version: 1.0