Macquarie QA Engagement Proposal Sahi Web Automation and Test Tool Author: Divya Peddi & Nivetha Padmanaban 2008 ThoughtWorks Ltd. Version: 1.0
This document and the information contained in it are the confidential property of ThoughtWorks Ltd. Use of the document is subject to the following conditions: 1. No part of this document may be reproduced or transmitted without the express written permission of ThoughtWorks Ltd. 2. The contents of this document shall not be revealed to any third party without ThoughtWorks prior written permission. 4. ThoughtWorks reserves rights at any time to revise, amend or withdraw this document and for any of these purposes to call for the return of this document. 2008 ThoughtWorks Ltd. 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. OSS is not taboo anymore: OSS gives control to the customer. You can see the code, change it, learn from it. Bugs are more quickly found and fixed. And when customers don't like how one vendor is serving them, they can choose another without overhauling their infrastructure. No more technology lock-in. No more monopolies. It multiplies one company's development capacity many times over. Everyone collaborates, the best software wins. Not just within one company, but among an Internet-connected, worldwide community. As a result, the open source model often builds higher quality, more secure, more easily integrated software. And it does it at a vastly accelerated pace and often at a lower cost. 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 2008 ThoughtWorks Ltd. Page 3 Version: 1.0
Facts about Sahi: Number of downloads till Jul 16, 2007 is 19385 Ranked as 581 in sourceforge.net Activity in sourceforge.net is 99.7% Role of Proxy in Sahi: Two things that happen in proxy---- 1. Script here gets modified in the proxy. The scheduler function gets added into the array and then executed with delay. And all API's get changed to sahi_ 2. The responses coming from the webserver gets injected in the beginning and end with javascript code to help me work with the objects in the app. 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: Recorder and Playback window Show accessor of the element DOM path of the element Value of the element List possible assertions for the element One / more commands can be executed Shows the list of properties like scrollheight, currentstyle etc for the selected element Can view the list of API s 2008 ThoughtWorks Ltd. Page 4 Version: 1.0
Fig - Sahi Controller 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 2008 ThoughtWorks Ltd. 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. 2008 ThoughtWorks Ltd. 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. Screenshot of Cruise Page 2008 ThoughtWorks Ltd. 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. 2008 ThoughtWorks Ltd. 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 2008 ThoughtWorks Ltd. Page 9 Version: 1.0