Wednesday, November 14, 2007

Blowing away IE

ASP.NET development is great fun, especially when you are targeting Internet Explorer 7 (as if there are any other browsers anyway) :).

It doesn't take much to confuse IE so I find myself in the continuous loop of trying a code change, clearing the cache in IE, rebuilding the app and running it again. Numerous times a day, too many. Dancing the Microsoft Visual Studio developer jig if you will.

Well, enough is enough. Time to automate it.

Consider the following ruby script that uses WSH. I'm aware of watir and other winole jiggery, but why not just send the keystrokes, I say. This script blows out the IE cache, quits it, goes into visual studio and restarts the project, hurrah. Obviously you'll want to replace the AppActivate parameters to match your window titles.

 1 require 'win32ole'
 2
 3 wsh = WIN32OLE.new('Wscript.Shell')
 4 wsh.AppActivate('Generic Auditing Tool')
 5 sleep(2)
 6 wsh.SendKeys('%{T}') #ALT-T: select 'Tools'
 7 sleep(1)
 8 wsh.SendKeys('o') #select 'Internet Options'
 9 sleep(1)
10 wsh.SendKeys('%{D}') #select 'Delete'
11 sleep(1)
12 wsh.SendKeys('a') #select 'Delete all'
13 sleep(1)
14 wsh.SendKeys('d') #select 'also delete files and settings stored by add-ons'
15 sleep(1)
16 wsh.SendKeys('y') #select 'Yes'
17 sleep(8)
18 wsh.SendKeys('%{F4}') #quit 'Internet Options'
19 sleep(1)
20 wsh.SendKeys('%{F4}') #quit IE
21
22 wsh.AppActivate('NAT - Microsoft Visual Studio') #grab the visual studio window
23 sleep(2)
24 wsh.SendKeys('^{F5}') #start the project without debugging

No comments: