Tuesday, October 20, 2009

Clearing IE cache and cookies before running Selenium tests

When using FireFox, it is quite easy to setup a profile to be used with your Selenium tests. FireFox allows configuration which can delete all cookies and cached files when shutting down. Internet Explorer neither allows a profile like FireFox nor deletes cookies and cache unless you delete them by using the Tools –> Internet Options menu.

Deleting cache and cookies might be required for some web applications when testing via Selenium. Here is a easy way to incorporate documented Windows calls to delete cache and cookies via Ruby.

The following script uses the system function to get access to the Windows command prompt. Run the following ruby script on a Windows based ruby installation to clear all cookies and cached files.

#This script is meant for Ruby on Windows only for
#clearing all cache and cookies in Internet Explorer.
#Run this script from the command prompt like this
#C:\Ruby>ruby clear-ie-cache-cookies.rb

#To clear IE7 temporary Internet files
system('RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8')

#To clear IE7 browsing cookies
system('RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2')

#To clear IE7 browsing history
system('RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1')

#To clear IE7 form data
system('RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 16')

#To clear IE7 remembered passwords for filling web login forms
system('RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 32')

#To clear or delete all IE7 browsing history – all of the above!
system('RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255')

No comments:

Post a Comment