Sahi my expirience


Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Sahi my expirience

  1. 1. Sahi TutorialIntroductionSahi is an open source testing tool for web applications, with the facility to record and playbackscripts. Developed in Javaâ„¢ and Javascript, this tool uses simple Javascript to execute events inthe browser.Features:In-browser controlsIntelligent recorderText-based scriptsAnt support for playback of suites of testsMulti-threaded playback from a command lineHTTP and HTTPS supportAJAX supportSahi runs as a proxy server which intercepts traffic from the web browser and records the webbrowsing actions. Sahi can play back those recorded actions by injecting Javascript into thebrowser so it can access elements in the web page. This makes the tool independent of thewebsite/ web application.Sahi is similar to Selenium ( but is not browser specificlike Selenium is. Sahi works with Firefox, Internet Explorer, Opera, and Safari whereasSelenium is Firefox only. In addition, Selenium has to be deployed to the server the webapplication resides on. Sahi just needs a browser that can display the web application.Sahi is released under the Apache License, Version 2.0.PrerequisitesSahi requires Java 1.4 and above. You can get Java here.Installing SahiYou can download Sahi and the source code from here. The latest build (the one at the top of thelist) is the one you want.Unzip to a convenient directory of your choosing. Thats it!
  2. 2. Running SahiNavigate to the Sahi directory you extracted and:Windows: Go to bin and run sahi.batLinux and Mac: Go to /bin and run sahi.shThe 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 in theconfig directory.Now that the Sahi proxy server is running, its time to configure the web browser to use it.Configuring the browserFirefox:Go to Tools > Options > Advanced > Connection Settings >Set to "Manual Proxy Configuration"Set "HTTP Proxy" to "localhost"Set "Port" to "9999".Do the same for "SSL Proxy" too, if you wish to record and playback HTTPS trafficKeep "Use the same proxy for all protocol" unchecked as Sahi does not understand protocolsother than HTTPNOTE: "No Proxy for" should NOT have localhost or or the domain of the testapplication 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" uncheckedClick OK > OKOpera:Go to Tools > Preferences > NetworkClick "Proxy servers" buttonCheck "HTTP"
  3. 3. Enter localhost in the textboxEnter "9999" for PortClick Ok > OkRepeat the above if you wish to record and playback HTTPS trafficSafari:Go to Edit > PreferencesSelect "Advanced"click "Change Settings" for ProxiesClick "LAN Settings" buttonIn "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" uncheckedClick OK > OKTesting with SahiNow 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! Well start out by using Sahi to navigate a webpage:Open in your web browserAfter Google loads, hold down the Ctrl and Alt keys and then double-click the web page.The Sahi Controller should now appear:
  4. 4. The Sahi Controller has two tabs: Record and Playback. We will start by recording thenavigation steps.The "Script Directory" field shows you where the script will be saved. By default Sahi saves tothe "scripts" directory.NOTE: This directory can be changed via in the "config" directory.Enter "Test" in the "Script Name" text field and press the "Record" buttonIn the web browser, enter "Sahi" in the Google search box
  5. 5. Now click the "Google Search" buttonClick the "Stop" button in the Sahi ControllerSo far, so good!Now to play back what we just recorded:Click the "Playback" tab in the Sahi ControllerSelect "Test.sah" in the "File" selection listEnter "" in the "Start URL" text fieldClick the "Set" buttonWait for the web page in the browser to reloadClick the "Play" button
  6. 6. The web browser loads the Google search page, "Sahi" is entered in the search box, and thebutton "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 thisstatement: _click(_submit("Google Search"));
  7. 7. And finally Sahi signaled that the test was successful: --Stopped Playback: SUCCESS--Leave the Google results page open and well add a test to find an image on the page....Click the "Record" tab againEnter "Test" in the "Script Name" text boxClick the "Record" buttonHold down the "Ctrl" key and move the mouse cursor over the link for "Sahi" in the searchresultsClick the "Assert" buttonClick the "Text -->" buttonClick the "Apend to Script" buttonFinally, click the Stop button
  8. 8. Notice that the "Accessor" and "Alternative" fields have been filled in.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 onthe 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.Lets run the script again with the assert added to it:
  9. 9. 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 andtesting for them with Sahi scripts.A Closer Look At The Sahi Controller
  10. 10. Lets find out what the other buttons on the Record tab do...Open in the browser againClick the "Record" tab in the Sahi ControllerHold down the "Ctrl" key and hover the mouse over the Google search box.Click the "Props" button in the Sahi ControllerThe "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.Click the "Hilight" buttonA red box highlights the search box. This is good technique to use if other people will be usingyour Sahi scripts so they know what is being tested.In the "Value" text box, enter "Sahi is great"Click the "Set" buttonThe Sahi Controller enters "Sahi" in to the Google search box.Hold down the "Ctrl" key and hover the mouse over the "Google Search" buttonClick the "Click" buttonThe 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 specifiednumber of milliseconds (1000 ms = 1 second).
  11. 11. You can also add comments to your script to denote sections, what you are trying to test, etc.... Acomment is started with "//".
  12. 12. Click the "API List" text box and enter an "_" to view a list of the functions you can use to drivethe web browser.Lets go check out the rest of the Playback tab...
  13. 13. At the top of the tab you have the option telling Sahi where to load the test scripts from.By default, Sahi loads scripts from the location listed. This directory can be changed in the "config" directoryYou can share tests across a team by putting the test scripts on a web server instead of copyingthe tests to each workstation.Click the "from url" link at the top of the "Playback" tab
  14. 14. Enter the URL of the test script (e.g. the "Start URL" (e.g. "Set"The process should be familiar to you...At the bottom of the Playback tab you will find:View ScriptView Parsed Script
  15. 15. View QueueView LogsClick "View Script" and a copy of the test script currently loaded for play back is displayed inthe web brower."View Parsed Script" will display the actual code that will executed by Sahi. This is used fordebugging 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 fordebugging 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 resultsof 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 inthe "config" directory.ConclusionThat wraps up the tutorial for Sahi!You should now know how to:Install SahiConfigure your browser to use SahiUse Sahi to record scriptsFind page web page elementsTest for success using assertionsView test logsYou are encouraged to review the Sahi API. Sahi provides a robust feature set to assist you inautomating your web application testing efforts.You are also encouraged to visit the support forum at for helpand to contribute to the Sahi community.Good luck!