Professional Documents
Culture Documents
Introduction
Sahi is an open source-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 in the browser.
Features:
In-browser controls
Intelligent recorder
Text-based scripts
Ant support for playback of suites of tests
Multi-threaded playback from a command line
HTTP and HTTPS support
AJAX support
Sahi runs as a proxy server which intercepts traffic from the web browser and
records the web browsing actions. Sahi can play back those recorded actions by
injecting Javascript into the browser so it can access elements in the web page. This
makes the tool independent of the website/ web application.
Prerequisites
Sahi requires Java 1.4 and above. You can get Java here.
Installing Sahi
You can download Sahi and the source code from here. The latest build (the one at
the top of the list) is the one you want.
Running Sahi
The Sahi proxy server will start and begin listening for traffic on port 9999.
NOTE: by default Sahi uses port 9999. This can be modified through sahi.properties
in the \config directory as 8080.
Now that the Sahi proxy server is running, it's time to configure the web browser to
use it.
Firefox:
Go to Tools > Options > Advanced > Connection Settings >
Set to “Manual Proxy Configuration”
Set “HTTP Proxy” to “localhost”
Set “Port” to “8080”.
Do the same for “SSL Proxy” too, if you wish to record and playback HTTPS traffic
Keep “Use the same proxy for all protocol” unchecked as Sahi does not understand
protocols other than HTTP
NOTE: “No Proxy for” should NOT have localhost or 127.0.0.1 or the domain of the
test application in it.
Internet Explorer:
Go to Tools > Internet Options > Connections > LAN Settings >
In “Proxy server” section, check “Use a proxy server for your LAN”
Set “Address” to “localhost”
Set “Port” to “9999”
Leave “Bypass proxy server for local addresses” unchecked
Click OK > OK
Opera:
Safari:
Now that the Sahi proxy server is running and the web browser is configured to talk
to the proxy, it is time to start using Sahi! We'll start out by using Sahi to navigate a
webpage:
The “Script Directory” field shows you where the script will be saved. By default Sahi
saves to the “scripts” directory.
NOTE: This directory can be changed via sahi.properties in the “config” directory.
Enter “Test” in the “Script Name” text field and press the “Record” button
In the web browser, enter “Sahi” in the Google search box
Now click the “Google Search” button
Click the “Stop” button in the Sahi Controller
So far, so good!
The web browser loads the Google search page, “Sahi” is entered in the search box,
and the button “Google Search” is clicked.
Clicking “Set” loaded the test script and opened the target page for the start of the
test.
Sahi entered “Shai” into the textbox named “q” using the following statement:
_setValue(_textbox("q"), "Sahi");
After the text was entered, Sahi click the submit button labeled “Google Search” with
this statement:
_click(_submit("Google Search"));
Leave the Google results page open and we'll add a test to find an image on the
page....
The “Accessor” indicates that Sahi found the link by the text it contains.
The “Alternative” indicates where Sahi found the link in the Document Object Model
hierarchy.
Clicking the “Assert” button added a condition stating that we believe the link “Sahi”
exists on the web page. By clicking the “Test -->” button, we asked Sahi to verify
that the link existed. The link did exist and to Sahi answered “true”. We added the
assert to the script.
Let's run the script again with the assert added to it:
Success!
We are now able to open a web page, fill in a form, submit the form, and test the
results.
You are encouraged to experiment with setting assertions for different web page
elements and testing for them with Sahi scripts.
Let's find out what the other buttons on the Record tab do...
Open http://www.Google.com/ in the browser again
Click the “Record” tab in the Sahi Controller
Hold down the “Ctrl” key and hover the mouse over the Google search box.
Click the “Props” button in the Sahi Controller
The “evaluate expression” box displays the properties of the Google search box.
You can expand the Sahi Controller by dragging the corners if you need more reading
area.
A red box highlights the search box. This is good technique to use if other people will
be using your Sahi scripts so they know what is being tested.
Hold down the “Ctrl” key and hover the mouse over the “Google Search” button
Click the “Click” button
The Sahi Controller clicks the button for you and the browser navigates to the search
results.
If for some reason you need a Sahi script to pause, you can insert a “Wait” for a
specified number of milliseconds (1000 ms = 1 second).
You can also add comments to your script to denote sections, what you are trying to
test, etc.... A comment is started with "//".
Click the “API List” text box and enter an “_” to view a list of the functions you can
use to drive the web browser.
By default, Sahi loads scripts from the location listed. This directory can be changed
via sahi.properties in the “config” directory
You can share tests across a team by putting the test scripts on a web server instead
of copying the tests to each workstation.
Click the “from url” link at the top of the “Playback” tab
Enter the URL of the test script (e.g. http://www.example.com/Test.sah)
Enter the “Start URL” (e.g. http://www.Google.com/)
Click “Set”
View Script
View Parsed Script
View Queue
View Logs
Click “View Script” and a copy of the test script currently loaded for play back is
displayed in the web brower.
“View Parsed Script” will display the actual code that will executed by Sahi. This is
used for debugging and is not much use unless you are actively developing Sahi
features.
“View Queue” will display the commands being processed by Sahi. Again, this is used
for debugging and is not much use unless you are actively developing Sahi features.
The “View Logs” link is interesting. Clicking it will display a web page with links to the
results of test runs performed by Sahi. The test logs are stored by default in the Sahi
“/logs/playback” directory.
As usual, you can change where Sahi stores the execution logs by modifying
sahi.properties in the “config” directory.
Conclusion
Install Sahi
Configure your browser to use Sahi
Use Sahi to record scripts
Find page web page elements
Test for success using assertions
View test logs
You are encouraged to review the Sahi API. Sahi provides a robust feature set to
assist you in automating your web application testing efforts.
Good luck!
http://sahi.co.in/w/help-the-sahi-controller-does-not-come-up