Wednesday, March 10, 2010
 
 

Copy files using Wget

Files can be easily copied from one location to another location in a machine by using “cp” command. However things gets complex when you need to copy files from one machine to another machine. Obviously, your favorite command “cp” is not going to work!

The best solution would to use “rsync” which would transfer the file efficiently. Again, this will not work if the rsync daemon is not configured properly or you do not have ssh access.

The other solution which I used is “wget“. Since wget can download files using HTTP/HTTP/FTP, it seems to be an good solution for me. And Yes, It was!

A simple example of copying directory from remote machine would be

wget -r ftp://<USERID>:<PASSWORD>@<MACHINE-NAME>//home/test

The above command would copy the content (and obviously -r denotes recursively) of /home/test to the local directory ./<MACHINE-NAME>/home/test

Now lets say, you would like to copy the content of /home/test to some other location (for example, say /test/content/data . Following commands will help in doing so.

REMOTE_LOCATION=/home/test
LOCAL_LOCATION=/test/content/data

wget -r --no-host-directories --force-directories \
--cut-dirs=`echo $REMOTE_LOCATION | awk -F"/" '{ print NF }'`\
 --directory-prefix=$LOCAL_LOCATION \
ftp://<USERID>:<PASSWORD>@<MACHINE-NAME>/$REMOTE_LOCATION

Another thing to mention here is, by default, wget would traverse only five level down the directory hirerachy and hence can copy them accordingly. So if you have files in directory structure as /home/test/data/xyz/content/resources/site1/css, contents of that would never be copied by wget. If you need to do so, you should specify depth level also in your command as

REMOTE_LOCATION=/home/test
LOCAL_LOCATION=/test/content/data

wget -r --level=9 --no-host-directories --force-directories \
--cut-dirs=`echo $REMOTE_LOCATION | awk -F"/" '{ print NF }'` \
--directory-prefix=$LOCAL_LOCATION \
ftp://<USERID>:<PASSWORD>@<MACHINE-NAME>/$REMOTE_LOCATION

wget is nice (specially when you do not have the options to use rsync or rcp/scp). Try it!

Complete options for wget can be browsed at http://www.gnu.org/software/wget/manual/wget.html

 

Selecting ExtJS Grid Row using Watir

Grid is the most powerful widget in ExtJS and it becomes tricky at times to write test cases using Watir. One of the instance which I faced was selection of any row in grid with watir script.

From the script, I tried to find the DIV element of grid for the row using the class tag and fired the click event

1
$browser.div( :class => "x-grid3-row", :index => 10 ).click

The script immediatley highlighted 10th row in grid but did not get selected (Normally Grid row changes appearance when it gets selected). I tried the other way (firing mousedown event, thinking it would work ) as

1
2
$browser.div( :class => "x-grid3-row", 
                   :index => 10 ).fire_event( "onmousedown" )

Still no luck! It looked like as if grid is not responding to the events.

On debugging the issue, I found that whenever “mousedown” or “click” events are being fired from watir scripts, they were cascading “rowmousedown” or “rowclick” event appropriately to the Grid. But the function which changes the css class of row to be selected was not getting called. Again Why?

Stepping further, found the statement in RowSelectionModel class from where the event is simply ignored (as if nothing had happened)

1
2
3
4
5
Class - RowSelectionModel
handleMouseDown : function(g, rowIndex, e){
   if(e.button !== 0 || this.isLocked()){
      return;
   };

It seems that value of button property was not equal to ZERO when fired from watir script. However when I use mouse, button value is ZERO.

Why ExtJS has this comparison check for button property of Event? My guess is that ExtJS developer wanted to handle only those event which are being generated by clicking mouse. If the event was generated from Mouse, property button of event will definitely have the value as per the W3C standard or Microsoft standard ( which is obviously not the case with the events generated from watir scripts).

The question now, how do we generate mouse event using our watir scripts? Cause from watir library, there is no way to fire mouse event directly.

Solution to the above problem is to add the module as mentioned in Watir Wiki . Include the module in your script and modify your test statement as

1
$browser.div( :class => "x-grid3-row", :index => 10 ).left_click

It works perfectly!!!

for me, this is definitely elegant as I was trying to execute javascript code from watir script to select the row as

1
2
$browser.document.parentWindow.eval( 
      "Ext.getCmp( 'gridId' ).getSelectionModel().selectRow( 10 ) ")

On a side note, I have not heard of many instance where folks are praising Microsoft for implementing feature which is not according to the standard and still makes sense (specially true with Internet Explorer). Read the “Miscellaneous Properties” section in W3C Dom Events page for details of Event’s Button property. From the page

The Microsoft implementation is the only one that makes sense.

 

Bus Day – Take the Bus!!

Take The Bus!

Take The Bus!

 

Error Messages Rocks!!!

According to RBI guidelines, it is mandatory to have additional level of security for all online transaction using credit cards which is “Verified by Visa”. Credit card holder is suppose to verify each and all online transaction using a personal password. If the password does not match, transaction does not gets approved. Simple!

Today while I was making an online transaction and provided my password to complete the transaction, card provider site lead me to the following page

error

Err!! What’s that? Did you notice the error message? It does not say anything about the browser which I should be using for this card provider. A plain error message like this is ridiculous! What information does it give actually? Why there is no recovery steps? Why can’t the message include the supported browser list?

BTW, I did notice a link for “Terms and condition for verified by visa program” for this card provider and yes, the terms and condition also does not say anything about the browser/system requirement!

Searching the website of the card provider, I found FAQ for verified by visa program which mentions the browser requirement as “Microsoft Internet Explorer version 5.5 or above, or Netscape Navigator 4.7x.”. Awesome! Is netscape exists anymore? who is using it ?
( must be the developer who wrote the program :D )

No prize for guessing that I was using Firefox and I had to launch Internet explorer to complete my transaction.