Frequently Asked Questions on Sahi
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!
Q: Really? How does Sahi work?
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?
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: 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: 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.
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?
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 –