Sahi is an open source automation tool for browser based testing. Following is a representative conversation between someone new to Sahi and the Sahi team.

Q: What is Sahi?
A: Sahi is a tool that helps automate testing of browser based applications. It is released under an Apache 2 license.
If you work with web applications, you need to test the product before each release. Testing can be done manually but it may take a long time and may become repetitive and boring. Automation can make this testing (or checking) very fast and free up the tester for more useful exploratory testing. Typically a 1000 script suite can be executed in as less as 6-8 hours. This means that regression tests can run overnight and you can have results when you come in the next morning.

Q: But does it not take a lot of effort to create and write scripts and maintain them? We had once attempted it and failed!
A: Success in browser automation depends a lot on the tool you use. Browser technology has advanced significantly and most tools are unable to keep up with browsers for automation. Sahi’s architecture, however, allows automation of any browser new or old, as long as they support proxies and javascript (which all browsers do)

Q: Really? How does Sahi work?
A: To use Sahi, the browser is configured to use Sahi as its proxy. Once configured, all HTTP requests and responses pass through Sahi. Sahi then injects javascript in relevant HTTP responses. This javascript allows recording of user actions and simulation of events for playback.

Q: Sahi has a recorder? Is a recorder helpful? I have heard that record and playback is frowned upon.
A: Sahi has a good recorder for recording user actions. Good recorders are excellent time savers for testers. Pure record and playback does not work however. The recorder is used to record snippets of code and then functions are created which are reused in scripts. Nevertheless, the recorder (or rather the object spy) saves 30 to 40% time spent in identifying elements and creating user flow.

Q: Oh, so do I need to know programming? Does it involve coding?
A: Some level of programming/coding knowledge would be required. Sahi’s scripting language is Sahi Script which is an extension of Javascript. Javascript is one of the easiest languages to learn and use especially if one writes simple procedural code as is normally needed in testing.

Q: Why not use Java or C#?
A: Sahi has Java and Ruby drivers. However, testers find Sahi script to be the easiest to work with. Choose which ever works for your business (Note: not you, but your business. It should be simple, easily learnt and maintainable by a normal testing team, without specialist automation experts)

Q: But Javascript cannot read files etc. right?
A: Not really. Javascript on the browser has restrictions. Sahi’s script executes inside a Java process. You can read/write files, connect to databases, and do pretty much anything that Java can.

Q: I have heard that testing code is like development code. It needs to be architected, refactored and maintained like production code?
A: No this is not correct. Automation code SHOULD be simplistic without too many conditions/loops/inheritance etc. It is even OK to have duplication in automation code. If a script fails, one should be able to right away suspect the application under test rather than the testing code. This can only happen if the testing code is trivially simple.

Q: That was a useful digression on automation code. Coming back to Sahi, how does Sahi work with various browsers? Do I need to write separate scripts for each browser?
A: No. A script written for one browser will work on any browser. Sahi takes care of normalizing the differences across browsers.

Q: How does Sahi identify elements?
A: Javascript exposes a lot of attributes in the DOM. DOM is the programmatic hierarchical representation of the HTML structure in a page. Sahi uses any of the element’s DOM attributes to identify elements. For example, a button may be identified by the visible text, id, name, css className etc. Sahi’s Controller shows all the identification alternatives that are possible for an element.

Q: XPaths?
A: XPaths are frowned upon in Sahi. XPaths are normally used to traverse data represented as XML. HTML structures are not really data but UI representations and are prone to modification. XPaths starting from the root node are almost never useful. One has to then modify it using a regular expression. When a script fails, the first suspect is normally the expression and not the AUT. This wastes a good amount of tester’s time. There are also differences in XPath implementations which add to the tester’s troubles.

Q: What about dynamic ids?
A: When an element is not identifiable by any of its own attributes, you can use a relation like, _in, _near, _under etc. to identify one element relative to another.
For example,

A textbox with label “Loan Amount” becomes
_textbox(0, _near(_label(“Loan Amount”)))

The cost becomes
_cell(0, _near(_div(“My product one”)), _under(_div(“Cost”)))

The expand collapse icon becomes
_image(“/tree-node-icon/”, _near(_span(“Expand me”)))

Also note that Sahi can use a regular expression at any place that a string can be used.

Q: One of the main problems in our current browser automation is that we need to add waits everywhere. Can you add waits in Sahi?
A: In 99% cases, Sahi does not need waits. Sahi automatically waits for page/frame/iframe loads and also for any AJAX activity. Even after waiting if a step fails, Sahi retries it 5 times at 2 second intervals before it reports a failure. Due to this Sahi scripts are very stable and have very few false negatives.

Q: My application uses lots of frames and iframes. How does Sahi handle this?
A: Sahi automatically traverses frames and iframes to identify elements. One does not need to specifically choose a frame before working with it.

Q: What about popup windows?
A: Popup windows is a loose term. Some people refer to javascript alerts, confirms and prompts as popups. These popups are suppressed by Sahi during playback, but you can control them in script.
The other kind of popup are the popup windows. Sahi allows switching to another window and working on it.

Q: Does it support file uploads and file download dialogs?
A: File uploads are handled in a round about way in Sahi. Sahi adds the file to the HTTP request via the proxy. For file downloads, files are automatically downloaded to a temp location by Sahi and the script allows interaction with these files.
The file upload part can get tricky in HTML5 apps on some browsers, so you may need to resort to native events which are supported in Sahi Pro.

Q: OK, once I have a few scripts, can I run them in batch? Can I hook into my Continuous Integration system?
A: Yes Sahi has a concept of suites. Suites can be triggered from .bat files, shell scripts and ant. You can trigger Sahi scripts from CI systems using its ant target.

Q: Do we need to build reporting logging etc.?
A: No, Sahi automatically logs all statements that are executed, without the tester adding any code. It also builds a summary report in HTML of all script executions in a suite.

Q: How long has Sahi been around? When is the next release?
A: Sahi has been around since 2005. The next open source release is slated for end of April 2014.

Q: What about support?
A: One can get help from the Sahi forums at http://sahi.co.in/forums. Commercial support is available for Sahi Pro.

Q: That was useful! Let me check it out in the next sprint!
A: You are welcome! Wish you happy hassle free testing with Sahi!

Know more about sahi at –
http://www.sahi.co.in

https://i0.wp.com/www.testingcircus.com/wp-content/uploads/Sahi-Automation-Tool.png?fit=642%2C300&ssl=1https://i0.wp.com/www.testingcircus.com/wp-content/uploads/Sahi-Automation-Tool.png?resize=150%2C150&ssl=1Narayan RamanArticlesTools & TutorialsOpen Source Testing Tools,Testing Article,Tools TutorialsSahi is an open source automation tool for browser based testing. Following is a representative conversation between someone new to Sahi and the Sahi team. Q: What is Sahi? A: Sahi is a tool that helps automate testing of browser based applications. It is released under an Apache 2 license. If you...