Showing posts with label Sahi. Show all posts
Showing posts with label Sahi. Show all posts

Thursday, April 02, 2009

Syntax Highlighting for Sahi Code

I have added syntax highlighting to my blogs now. Used Alex Gorbatchev's SyntaxHighlighter 2.0 which is awesome. I added a Sahi brush to SyntaxHighlighter so that keywords in Sahi would also be highlighted.

This is what shBrushSahi.js looks like:

SyntaxHighlighter.brushes.SahiScript = function()
{
var keywords = 'abstract boolean break byte case catch char class const continue debugger ' +
'default delete do double else enum export extends false final finally float ' +
'for function goto if implements import in instanceof int interface long native ' +
'new null package private protected public return short static super switch ' +
'synchronized this throw throws transient true try typeof var void volatile while with';

var schedulerFns = '_alert _assertEqual _assertNotEqual _assertNotNull _assertNull _assertTrue _assert _assertNotTrue _assertFalse _assertExists _assertNotExists _callServer _click _clickLinkByAccessor _dragDrop _resetSavedRandom _setSelected _setValue _simulateEvent _call _eval _setGlobal _wait _popup _highlight _log _navigateTo _callServer _doubleClick _rightClick _addMock _removeMock _expectConfirm _setFile _expectPrompt _debug _debugToErr _debugToFile _mouseOver _keyPress _focus _keyDown _keyUp _mockImage _execute _assertContainsText _enableKeepAlive _disableKeepAlive _dragDropXY _deleteCookie _createCookie _clearPrintCalled _saveDownloadedAs _clearLastDownloadedFileName _rteWrite';

var browserFns = '_accessor _button _check _checkbox _image _imageSubmitButton _link _password _radio _select _submit _textarea _textbox _event _getGlobal _random _savedRandom _cell _table _containsText _containsHTML _byId _row _getText _getCellText _div _span _spandiv _option _lastConfirm _reset _file _lastPrompt _lastAlert _get _style _byText _cookie _position _print _printCalled _label _lastDownloadedFileName _rteHTML _rteText _re _prompt _getCellText _getSelectedText _scriptName _isVisible _listItem _parentNode _parentCell _parentRow _parentTable _in';

var otherFns = '_getDB _readFile _logException _logExceptionAsFailure _stopOnError _continueOnError _include';

schedulerFns += (' ' + otherFns);


this.regexList = [
{ regex: SyntaxHighlighter.regexLib.singleLineCComments, css: 'comments' }, // one line comments
{ regex: SyntaxHighlighter.regexLib.multiLineCComments, css: 'comments' }, // multiline comments
{ regex: SyntaxHighlighter.regexLib.doubleQuotedString, css: 'string' }, // double quoted strings
{ regex: SyntaxHighlighter.regexLib.singleQuotedString, css: 'string' }, // single quoted strings
{ regex: /\s*#.*/gm, css: 'preprocessor' }, // preprocessor tags like #region and #endregion
{ regex: new RegExp(this.getKeywords(schedulerFns), 'gm'), css: 'color4' }, // operators and such
{ regex: new RegExp(this.getKeywords(browserFns), 'gm'), css: 'color5' }, // operators and such
{ regex: new RegExp(this.getKeywords(keywords), 'gm'), css: 'keyword' } // keywords
];

this.forHtmlScript(SyntaxHighlighter.regexLib.scriptScriptTags);
};

SyntaxHighlighter.brushes.SahiScript.prototype = new SyntaxHighlighter.Highlighter();
SyntaxHighlighter.brushes.SahiScript.aliases = ['sahi', 'sahiscript'];


And this is what I added to my blogger template:


<script src='http://sahi.co.in/static/syntaxhighlighter/scripts/shCore.js' type='text/javascript'/>
<script src='http://sahi.co.in/static/syntaxhighlighter/scripts/shBrushJScript.js' type='text/javascript'/>
<script src='http://sahi.co.in/static/syntaxhighlighter/scripts/shBrushSahi.js' type='text/javascript'/>
<link href='http://sahi.co.in/static/syntaxhighlighter/styles/shCore.css' rel='stylesheet' type='text/css'/>
<link href='http://sahi.co.in/static/syntaxhighlighter/styles/shThemeDefault.css' rel='stylesheet' type='text/css'/>
<style>
.syntaxhighlighter .color4, .syntaxhighlighter .color4 a{color: #000A7F !important;}
.syntaxhighlighter .color5,.syntaxhighlighter .color5 a{color: brown !important;}
</style>
<script type='text/javascript'>
SyntaxHighlighter.config.clipboardSwf = 'http://sahi.co.in/static/syntaxhighlighter/scripts/clipboard.swf';
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.all();
</script>


Note that, in blogger, <br> tags will be visible in the code in place of new lines if you do not add
SyntaxHighlighter.config.bloggerMode = true;


So now Sahi scripts on the blog will look like this:


function search(){
_setValue(_textbox("q"), "sahi");
_click(_submit("Google Search"));
_assertExists(_link("Sahi"));
}
function goToForums(){
_click(_link("Sahi"));
_click(_link("Forums"));
}
function logout(){
if (_condition(_link("Logout"))){
_click(_link("Logout"));
}
}
function login($username, $password){
_click(_link("Login"));
_setValue(_textbox("req_username"), $username);
_setValue(_password("req_password"), $password);
_click(_submit("Login"));
_assertExists(_listItem("Logged in as "+$username));
}

search();
goToForums();
logout();
login("sahitest" "khuljasimsim");

Sunday, August 31, 2008

Sahi V2 20080831 Released

After close to a month of development, Sahi V2 20080831 has been released today. (http://sahi.co.in/w/)

This release uses Rhino as the scripting engine, thus moving most of the script execution to the proxy. This should go a long way in simplifying Sahi scripts. Scripts now execute on the proxy, and only stuff that needs to execute on the browser is sent to the browser. Thus scheduler functions are sent to the browser for execution. One change which has come in is that custom functions which may have been added for identification of browser elements, now need to be wrapped in a <browser></browser> tag so that they are also sent to the browser.

This build also has some important changes to the SocketPool which will fix issues related to too many sockets being used and errors due to BindExceptions. Suite execution has been changed such that even if the browser crashes, the suite will continue with the next script and thus not hold up a build. DB methods now close connections properly.

There will still be a few rough edges and I hope users will report bugs so that they are easily fixed. Meanwhile, help spread the message through your blogs or email forums.

Sahi V2 20080831 Released

After close to a month of development, Sahi V2 20080831 has been released today. (http://sahi.co.in/w/)

This release uses Rhino as the scripting engine, thus moving most of the script execution to the proxy. This should go a long way in simplifying Sahi scripts. Scripts now execute on the proxy, and only stuff that needs to execute on the browser are sent to the browser. Thus scheduler functions are sent to the browser for execution. One change which has come in is that custom functions which may have been added for identification of browser elements, now need to be wrapped in a tag so that they are also sent to the browser.

This build also has some important changes to the SocketPool which will fix issues related to too many sockets being used and errors due to BindExceptions. Suite execution has been changed such that even if the browser crashes, the suite will continue with the next script and thus not hold up a build. DB methods now close connections properly.

There will still be a few rough edges and I hope users will report bugs so that they are easily fixed. Meanwhile, help spread the message through your blogs or email forums.

Thursday, August 21, 2008

Sahi - Latest developments

Copy of post on forum: http://sahi.co.in/forums/viewtopic.php?id=261

I had not been active on the Sahi forums (http://sahi.co.in/forums) for sometime. Thanks a ton to StringyLow, tinchie8, lepierrot, pankaj.nith and others for keeping this forum active, and replying to posts.

Meanwhile I have been working on a version of Sahi which attacks one of the basic problems with Sahi.
Scopes of variables, scheduler and normal functions and the the way steps are queued and executed and the way their integrity needs to be maintained across page loads.

The problem had been that the scripts (after parsing) were executed on the browser itself, and when a page unloads, the state of the script's execution needed to be persisted on the proxy and then resurrected when the next page loaded. While this allowed the ease of using javascript for scripting, when scripts became bigger, the browsers and the proxy had to do a lot more persisting and resurrecting.

As the logical next step, I wanted to move this script execution to the proxy. I now use Rhino, an excellent javascript engine, to execute the scripts on the proxy. Only steps that need to be executed on the browser are sent to the browser. Javascript can still be used for Sahi scripting. Even though the script still is parsed, it is much simpler to understand script execution than it was before. Rhino also comes with a debugger which can prove useful to Sahi script debugging.

The version is slated to be released soon. I am looking for volunteers to test and give me feedback about the new version. If you have existing scripts, the scripts may need to be modified a little to make it work with the new version.
If you are interested, please post back or email me at narayan at sahi.co.in.

Wednesday, December 19, 2007

Javascript sleep() or wait() in Sahi

My previous post on 'Javascript sleep() or wait()' is visited a lot of times and I think I should write how the problem was eventually solved in Sahi.

Sahi needs to playback scripts written in javascript on the browser.
Let us consider a small example:

We are trying to automate an AJAXy mail client application which has an Inbox button, which when clicked, loads a part of the page, and this newly loaded content has a link 'Unread'.


_click(_button('Inbox'));
_click(_link('Unread'));


When the first line is executed, the Inbox button gets clicked and the script has to wait till the relevant portions of the page load, before it can click 'Unread'.

To solve this, Sahi has a script parser which modifies this script to look something like this:


steps = new Array();
steps[steps.length] = "_click(_button('Inbox'));";
steps[steps.length] = "_click(_link('Unread'));";


And to execute these steps, it does:


var currentStep = 0;
function execute(){
if (currentStep == steps.length) return;
window.eval(steps[currentStep]);
currentStep++;
window.setTimeout('execute()', 1000);
}

execute();


Hope this helps people who are looking for a solution for javascript sleep.

Thursday, November 29, 2007

Sahi at FOSS.in

I will be presenting on the internal workings of Sahi at FOSS.in at Bangalore. This is not a demo level session but will involve a deep dive into the internals of the proxy, the script, extending the proxy, adding new APIs and other unmentionables. Hope to meet some interested and interesting people there.

Wednesday, October 10, 2007

Sahi no longer needs waiting for AJAX calls

A new version of Sahi has been released. Download from https://sourceforge.net/project/showfiles.php?group_id=151639

More details on the release are here: http://sahitest.blogspot.com/

Sunday, June 24, 2007

Vote for Sahi on SourceForge Community Choice Awards 2007

If you like Sahi, nominate and vote for it in the SourceForge Community Choice Awards 2007.
Ask your friends, colleagues and other bloggers to express support too. Thanks :)

http://sourceforge.net/projects/sahi

Friday, February 02, 2007

Sahi Nightly Build 2006-02-02 released

Released another version of Sahi.
Added a few fixes to the release made 2 days back.

This is a fairly major release with the following changes:

* APIS added
_mockImage(pattern, clazz)
_assertContainsText(expected, el, msg)
_enableKeepAlive()
_disableKeepAlive()
_style(el, property)
_execute("commandline command");

* Feature additions
Test status on Controller
Launch test from command line
Add line numbers to script in logs
Back button support
Keep-alive support to tackle too many connections in TIME_WAIT issue
regular expression support in all APIs
Safari support
junit style logs added
jira issue tracking added

* Bugfixes
_condition when used with _include was stopping execution of script.

Of significance is the regular expression support in APIs.

So if you wanted to find a link which looks like "my_link_KJHSA" you could just do _link(/my_link_.*/).
Most APIs which took strings as parameters can now take regular expressions.

The communication between the browser and Sahi now uses Keep-Alive thus solving the major issue of too many connections in TIME_WAIT state.

Documentation is still being added for the new features on http://sahi.co.in

Sahi Nightly Build 2006-02-02 released

Released another version of Sahi.
Added a few fixes to the release made 2 days back.

This is a fairly major release with the following changes:

* APIS added
_mockImage(pattern, clazz)
_assertContainsText(expected, el, msg)
_enableKeepAlive()
_disableKeepAlive()
_style(el, property)
_execute("commandline command");

* Feature additions
Test status on Controller
Launch test from command line
Add line numbers to script in logs
Back button support
Keep-alive support to tackle too many connections in TIME_WAIT issue
regular expression support in all APIs
Safari support
junit style logs added
jira issue tracking added

* Bugfixes
_condition when used with _include was stopping execution of script.

Of significance is the regular expression support in APIs.

So if you wanted to find a link which looks like "my_link_KJHSA" you could just do _link(/my_link_.*/).
Most APIs which took strings as parameters can now take regular expressions.

The communication between the browser and Sahi now uses Keep-Alive thus solving the major issue of too many connections in TIME_WAIT state.

Documentation is still being added for the new features on http://sahi.co.in

Friday, October 20, 2006

Sahi - New Website

Sahi has a new look and location at http://sahi.co.in.

A new release (Nightly Build 2006-10-20) of Sahi is also available. Download from here

Saturday, August 05, 2006

Blog for Sahi

Created a new blog for Sahi since there seem to be too many posts just on Sahi here.

That said,
Release 2006-08-06 with file upload facility has just come out

Toggling proxy on IE became easier with toggle_IE_proxy.exe and ProxyPal

And tons of thanks to Sriram Narayanan (Ram) for creating toggle_IE_proxy.exe
Seen few people who attack someone else's problem with such vigour and effect.
Taught me something...

Sunday, July 30, 2006

Automated file uploads, anyone?

Inspite of browsers playing spoil sport,
Sahi now handles file uploads too!

The strategy was to intercept the request in the proxy, read the file off the file system and insert it into the multipart request.

A workaround yes, but it at least works around!

Good thing is, it even records and plays back the file upload.

Code?
_setFile(_file("id"), "C:\\abc\\efg.jpg");

The file has to be present on that path on the machine running the proxy.

Coming up in the next build ...

Friday, June 09, 2006

Sahi Nightly Build 2006-06-06 released

Tested with 200 consecutive tests.

Made the following changes:

* Fixed bug for some submitted pages not working properly on IE
* Added socket pool to prevent Connect exceptions when there are a lot of tests
* Fixed bug to prevent injection of html code into js files
* Added documentation for _callServer and a few other apis
* Displaying an error page when remote server is down. Tests do not stop anymore.

Friday, May 19, 2006

Sahi Flash Tutorial

A Flash tutorial has been added to the Sahi home page.
It can be accessed at http://sahi.sourceforge.net/sahi_tutorial.html

If you like it, spread the word.

Monday, May 15, 2006

Sahi Nightly Build 2006-05-15 released

Release 2006-05-15 is a very enhanced release.
It contains the following fixes:

SSL certificates for proxy are generated automatically and on demand using keytool.
This fixes the security alerts problem.
Triggering keyboard events when value is set to textboxes.

Fixed bug which caused improper functioning in popups.
Fixed bug which caused null pointer exception when content type was not set.
Fixed bug where _table(index) was not working properly.
Fixed bug for multiple submit buttons on IE.

Thursday, May 11, 2006

Sahi ranked 55 out of 118720 projects

Current Sourceforge ranking of Sahi is 55.
Out of a total of 118720 projects.
Never dreamed of under 100.
Hope sourceforge does not say "we have a flaw in the statistics" ...

Wednesday, May 10, 2006

Under 150

Sahi's sourceforge ranking is now 146.
Today's ego boost :)

http://sourceforge.net/project/stats/?group_id=151639&ugn=sahi

Sahi - HTTPS support

Another 6 hrs of late night work yesterday
and I have almost all my https woes solved.
Even though Sahi could handle https before,
it was using a single certificate for all https websites,
causing browsers to report mismatch in the certificates.
With a mix and match of on demand generation of certificates using keytool,
and per website creation of certificates and some caching,
I have Sahi handling SSL so smoothly that
all I have to do is accept the certificates just once,
when I first visit a site and then totally forget about it.

If you have a https website to test, it is going to be a no brainer to automate it using Sahi. Await the next release. I shall post soon.

Now the only big issue left is web pages from multiple domains embedded into the frames of a frameset.

Of course there are a few bugs ... ;)

Monday, April 24, 2006

Sahi - Nightly Build 2006-04-24 released

This release of Sahi has the following changes:

The whole code base has been rewritten to be easily extendable.
Various optimizations have been made for speed.
This release includes a few important bugfixes related to cookies.
APIs
_dragDrop(elementToDrag, targetElementToDropOn)
and
_callServer("ServerClass_method") have been added.

Documentation has been given a face lift.

Check out http://sahi.sourceforge.net/ for the changed look and feel.

A mailing list sahi-users@lists.sourceforge.net has also been created.