Automation testing always saves the time. If there are five features in an application which is already tested manually and a new sixth feature included in the application then tester has to test the five feature plus the new feature also.But automation testing will test altogether and saves the time of the tester.It record the actions performed on the object in the application and while playback the same actions are performed on the object in the application under test.
For testing web application we use different automation tools . Sahi is one of the example which is an open source record and playback automation tool .
Features :-
- User friendly
- Platform independent
- Powerful object spy
- Support and performs data driven testing
- Multithreaded playback feature,
- Support( HTTP,HTTPS and AJAX),
- Perform validation through Assertion feature included in the interface
- Produce automatic html output report with error logs
- Does not need wait statement like other automation tools.
Sahi can test on any platform and run the scripts in batch mode.Anything that runs on the browser can be automated using sahi.Object spy work as spy through which we can view the properties of the object in the web application which is helpful while scripts.Data driven testing is useful while testing multiple data for single field with same script.
Download Sahi
To download sahi tool we can refer http://sahi.co.in. After downloading we have to configure browser before starting the proxy.
Steps to start sahi proxy
Windows: – Go to <sahi_root>\userdata\bin and run start_sahi.bat
Linux – Go to <sahi_root>/userdata/bin and run start_sahi.sh
Steps to configure Browser in linux
Firefox
Go to Edit>Preferences>Network>Settings>
Set to Manual Proxy configuration
Set “HTTP Proxy” to “localhost”
Set “Port” to “9999”
Set “SSL Proxy” too to record and playback https sites.
Steps to configure Browser in windows
Firefox
Go to Tools > Options > General > Connection Settings
Set to Manual Proxy configuration
Set “HTTP Proxy” to “localhost”
Set “Port” to “9999”
Set “SSL Proxy” too to record and playback https sites.
Internet Explorer
Go to Tools > Internet Options > Connections > LAN Settings >
In “Proxy server” section, Check “Use a proxy server for your LAN”
Click on “Advanced”
For HTTP: set “Proxy address to use” to “localhost” and set “Port” to “9999”
For HTTPS: set “Proxy address to use” to “localhost” and set “Port” to “9999”
Clear out anything in “Do not use proxy server for addresses beginning with:”
Click on ok
Leave “Bypass proxy server for local addresses” unchecked
Ok>Ok
Recording done by sahi tool
1.Press Ctrl and Alt Key simultaneously and double click on the window which we want to record to get the interface on the browser.
Sahi’s controller will pop up(See pic below).
2.On the controller go to the record tab assign a name for the script with extension (.sh) and click record.
3.Navigate on the website and actions will be recorded
4.Add an assertion
a.Move the mouse over any html element while pressing Ctrl key. The Accessor field will get populated in the Controller.
b.Click the “Assert” button to generate assertions for the element. They will appear in the “Evaluate Expression” box.
c.Click Test to check that the assertions are true.
d.Once satisfied, click on “Append to Script”. This will add the assertions to the Script.
e.Click “Stop” to finish recording.
f.We can view the recorded actions in view history included in the controller
g.The script can be edited even while recording.
Playback steps
1. Open the Sahi Controller (CTRL-ALT-DblClick on the page).
2. Enter the script name in the “File:” field (with the help of the autocompletion feature).
3. Enter the Start URL of the test.
4. Click ‘Set’.
5. Wait for the page to reload.
6. Click ‘Play’.
It will execute the steps and controller will update accordingly. Once finished, SUCCESS or FAILURE will be displayed at the end of the steps.
View logs
We can view the Output of the recorded actions.On the Controller, go to Playback tab and click on “View Logs” link at the bottom right.It will open a window with the results
Data Driven Testing
For this scenario we can put all the user information in an excel sheet and can use a single script.Data table can be created by inserting values in a table or by importing data from an external file.For example we can use data driven testing if we want to create an account in yahoo for 100 or 1000 people.
Code for Data Driven Testing
coding with null function
[javascript]
function login($email, $pwd)
{
try
{
_setValue(_textbox("email"), $email);
_setValue(_password("passwd"), $pwd);
_click(_submit("Log in"));
_click(_link("logout"));
}
catch(e)
{
_logException(e);
}
}
function blankIfNull($s)
{
return ($s == "null" || $s == null) ? "" : $s;
}
var $name;
var $password;
_navigateTo("URL", true);
_click(_link("signup"));
var $data=_readCSVFile("/home/users/anushree/test.csv");
for(var $i=0; $i<$data.length; $i++)
{
var $row = $data[$i];
$name = blankIfNull($row[0]);
$password = blankIfNull($row[1]);
login($name, $password);
}
[/javascript]
Explanation
Above specified scenario is about login and log out session for more than one users at a time which can be performed by data driven testing through sahi tool.
AJAX(Asynchronous java script and XML)
“Asynchronous” means processing without a fixed time interval .Ajax is a programming language which create dynamic web applications with the help of javascript and XML.
“XML” is a data storage language which helps a designer to create element tags.It brings up updated information into the page without the need of reloading the whole document with all images and menus and javascript help it to present it dynamically. Ajax applications works on any browser and it is also platform independent.Gmail,Youtube,google maps and Facebook tabs are few applications which are based on Ajax.
A very good example of Ajax application is login scenario where one particular user want to create a new account .In this case javascript can verify two things whether login id meets the minimum and maximum length and does not contain any invaild characters.To validate that particular login id is not in use by someone else we need to check the database to check whether this particular id exists or not . Javascript cant do this alone but by using Ajax it can pass on the loginid to the server for checking and recieve a reply that can be dynamically displayed on the page without having to wait for the form to be submitted and a whole new web page to load.
Ajax contain following elements:-
a.Javascript for local processing and DOM(Dynamic object modal) for accessing content of the page or to acces the elements of the XML file.
b.HTML and CSS for presenting.
c.The XMLHttpRequest object is used to read or send data on the server asynchronously.
All modern browsers (IE7+, Firefox, Chrome, Safari, and Opera) have a built-in XMLHttpRequest object.
Syntax for creating an XMLHttpRequest object:
[javascript]
xmlhttp=new XMLHttpRequest();
[/javascript]
Old versions of Internet Explorer (IE5 and IE6) uses an ActiveX Object:
[javascript]
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
[/javascript]
To send a request to a server, we use the open() and send() methods of the XMLHttpRequest object:
[javascript]
xmlhttp.open("GET","ajax_info.txt",true);
xmlhttp.send();
[/javascript]
-
Methods:-
open: create a connection.
send: send a request to the server.
-
open(method,url,async)
Specifies the type of request, the URL, and if the request should be handled asynchronously or not.
method: the type of request: GET or POST
url: the location of the file on the server
async: true (asynchronous) or false (synchronous)
-
send(string)
Sends the request off to the server.
string: Only used for POST requests
POST is more robust and secure than GET
With help of AJAX, the JavaScript does not have to wait for the server response, but can can execute other scripts while waiting for server response.
If the response from the server is not in the form of XML, we can use the responseText property.The responseText property returns the response as a string, and we can use it as:-
document.getElementById(“myDiv”).innerHTML= xmlhttp.responseText;
AJAX – The onreadystatechange Event
When a request to a server is sent an action will be there based on the response.The onreadystatechange event is triggered every time the readyState changes.The readyState property holds the status of the XMLHttpRequest.
Three important properties of the XMLHttpRequest object:
onreadystatechange:-
Stores the function to be called automatically each time the readyState property changes.
Ready state:-
0: request not initialized
1: server connection established
2: request received
3: processing request
4: request finished and response is ready
Status:-
200: “OK”
404: Page not found
The readyState property holds the status of the XMLHttpRequest.
When readyState is 4 and status is 200, the response is ready:
Example:-
[javascript]
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
[/javascript]
Sahi can execute the Ajax application without using wait statement.
Example:-
Let’s create a search page for SparkSupport website with following search options:
- Remote Infrastructure Management Services
- Cloud Computing Infrastructure Services
- Server Setup And Security Hardening
- E-mail Deliverability Support
when a user types a character in the input field (searchbox) , the function “showResult()” get executed .The function is triggered by the “onkeyup” event
created file named searching.php
[php]
//Searching.php
$xmlDoc=new DOMDocument();
$xmlDoc->load("data.xml");
$x=$xmlDoc->getElementsByTagName(‘link’);
//get the q parameter from URL
$q=$_GET["q"];
//lookup all links from the xml file if length of q>0
if (strlen($q)>0)
{
$hint="";
for($i=0; $i<($x->length); $i++)
{
$y=$x->item($i)->getElementsByTagName(‘title’);
$z=$x->item($i)->getElementsByTagName(‘url’);
if ($y->item(0)->nodeType==1)
{
if (stristr($y->item(0)->childNodes->item(0)->nodeValue,$q))
{
if ($hint=="")
{
$hint="<a href="%22%20.%20$z-%3Eitem%280%29-%3EchildNodes-%3Eitem%280%29-%3EnodeValue%20.%3Cbr%20/%3E%22" target="_blank">" .
$y->item(0)->childNodes->item(0)->nodeValue . "</a>";
}
else
{
$hint=$hint . "
<a href="%22%20.%20$z-%3Eitem%280%29-%3EchildNodes-%3Eitem%280%29-%3EnodeValue%20.%3Cbr%20/%3E%22" target="_blank">" .
$y->item(0)->childNodes->item(0)->nodeValue . "</a>";
}
}
}
}
}
if ($hint=="")
{
$response="no suggestion";
}
else
{
$response=$hint;
}
echo $response;
[/php]
Explanation:-
If the input field is empty (str.length==0), the function clears the content of the search placeholder and exits the function.
If the input field is not empty, the showResult() function executes the following:
- Create an XMLHttpRequest object
- Create the function to be executed when the server response is ready
- Send the request off to a file on the server
The page on the server called by the JavaScript above is a PHP file called “searching.php”.
The source code in “searching.php” searches an XML file for titles matching the search string and returns the result:
Created another file named search.php
[php]
<form>
<input onkeyup="showResult(this.value)" size="30" type="text" />
</form>
[/php]
If there is any text sent from the JavaScript (strlen($q) > 0), the following happens:
Load an XML file into a new XML DOM object
Loop through all <title> elements to find matches from the text sent from the JavaScript
Sets the correct url and title in the “$response” variable. If more than one match is found, all matches are added to the variable
If no matches are found, the $response variable is set to “no suggestion”.
Created another file named data.xml
[xml]
<?xml version="1.0" encoding="utf-8"?>
<pages>
<link>
<title>
Remote Infrastructure Management Services
</title>
<url>
http://www.sparksupport.com/services/
</url>
</link>
<link>
<title>
Cloud Computing Infrastructure Services
</title>
<url>
http://www.sparksupport.com/services/
</url>
</link>
<link>
<title>
Server setup and security hardening
</title>
<url>
http://www.sparksupport.com/services/
</url>
</link>
<link>
<title>
E-mail Deliver-ability Support
</title>
<url>
http://www.sparksupport.com/services/
</url>
</link>
</pages>
[/xml]
By going through “http://localhost/search.php” we will get the particular search box option for searching SparkSupport service details.Sahi can record the search steps and performs playback with script which we can view in log file.For this first we have to set the proxy and configure the browser as specified above.
Limitations
Sahi never handle pages which have other pages from different domains embedded in them using frames or iframes.So we can not have a page from google.com having an iframe with a page from facebook.com
Releases
Sahi releases once every two months and also it is improved continuously.
Updates
Sahi Pro V 1 has been released
Features
DSahi lets you distribute tests across machines to rapidly reduce your playback time.
Sahi does all the heavy lifting of distributing tests across machines, tracking their progress and assemble reports properly.
Sahi Pro automatically accepts SSL certificates.
Log results to database.
Build reports from the database.
Though the Chrome icon is present in sahi dashboard ,but when i click on it not able to open it.Please provide a solution .
yes
Hi Priya,
Sahi interface will open when you double click on any browser after doing proper configuration.No need to go for chrome icon present in the interface.
Regards
Anushree