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.

Tuesday, December 11, 2007

java -cp does not work?

Was trying to get Sahi's batch and shell scripts to work properly since I get a lot of queries regarding database drivers not being found instpite of adding to the classpath.

The problem is this. I need to add a mysql driver to Sahi's classpath so that the scripts can access the driver to do some data driven testing.

So I had to add the mysql driver to this:

java -jar ../lib/sahi.jar

Trivially, I added a -cp option so the command looks like this:

java -cp ../extlib/mysql-connector-java-5.0.4-bin.jar -jar ../lib/sahi.jar

But this does NOT work. Why? Because an executable jar should have its classpath in its manifest file and not outside.

The way to solve this is to use:

java -cp ../extlib/mysql-connector-java-5.0.4-bin.jar;../lib/sahi.jar net.sf.sahi.Proxy

So I made these changes on my windows machine, and it worked. Then logged on to my newly installed ubuntu to check if the shell script works with the same changes.

Made the necessary semi-colon to colon conversion in the classpath, so it looks like this.

java -cp ../extlib/mysql-connector-java-5.0.4-bin.jar:../lib/sahi.jar net.sf.sahi.Proxy

The sahi.sh file has a few other lines too.

When I ran sahi.sh, it gave me a NoClassDefFound error for net/sf/sahi/Proxy! After hunting around quite a bit on the net to see if there was such a problem on linux, I realized that nobody on the forums seems to understand the problem even when somebody reported it.

Eventually I realized that since I had edited the file in windows, it was adding ^M characters at the newlines which was not being recognized by the shell. So I used another editor and got rid of them by deleting and reentering the newlines. (I could also have used dos2unix, but did not have it installed on my machine)

I also realized why the people in the forums did not understand the problem. Most of the replies were from people using linux all the time and the question posters would have mostly been using windows but since the problem was on a linux machine would have posted the question on linux forums!

Anyway, now things work properly :)

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.

Sunday, November 18, 2007

Cycling trip to god knows where

The cycle had been well over hauled. Had to replace the fork, both tyres and tubes. But the result was good. A very smooth, no hassles ride. The gear shifts were working well and the rolling was good. Except for the loose pedal shaft which had worn out and kept shaking and threatened to come off anytime. Saturday morning I set out from home at around 9, got the pedal shaft replaced and was on my way by 9.25. Was to meet Shrik near my office which was a good 17 kms away. Reached the office by 10.10. 45 minutes was a decent time and made me feel that I could go the office on cycle at least once a week. Had a vada pav and lime juice.

Shrik's Hero Octane looked good, and we started at 10.30 towards Hinjewadi. Past Hinjewadi, towards Paud, and we were in the villages and we kept going uphill and then eventually had a long long descent. Rested at the end of it. Had a limca and decided where to go next. Turned right on some local advice and went on a really bumpy bad road for quite a distance. The scenery around was good though it was all villages. Suddenly we were pleasantly surprised to see three woolly necked storks on the side on an inundated field. Took a few snaps and moved on in search of some hotel to eat.



We saw a lot of sugar cane laden tractors and got a sugarcane from one of them. Had some of it and washed ourselves in a nallah. Eventually found a hotel, but we could not get any meals there. Just had vada sambar, pav and a tea. The hotel guy suggested we go a little ahead and go to a Satya Sai temple nearby if we wanted to have a nap. So off we went to the temple, but it turned out to be one steep climb. Half way through we came across a short cement platform and we parked right there and went off to doze in the shade. Half an hour later, a little refreshed, we proceeded and came across Tikona on the right and a lovely lake on the left. It was beautiful. Ahead, after a friendly water break with some locals, we hit a steep long ghat road which was quite a challenge to go up. At the top, rested for a while with tea and a cream roll. Moved on from there down a lovely steep winding road, and then climbed again all the way to the Kamshet Dam and then downhill again to Pavana nagar village. At a fork where Kamshet was 10 kms to the left, we decided to go right because we were told that the highway was closer in that direction. Was that a mistake! We cycled for a long long distance with no sign of a highway. Twilight became night and we were either guided by the less than half moon, or blinded by the oncoming vehicles. Had a very needed halt where we hogged five bananas each and to wash off the sweet taste I had a tomato too! Tried to hitch a ride back with a few vehicles but no luck. So we kept going and eventually, we went over the Bombay Pune expressway, and down further to join the NH4. We went to the nearest dhaba, which was quite comfortable with beds to rest, had a beer and some not so great food, and chilled out for a while.

Around 8.30 we started cycling towards the nearest railway station, Begadewadi, which was hardly a km away from the dhaba thankfully. Got on the Lonavla-Pune local at 9.20 and after getting a few excited and curious glances and comments about our cycles, Shrik got down at Khadki and I at Pune. Pedalled back from the station to home and reached around 10.30, by when Shrik had also reached home. Had a bath and crashed.

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/

Tuesday, September 18, 2007

0=="" is true

Debugging something on Sahi, came across this interesting equality in javascript:

0 == "" is true!

So are:

1 == "1" etc.

An easy way to test these out (and any other single line javascript) is to type

javascript:0==""

on the browser url navigation bar.
Yes, it works on IE and firefox.

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

Saturday, May 26, 2007

Trip to BR Hills

Rashmi and I had been to this place called BR Hills near Mysore. It was early April and it was supposed to be a good time for sighting animals. But we were disappointed to know that a forest fire had burnt very large tracts of the forest and since there was no vegetation for the deer and other grazers, they had all moved away.
But luck was on our side. On the second night, we saw a bear in the moonlight, quite close to our log hut. It was scratching the ground and lazily moving around, making a lot of rustling noises among the fallen dry leaves.
The next day evening, as we were coming back from the safari, we saw a couple of deer, right by our side, totally ignoring us, and staring at something right ahead of us. They called twice, the sharp and loud "cow", the alarm call of the spotted deer. And then, from the grasses to the left, something came out on the road. In a second it vanished around the bend in the road. In a frenzy of excitement we urged the driver to drive down. He had not seen the animal come onto the road, but started driving down slowly to the bend. But the animal was gone.
We looked around, excited, frustrated and expectant. Someone saw a movement on the raised bank on the right. There it was, a full grown leopard, moving stealthily towards cover. A few more moves and the vegetation consumed the cat.
The now very excited driver guessed it must come out again a bit further and he started moving. And then we spotted it again. A magnificent animal, sitting right there, a few feet away, at a height on the raised bank which let us look at it straight in the eyes. I clicked away shaking with excitement. The leopard was just beautiful. I had never seen one so close and for so long. It just sat and looked at us. And slowly moved back, while still sitting, so that it was covered by some undergrowth. This is exactly how a tiger had behaved a few months back in Bandipur. Slowly creep backwards in imperceptible movements but soon be hidden from view behind some neighbouring undergrowth.

And then the leopard started moving. It came down the embankment and walked across the road and then down the curvy road which bent in a U to be parallel with us again. And man, was it brilliant. The leopard moved effortlessly, purposefully, silently, stealthily and man, so beautifully. And it was in full view of us all the time!
15 minutes had gone by and it was still around! Perfect sighting!
And then we started moving towards it, as we had to return to camp, and by then the leopard decided to vanish. And vanish he did. We could not figure out where he went.


We were again rewarded th next day with a bear sighting while we trekked nearby! Quite an eventful and satisfying three days!

Inter-linking of rivers in India is a bad idea

I think inter-linking of rivers in India is a bad idea.
Whenever any friend of mine sounds impressed with this grandiose idea, I have felt frustrated and disturbed. We tend to overlook smaller more effective solutions and go for more romantic and glamorous 'solutions'. So I had been hunting around to gather information on this and make a case of it to people who want to understand what the pros and cons of this effort are. Following are a few links which spell out the danger of going ahead with this plan which does not have enough scientific evidence or prior experience to back it.


The Interlinking of Indian Rivers

Some Questions on the Scientific, Economic and Environmental Dimensions of the Proposal

Paper presented at Seminar on Interlinking Indian Rivers: Bane or Boon?
at IISWBM, Kolkata
17 June 2002

The conclusion of the above goes thus: "At the end of the above review and analysis made on the basis of whatever open information is available on the project for interlinking the rivers in India, there appears a great inconsistency in the declared claims of the project, and their feasibility"


This link, by Shailendra Nath Ghosh, talks about what is wrong with the concept, and what questions need to be answered, to make a proper assessment of this project

More articles and opinions. Quite insightful.

Bangladesh's views on India's inter-linking of rivers (They too oppose this)

Narmada Bachao Aandolan's views in "Dams, Rivers and People": This talks about rehabilitation failures and need for local management and conservation than an imposed, top down solution. They may appear biased because of their image in the press but they are people who have seen and fought unselfishly for rehabilitation of displaced people.

"The proposal is even more dangerous as attempting to link up veins of different persons without trying to find out the blood groups of the individuals. He said consequences will be disastrous." from National Citizens’ Meeting in Delhi concludes: River Link Proposals ill conceived, not in national Interest

More:
ILR in Supreme Court

Bahuguna opposes interlinking of rivers

I have not included any links which talk about the environmental aspects of this inter-linking. While the impact will be enormously destructive, talking about it seems to turn off people because they cannot see how economic growth and environmental conservation can co-exist. (May these lesser mortals exit soon)

So next time you hear of the inter-linking of rivers , doubt it, question it and take the side of what then comes out as true and right.

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