In one of our clients current projects, there is a module of scripts that require each script to log in as multiple user/roles to complete certain parts of the work flow. The application is also a little quirky. It has no log out button!  So in order for our script to log out of one user/role and into another we must have it kill the IE window, with delete history settings set, and reopen a new “fresh” window to pass in the next set of credentials.

Earlier this week I was tasked with doing some routine maintenance on this module of scripts so I downloaded them to my favorite ruby debugger, Rubymine, and kicked them off. Things were running smoothly. The script was able to log in as the first user/role and carried out the test case for that role without a hitch. But when time came to kill the browser and sign as the next user/role, the IE browser‘s cache was not getting cleared because IE reopened to quickly. Weird. I had the correct IE settings to clear the browser cache upon exit but nothing was getting cleared. The answer. MORE SLEEP!

IE settings to clear browser on exit

Understandably, packing your script full of extra sleep time might not the best solution for handling this IE cache issue due to varying execution speeds and time waste but it is definitely a good quick fix in a pinch and can help you get your script back on track after a nerve racking derailment. Below is an example of the run method I used as a quick fix to get my Watit / Awetest scripts up and running again. Notice the sleeps I added after the test case (in which the last step is kill browser) and before the new browser is allowed to fire up. Without these sleeps a new browser window would fire up, with the cache uncleared, and therefor the application would already be logged in as the first user. In any case, it seems that IE needs some time to actually clear its cache so there is nothing wrong with using a little sleep to let IE do its business.

In summary, We could probably all use some more sleep and it’s the same for Watir. If you are struggling trying to get something to work that by all accounts should work, maybe you haven’t given your script a chance to do its work. In short, More Sleep Is Always A Good Bet.

Enhanced by Zemanta