Tuesday, October 29, 2013

Defeat Browser Caching

Caching is used at various levels. When you visit a website, your browser fetches the data from the web server and a part of it is stored on local storage temporarily. These can contain source code, image etc. So the next time you open the same website, your request doesn't have to traverse long hierarchy from DNS all the way to country specific web server. This saves time and bandwidth.

Browser Caching may be good for most websites or most parts of it however, it’s not advantageous in number of situations.

  • A secure banking site may not like any of its part to be cached as the customers system can be compromised and cached information can be used to gain insight into customers account. (Yes it uses SSL but the intruder can still know the time of access etc)
  • Parts which need are updated very frequently. For example, the ad block may still show the old “advertisement.gif” and user may click thinking the he’s lucky to always be the millionth visitor!
I have seen these two scenario’s in past one year.

Old Ads

Scenario 1 - In a large organization, it often happens the Development team fixes an issue raised by the Testing team and closes the bug but testers can still find the flaw!
Or
Scenario 2 - There might be various development teams in a web product which is already deployed at the client site. The UI team makes changes but these changes are not visible to end user. The angry client admonishes UI team manager and the blame is passed to business logic team who had no role in it!
The reason for all these is neither Testing team nor Business logic team but Browser Caching!!!

Fighting it out

You must remember that you cannot delete the user’s cache programmatically. Hence, all the methods revolve around prevention.

Method 1 – Tell the browser not to cache.

HTML
<meta http-equiv="cache-control" content="no-cache, no-store, must-revalidate" /> 
<meta http-equiv="expires" content="-1" /> 
<meta http-equiv="pragma" content="no-cache" />

Servlet


response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); 
response.setHeader("Pragma", "no-cache");
response.setDateHeader("Expires", 0);

And one can make it for PHP with header(), ASP with Response.AppendHeader() etc.

This approach is useful if your application was not already cached. If it was, then browser may fetch the cached version only. Also doesn’t work on version of IE (http://support.microsoft.com/kb/321722). The above method is necessary but not sufficient. (Please read edit for the method below)

Method 2(a) – Random number next to link (un-escaped characters)
Change
<link REL="STYLESHEET" TYPE="text/css" HREF/css/default.css"/>
To
 <script >document.write('<link REL="STYLESHEET" TYPE="text/css" HREF="/css/default.css?' + new Date().getTime() + '"></link>');</script>
Each time a random number is generated, it changes the URL and browser believes that it doesn’t have a cached copy.


Method 2(b) – Random number next to link (escaped characters)
Change
<script language="JavaScript" src="/jsdir/My.js"/>
To
<script >    document.write(unescape("%3Cscript src='/jsdir/My.js?" +  new Date().getTime() + "' type='text/javascript'%3E%3C/script%3E"));</script>

The method 2(a) worked for both Google Chrome and Mozilla.

But for IE you need to follow two approaches.
1. If you have CSS then use 2(a), and for
2. JavaScripts use 2(b).


EDIT: Full proof method - Change in Method 1

    This method works on all browsers and you won't need to restart the webserver! Simply include the <head> tag with meta tags two times, one after the <body> tag (needed only for IE).

<html>
<head>
<title>title</title> 
 <meta http-equiv="expires" content="-1" /> 
 <meta http-equiv="pragma" content="no-cache" />
</head>
<body>
  Body goes here
</body>
 <head> 
 <meta http-equiv="expires" content="-1" /> 
 <meta http-equiv="pragma" content="no-cache" />
 </head>
</html>

Monday, July 29, 2013

QTP 11.5 Batch Test Problems

I wanted to test a GUI application and came across this great software - QTP which automates test cases easily. However, I faced issues with the trial version for Batch Testing. Without the batch test runner, one has to keep repeating "Open-Run-Log Results" cycle for EVERY test case. All of it requires user intervention and it felt that manual testing would be much better.I installed updates but it didn't solve the issue.

Googling facilitated me to find an alternative way to batch test. Some users used their VB Scripting knowledge. One can create a .vbs file with following code:-
 ' on error resume next  
 Dim qtApp 'As QuickTest.Application ' Declare the Application object variable  
 Dim qtTest 'As QuickTest.Test ' Declare a Test object variable  
 Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object  
 qtApp.Launch ' Start QuickTest  
 qtApp.Visible = True ' Make the QuickTest application visible  
   
 ' Set QuickTest run options  
 Set file_Sys=CreateObject("Scripting.filesystemObject")  
 Set Dir=file_Sys.GetFolder("C:\YOUR PATH FOR TESTCase Folder")  
 set test_collection=Dir.SubFolders  
 Set qtresultsObj=CreateObject("Quicktest.RunResultsOptions")  
   
 For each t_folder in test_collection  
      qtApp.Open t_folder.Path,True,False  
      qtresultsObj.resultsLocation=t_folder.path&"\Res1"  
      qtApp.Test.Run qtresultsObj,true  
      qtApp.test.Close  
 Next  
 
 qtApp.Options.Run.RunMode = "Fast"  
 qtApp.Options.Run.ViewResults = False  
   
 Set qtTest = Nothing ' Release the Test object  
 Set qtApp = Nothing ' Release the Application object  
   


This script helps to get away with the QTP's erratic batch test runner. But it has its own pitfalls. Whenever you use this, there are error messages displayed after each execution. 

Batch Test Error

 To overcome, I wrote an application in JAVA which will scan after every interval for such messages and do away with them. 




STEPS for Batch Testing
  1. Make a .vbs file
  2. Copy paste the code as shown above and change the file path to the folder where all your test cases are stored, save it
  3. Download the QTP Batch Runner Helper
  4. Run the Helper and enter the scan interval. (Dont click on "Start" )
  5. Double click on ".vbs" file
  6. While the QTP is loading the test case, go back to "Batch Runner Helper" and click on "Start"

Friday, July 19, 2013

Jana Gana Mana Controversy - Clearing Facts

Someone created a post on Facebook about Indian National Anthem being a homage to King George V and as the bad news travels faster, people have started believing it. The post
Stanza 1: The (Indian) people wake up remembering your good name and ask for your blessings and they sing your glories 
(Tava shubha name jaage; tava shubha aashish maage, gaaye tava jaya gaatha)
Stanza 2: Around your throne, people of all religions come and give their love and anxiously wait to hear your kind words.
Stanza 3: Praise to the King for being the charioteer, for leading the ancient travellers beyond misery.
Stanza 4: Drowned in deep ignorance and suffering, this poverty stricken,unconscious country? Waiting for the wink of your eye and our mother's (the Queen's) true protection.
Stanza 5: In your compassionate plans, the sleeping Bharat (India) will wake up. We bow down to your feet, O Queen, and glory to Rajeshwara(the King).
This whole poem does not indicate any love for the Motherland, but depicts a bleak picture of it. When you sing Jana Gana Mana, whom are you glorifying?
Certainly not the Motherland. Is it God? The poem does not indicate that. 
1. "The poem does not indicate that" Surely, such an article was written by someone who lacked intellectual acuity. A poem isn't always direct! Its the meaning behind those words that you have to understand. I'm sure that if this author had read "The Road not Taken by Robert Frost", he would infer that its actually about making a choice of road when one is stuck in a forest!

"Whom are you glorifying? Is it God?" Yes!  The meaning can be easily interpreted by reading the translation itself -> "Praise to the King for being the charioteer, for leading the ancient travellers beyond misery". Tagore could be thinking about Lord Krishna, as to how being a Charioteer, he ensured the victory of the Truth.

And now, if you re-read the entire translation it seems as an ode to God.

2. But, the post also has this ->
only those provinces that were under British rule, i.e., Punjab, Sindh, Gujarat, Maratha, were mentioned. None of the princely states, which are integral parts of India now, such as Kashmir, Rajasthan, Andhra, Mysore and Kerala, were recognized.
"Dravida-Utkala-Bangal" - Dravida includes southern states - Kerala, Mysore too. Even if he hadn't included I still wouldn't believe this allegation for a simple reason - its a "poem" and not encyclopedia page to include all names.

This is what I believe. But I could be wrong. So you should hear straight from the horses mouth:-
1. From his letter in 1939(1) - "I should only insult myself if I cared to answer those who consider me capable of such unbounded stupidity"
2.  Extract from another letter written(2) -  “A certain high official in His Majesty’s service, who was also my friend, had requested that I write a song of felicitation towards the Emperor. The request simply amazed me. It caused a great stir in my heart. In response to that great mental turmoil, I pronounced the victory in Jana Gana Mana of that Bhagya Vidhata of India who has from age after age held steadfast the reins of India’s chariot through rise and fall, through the straight path and the curved. That Lord of Destiny, that Reader of the Collective Mind of India, that Perennial Guide, could never be George V, George VI, or any other George. Even my official friend understood this about the song. After all, even if his admiration for the crown was excessive, he was not lacking in simple common sense.”

References:-

Saturday, June 8, 2013

Thank You Dear Stranger


I had to board my flight at 5:45 pm from Delhi Airport. To be on a safer side I decided to reach Mathura at 11:30 am to take any train to Delhi which all reach there before 2:30 pm.

The suitable trains

The plan was simple, clear and effective.
It usually takes about 30-35 mins to reach Mathura from Vrindavan so I was very relaxed as I started around 11 am. To accompany me, on this lonely journey were a plethora of doleful songs for the heartbroken sung by Altaf Raja et al who have unanimously been the favourite of all Taxi's drivers since time immemorial. Though I requested him three times to decrease the volume but maybe he couldn't hear me as he was already lost thinking why his girl was "Bewafa" (carried away by the song). We stopped for refuelling, a brief transition from cacophony to the highway silence. On arriving at Railway Station's Outer gate, he asked me to take the Pedal rickshaw as he didn't want to bribe the Policemen, I agreed.  The skinny rikshawala took 10 mins to steer the riksha through the crowd and stopped halfway to the reservation centre. 


With only a small trunk besides my laptop bag, I rushed inside the station to see the 100's of men lined up in many queues for getting ticket. With some experience, you can know that enqueing the shortest line doesn't always decrease your waiting time. The dynamics of queuing theory work in ideal conditions and Indian Railway Queues are surely ideal...... for abnormality! As I was halfway in the queue chosen by me, a catfight commenced in the adjacent queue. Since the railway guards failed to break it off, they asked the guy inside the window to stop issuing the tickets. Apparently, the guard must have been inspired from the famous quote - To stop the train, pull the chain!

When I reached near the ticket window, a lady requested me to buy a ticket for her as was in hurry and couldn't afford to join the queue. With people trying to push me aside, I quickly took the money from her and requested for two tickets to Delhi. In no time, the lady inside the window gave me a single ticket for two people!

I quickly apologized for being unable to get a single ticket for her. She understood that it all happened unintentionally and agreed to go in the same train. Though, this didn't appeal me, as the only way to get a train now was to run (it was 12:30 pm). I was frantic to reach Delhi before 3 pm. A guy who accompanied her asked us to cross 2 platforms quickly to catch a train that was to depart. It was a race in which I had to run slower so as not to leave my co-passenger because I had the tickets. Just as we reached the platform-3, panting heavily - found out that, the train had already departed. Cursing myself for helping a stranger and wasting the last opportunity to make it to my flight, I could only get angrier when she said that there are no other trains till 3 pm.

The thought of missing the flight sent shivers, and decided if there are no trains, then I'm taking a bus right away. I traversed back to platform 1, to ask for trains to Delhi at help desk. They were out to lunch. My mind had started playing games, and it kept saying as if the "Game's over”, "You have lost it". It even started questioning my faith. But still something inside me kept saying that "He" can't do that. In few minutes, the same girl with the guy stood before me. I gave them a displeasing look to let them know what they had done to me. She said they are out for lunch, now we need to wait.

We both had smartphones and could access internet. But sometimes, even Google fails to answer what a Coolie can! I fetched the latest information from a Coolie, and started running to platform 3 where the Kongu Express was arriving an hour late from its schedule time. The lady asked me to get into sleeper compartment, even though we didn't have a ticket. As it was my mistake to get a clubbed ticket, I had to accede to it but requested her to handle the ticket Examiner (TTE). Fortunately, we got a compartment where only one person was sleeping. She managed to bribe the TTE. It was a relief as I'm not a veteran player in that field.

After realising that train was going to Hazrat Nizzamuddin instead of New Delhi, I re-calculated the time. It turned out that then I would reach airport only if there isn't a single traffic jam. I couldn't risk it.

The lady started talking, I kept answering straight to end the conversation soon. I thought - Why prolong a futile talk when we were to part anyway? It was sultry and I was perspiring, she offered water. The affable savour-faire seemed suspicious. With a smile, I answered a no to it. As it was only a 2 hour journey, I thought I would survive but the fast moving train made me feel sleepy. With half closed eyes, I laid on my head the bag. Looking at my uneasy posture, she suggested that I must keep my luggage below the seat and sleep peacefully. After a long comfortable sleep, I asked her how I can reach New Delhi at the earliest. She initially said bus to which I objected (didn't want to be a hostage to traffic). The next suggestion was Metro, which involved changing two trains. Favorably, she was also going to a place which had the same route.

After arriving at Delhi, we quickly took a taxi to get to the nearest Metro station. On the train, she told me that the bus from Mathura would not take less than 4 hours and if chose it, I was sure to miss the flight. On the way, I kept thinking, why was she amiable to me? Why didn't she take the auto fare even though I requested her several times? When the New Delhi Metro Station came, I could only re-pay for her kindness with a Munch. From there I got a direct train to Airport.

I now ponder over this incident and ask myself - what if she hadn't asked me to buy a ticket for her? Would I be able to get the much needed peaceful sleep in a sleeper coach? 

Most importantly, Would I still make it to the airport? Maybe not because the train which departed couldn't be caught even If I ran the fastest I could. I reached Airport 50 mins before boarding time, if I was alone in the metro; I would surely get late while learning the process. It made me realize that there are people who are good and without a cause. They are like jewels found below the sea, so rare that its hard to believe they are real. 

--Thank you Dear Stranger    

Monday, February 18, 2013

Those "ASL" Days


Today when my cellphone beeped, it was my friend from college asking if there was anyone in the group of 10 people who could field the question. Suddenly, I reminisced the sounds of "Knock" and "Shutting of door". These two things had been like the beeps of the cell phone then.

In early 2000's, Internet was acknowledged for chatting and Yahoo, ICQ, MSN messengers were the Facebook, Twitter and G+. Yahoo! and Hotmail were competing head to head for users and Yahoo was giving 25 MB of free storage compared to a meager 5 MB from Hotmail. I recollect these from the past:-

1. "ASL?" - (Age, Sex, Location) was how conversations started 90% of the times. People were averse talking to same gender.

2. Usernames were very catchy - Sexyboy2000, smarty86, cuteprincess_18. A friend had made - "MC_BC_UC_IC@....com".

3. In the chatrooms, there would be one user who would force everyone to hear the song that he/she was listening to on his machine.

4. Most users usually had fix timings of staying logged in. You could find them during that interval in the same chatroom.

5. Every messenger had some irritating "Buzz!" which was to grab the attention of the participants. Most of us would use it several times one after the other.

I guess I was in 4th or 5th class when I joined a chatroom. There were some who were discussing about games and other topics in the main window. I didn't understand many of the shortforms they used and so I would ask the same. So then, this person PMed(private message) me. As I was new to chatting, I would immediately add anyone who sent a message. She was 60/f/US.

Slowly we started talking regularly and more so because this user was online most of the time. She would help me with all Internet related stuff (voice chat, ICQ etc).  Since its very usual for us to refer to any elder women as "aunty", she found it very cute. I was too young to understand what was cute there.  We became great friends. I often taught her hindi words, she would help me understanding american phrases. Im sure I voice chatted too but dont remember anything specific. Yes, once I asked her the meaning of F word and she said I need to stop talking to such people :). Everytime after the school, I would log in and we would have something talk about. It would usually begin with what I did at school.

A few months later, I tried to login but was unsuccessful. In those days, the server wouldn't always connect you. After several attempts, I was sure it wasn't that. The dialog box said that Yahoo! won’t allow anyone below 13 years! I couldn’t even log in from the web interface. They had deleted my account.

Later, I created another account but didn’t remember her username completely. I tried looking in various chatrooms but no "cookenciel....." was found. Even  couldn’t help me.  And this is how I lost my first online friend.