Advertisment

Automate Web App Testing with SAHI

author-image
PCQ Bureau
New Update

Testing is a crucial part of any software development life cycle regardless of the methodology followed. A software defect can cost a company millions of dollars, if not detected at the right time. However, the cost of detecting and correcting the error at the right time and phase is much cheaper. There are different tools available that help automate the testing process and eliminate the repetitive work for testers. SAHI is one such tool which is a testing framework designed specially for web applications. SAHI records and playbacks scripts which help software testers who want to record and play the test. He can then run those test cases without having to manually conduct the constituent steps again and again thereby eliminating repetitive work. For developers, it also has an API categorized in three types. First is Browser Accessor API, which helps in accessing DOM elements in simple ways, for instance, _label. The second is Browser Action API which is responsible for actions like click, while the third is miscellaneous API.

Advertisment
Applies To: Web application testers

USP: Learn how to automate the job of testing web apps

Related articles:Automating the software testing process: http://ld2.in/383

Automate software testing with Selenium: http://ld2.in/384

SAHI is based on Java, so any browser or operating system which supports Java or JavaScript, which most of them do, can support SAHI.

Getting started

Advertisment

You can download SAHI from http://sourceforge.net/projects/sahi/files/. Installation is simple and easy. Once installed, you may need to change the proxy settings of the browser that you shall be using, to use proxy settings of SAHI. To demonstrate how SAHI can be used to record and then create tests, we used Web forms. Web applications contain forms, and it becomes tiresome to fill these forms again and again while testing. We created a web form PCQTest and generated some test cases using SAHI. Once you open SAHI, you will also get a sample application to check its working.

Working with SAHI

Advertisment

Once you click on the SAHI icon you get a small window showing the browsers installed on your system. You can select any browser, where you want to run the test. If you do not get your browser in the list, then you can go to the Configure option and give the path to the browser.

Advertisment

Once your browser window is open you will get a Web page asking you to enter the URL of the Web page that you want to test. Here we entered the URL of PCQTest which we hosted on a localhost. When the page is open, press ALT and double click to open the control windows. It is through a control window that you can record and play the script. Just make sure the pop-up blocker is turned off.

Now in the Record tab of controller window, give a name to the script that you will be recording. We named the script 'test' and recorded the script. All the actions that we were performing on the form PCQTest were getting recorded, like filling up the form, clicking on buttons, etc. We moved the cursor to 'Total' box and pressed 'Ctrl'. With this, you can see the API in Accessor field in Controller window. Now to check whether the assertions are correct, we clicked on the Assert button and the required elements appeared in the 'Evaluate Expressions' window. Now to check whether the assertions are true or not we clicked on Test button and since it was correct we got the value as True.

Advertisment

To check whether the assertions were really correct or not, we changed the value of total in Evaluate Expression field and tested it again. Every time the total value was incorrect the assertion failed giving us the actual value and the expected value.

Now that assertions successfully worked, we clicked on 'Append the Script' to add the assertions to the script and we finally stopped the recording.

Advertisment

Checking and playing the script

After recording the script, you can play it back. We clicked on the Playback tab in the controller window and entered the script name which was Test and then clicked on 'Set' to set the URL of the page. Once it was done we played the script in another browser window. We were able to see the script running automatically and after it finished running, the result showed SUCCESS.

You can also check the logs and scripts. Logs will show you the error, the number of steps taken, failures, success rate, etc. Also you can see the script here. If you want to make changes in the script, you can click on the Sripts option in the window where you get the option to choose the browser. This will let you change the script and you can then run the test with the new script.

So we have seen how this tool spares us from the repetitive task of changing the script manually, by automating the work and saving time.

Advertisment