Friday, June 26, 2009

Parsing XML in Sahi scripts

Sahi uses Rhino as its javascript engine and Rhino has excellent support for handling XML.

Below is a script which reads and asserts XML nodes and attributes. The example has been picked from http://www.ibm.com/developerworks/webservices/library/ws-ajax1/ so that it is easy to experiment with the ibm examples in this script.



var xmlStr = '' +
'<people>' +
' <person gender="male">' +
' <name>Ant</name>' +
' <hair>Shaggy</hair>' +
' <eyes>Blue</eyes>' +
' <height measure="metric">176</height>' +
' </person>' +
' <person gender="male">' +
' <name>Paul</name>' +
' <hair>Spiky</hair>' +
' <eyes>Grey</eyes>' +
' <height measure="metric">178</height>' +
' </person>' +
'</people>';

var $x = new XML(xmlStr);
_assertEqual("Ant", $x.person[0].name.toString());
_assertEqual("Grey", $x.person[1].eyes.toString());

for each (var $p in $x.person){
var $measure = $p.height.@measure.toString();
_assert($measure == "metric");
_assert($p.height > 170);
}


Two points to note:
1) All nodes that you access are of type xml. You will need to use toString() on them before you assert them.
2) Using @ from inside a Browser Action Function (like _click, _assert etc.) causes the script to fail because of a parsing error in Sahi's code. So first assign it to a variable and then use it, like it has been used for $measure. This bug will be fixed in the coming release.

There is a lot more that can be done with the XML object. Have a look at these links:


Tuesday, June 23, 2009

Configuring Eclipse for Sahi

Eclipse's JSDT plugin provides syntax highlighting and verification for Javascript. It can be configured to work well with Sahi scripts too. This video goes through the different steps to configure Eclipse to work with Sahi scripts.


JSDT looks at all functions in the given source folder and can list them in content-assist. Taking advantage of this, we use a dummy definitions file called apis.sah which has all the Sahi APIs. This file, apis.sah, can be downloaded from here and needs to copied into the "scripts" folder.

JSDT is a part of the Web Platforms Toolkit.
It can be installed as a plugin or can be downloaded as a single bundle in the "Eclipse IDE for Java EE Developers (163 MB)" (For windows: eclipse-jee-ganymede-SR2-win32.zip). This is downloadable from http://www.eclipse.org/downloads/

Thursday, June 04, 2009

Increasing interaction with Sahi users

Sahi has been around for about 4 years now. It started in 2005 and was released before or just around the time Selenium RC's first cut was released. But there has been a huge gap in the visibility of Sahi and Selenium. While Selenium seems to be everywhere, Sahi is hardly heard of. After a lot of conversations with different people, this is what we learnt.

1) Sahi is aimed at testers and not developers. Its focus on strong record and playback and on simple scripting, is primarily meant for testers in the Indian industry. These are people who are good at manual testing and automation with tools like QTP, but are not from a programming background. Selenium and Watir on the other hand are aimed at testers and developers who are fine with programming. Unfortunately for Sahi, testers in India who use Sahi, do not blog or voice their opinions on the internet, or contribute back in forums. (Most of those who do, are good technical testers.)  That meant that there was no viral aspect to the spread of Sahi.

2) Very little emphasis was made on Sahi's website or in the program to collect user data. No testimonials, no newsletters, which meant that people were not informed of developments and good user stories to boost their confidence. While the program continued to evolve with releases every two months, few people really saw the progress. 

3) Being aimed at testers and using javascript for scripting, and because of our own lack of savvy in marketing to the internet, Sahi could never become sexy to the blogging bunch. Who would notice when there was Selenium and Ruby to talk about, which could get you more hits and popularity?

While the first and third problem cannot be solved easily, the second is quite addressable. A new section for testimonials and user stories has been added to Sahi Forums. This blog you are reading is being updated with new developments. Updates and news of Sahi can be followed via twitter at _sahi. Presentations on Sahi will be available here

If you are a Sahi user, tweet with #sahi so others may know. If you have a user story do post on the forums.

Wednesday, June 03, 2009

HTTPS Problem Resolution: Unable to tunnel through proxy

Sahi had been using its own custom implementation of proxy tunnelling till a few months back. Owing to a lot of demand for some features, we moved to Java's httpsurlconnection which supported tunnelling through a corporate proxy with authentication. 

But unfortunately a bug in Java's httpsurlconnection was tripping up a few users on some https sites. One case was the failure of websites using login via SiteMinder. 
The exception thrown was  
Unable to tunnel through proxy. Proxy returns "HTTP/1.1 400 Bad Request"

After some research we figured that it was due to this bug 6687282 
Switching to the latest java 1.6.0_14 fixed this issue for us.

Thursday, May 21, 2009

Sahi V2 Release 2009-05-21 is now available!

Sahi V2 2009-05-21 is a stable build. 
Please use and give feedback to make next release more stable. Download here

* Features added
    Optimizations to increase speed.
    Optimized listing of log files.
    Added better error messages for el = null errors.
    Added tests for failing features.

    Added _parentNode(el, tagName, occurrence),
    Added _parentCell(el, occurrence)
    Added _parentRow(el, occurrence)
    Added _parentTable(el, occurrence)
    Added _cell("cellText")
    Added _in() and modified other accessors to take inElement as parameter
    
    saveAs looks at Content-Disposition: attachment to download files
    Added tests around accessor identification
    Test and highlight on the Recorder tab work on selected text
    Temp files saved via "Save As" have session id prefixed to prevent overwrite.

    _near
    _rte for richtext editors based on iframe
    Reset button added to Playback. Does not refresh page.
    _scriptPath added
    _type added to type partial content without blur or onchange.
    moved to chunked encoding

    Added element.visibility_check.strict = false to sahi.properties. This is the default now.  
    Added download.download_if_contentdisposition_is_attachment = false to sahi.properties. 
    Set this to true to automatically download files with header Content-Disposition:attachment. 
    Causes problems with blogger.com profile images.

    Stubs for Sahi's APIs and basic objects like window and document added.
      This allows variable declarations like 
      var $ln = _link("Form Test"); 
      _click($ln);
    Added xhr.wait_when_ready_state_3 to sahi.properties.
      Set to false for cases if some XHRs never reach readyState 4. Needed for gmail.

* Bugfixes

    Playback to recorder tab switch when moving between multiple domains during playback fixed.
    Messages displayed multiple times during retry of step removed. Shows only once.
    Fixed NaN error in _logException and _logExceptionAsFailure.
    Fixed Content-Type related errors for state.js.
    Fixed order of response headers (SignIn Cookie problem).
    Log viewer shows file not found message and does not throw exception on console.

    Autosuggest on Controller Accessor field does not disappear to the right.
    APIs dropdown only lists public APIs of Sahi
    _imageSubmitButton indexes fixed. (Treats alt and title equivalently)
    saveAs NPE fixed

    Fixed traffic logging. It had stopped working after moving to streams.

    Divs are identified as _div instead of _spandiv
    Spans are identified as _span instead of _spandiv

Wednesday, May 20, 2009

Sahi Forums updated

We have upgraded the PunBB version of Sahi Forums. Kudos to the PunBB folks for creating such a nice light weight forum software.

The new Sahi forums have a few nice features, namely:
  • Tagging topics.
  • Sending private messages.
  • Ability to mark a topic "Closed".
  • Private forums for paid customers.
  • Adding attachments (for paid customers).
Have a look at the new forums at http://sahi.co.in/forums

Comments and suggestions are welcome.

Wednesday, April 22, 2009

Sahi V2 Nightly Unstable Build 2009-04-23 Released

Sahi V2 Nightly Unstable Build 2009-04-23 has been released. (Download)

This build has a few significant improvements. It now uses Rhino 1.6R2 as its Javascript engine.

NOTE that this and further builds need Java 1.5 or greater.

* API _near, similar to _in has been added. Any element can be found relative to another by using _near.
Eg.

_checkbox(0, _near(_span("user name 1")))
_link("delete", _near(_span("user name 1")));

* All Sahi accessor API calls can be set to variables now.
Eg.

_click(_link("click me"));
can be written now as


$ln = _link("click me");
_click($ln);


* Check for visibility of elements is now controlled via element.visibility_check.strict property in sahi.properties. It is set to false by default.