Compared to other web testing tools, Sahi controller (IDE) can be used in various browsers.
Sahi's APIs do not depend much on the HTML structure. Sahi does not use XPaths and has APIs like _near, _in etc. to help finding one element in relation to another. Even if the structure of the page changes, these work properly. Our client website is an ExtJS site; Sahi is helpful in dealing with the changing pages.
First of all, we can download the latest Sahi zip file from sourceforge. The prerequisite for Sahi is JRE 1.4 or above.
- Unzip sahi.zip to a desired location.
- Navigate to \bin to start sahi proxy server.
- Next, config the browser to use sahi proxy.
After finishing the setup, we can start creating scripts. The scripts can be written using any text editor with the facility of recording by controller. Press ALT and double click on the window, which you want to record.
The controller is as below:
- On the popup that appears, give a name for the script you wish to generate, and click 'Record'
- Most actions on the page will now get recorded.
- Clicking the "Add Assertions" button generates assertions for the element. These assertions can be added to the script by clicking "Add to Script".The script being generated can be viewed by opening the .sah file in the scripts directory. The script can be edited even while recording, so that logical segregation into functions etc. can be done while recording happens.
- Once done, click stop.
Note that custom code can be tested, by entering code in the "debug" text area and clicking on "Test->". The command will be executed and the result will be displayed in the textbox near the” Test->"button.
Once confirmed that the desired result has been achieved, that code snippet can be added to the recording by clicking "Append to Recording".
- Open (alt-dblclick) the popup window.
- Select script file from the dropdown.
- Or go to the "[from url]" section and specify the full URL of the script file. (e.g. http://proxyhost:proxyport/_s_/scrcipts/scriptName.sah)
- Click 'Set'.
- Wait for the pages to reload.
- Click 'Play'.
Multiple tests can be run through ant. For each test in the suite, the ant target opens a browser, runs the test and closes the browser. The ant target specifies a suite file, say SuiteName.suite.
Data Driven Testing
Sahi has some inbuilt features for data driven testing. Sahi can read and write to CSV (Comma Separated Value) files, databases and Excel sheets.
- _readCSVFile (csvFilePath) reads a CSV file and returns a two dimensional array.
- _writeCSVFile (array2D, filePath) writes the two dimensional array into a file in CSV format.
View Sahi in-detail with more examples in part 2 of this article.