Chris Tankersley

· PHP Jack of All Trades ·

Testing IE The Right Way

Most developers don't have the luxury of being able to say, "You know what, screw Internet Explorer. I'm not supporting it!" Those that do are probably in some startup that thinks they are on the cutting edge and that IE is still just as bad as it was in the IE6 days. Well, it's not.

Of course, your users aren't all going to be techies that will install the latest and greatest Chrome or Firefox, much as you would like them to. You end up being stuck developing and making sure that it works fine in IE. There's one problem - you can't have more than one version of IE installed, and even with the developer tools you don't get a true representation of the IE rendering.

If you have a relatively new computer, you can use virtualization to do the testing. The best part is it's completely legal and you don't have to mess around with any licensing issues because Microsoft gives away testing VMs. You can download, from Microsoft, the following:

  • Windows Vista with IE7
  • Windows 7 with IE8
  • Windows 7 with IE9

and I'm sure that you can get a Windows 8 VM with IE10 soon enough (though in the mean time you can just use the developer preview, which is free anyway). How do we go about this magic?

Get the Required Files

Microsoft has all the files availabel on their site, it just takes a bit of searching. You will need to download a copy of Virtual PC and the install images. Again, all of this is free.

One note I will make is with Virtual PC - be careful what you download. I don't mean this in a 'this might be a virus' sort of warning, but a 'watch out for upselling' kind of warning. With Windows 7, Microsoft introduced Windows XP Mode, which is a free Windows XP VM you can use with upper versions of Windows 7 (Professional, Enterprise, and Ultimate, to be exact).

If you go to Google and just search for "Microsoft Virtual PC", you will probably end up at the XP Mode site. Virtual PC by itself doesn't need anything more than Windows 7 and a processor that supports virtualization, so don't feel the need to upgrade to a higher version of Windows 7 unless you need XP mode.

Install Virtual PC

Install the hotfix file for Virtual PC and reboot your PC. Once it comes back up, check your start menu for 'Windows Virtual PC' entry and click on it. This will create a 'Virtual Machines' folder in your user profile directory.

Install the VMs

Each of the VMs consists of two parts - an extractor program that ends in '.exe', and multiple '.rar' files. The Windows Vista/IE7 bundle has 1 .exe, and 5 .rar files. To install the VM, double-click the .exe file and it will run the extract process. Browse to your 'Virtual Machines' folder. I create a new folder and extract the VM image to the new folder, so I end up with an IE7, IE8, and IE9 folder.

Setting up the VMs

Now comes the fun part. Microsoft generated the VMs and set them up as basic as possible. Since they give them away for free, they are also not activated and can't be activated without purchasing a full license. We need to 'activate' the VM and then set it up to work properly before we can do anything.

Double-click on the '.vmc' file that was extracted to start the VM. The default password for the accounts is 'Password1'.

Activating the VM

This is quite easy with Windows Vista and Windows 7. Each of them can be run for 30 days after install and Microsoft is using that to an advantage with these VMs. The only problem is these VMs were generated over 30 days ago, so they are no longer active.

You can get around this by rearming the 30 days. Microsoft allows you to do this a limited number of times though. I believe Windows 7 is 4 times, and Windows Vista is 2 times. In any event, it's limited.

To rearm your install, click on Start, type 'cmd', and then right-click on it. In the menu, select 'Run as Administrator'. The rearm can only be done through an adminstrator prompt.

In the window, type 'slmgr /rearm' and hit enter. After a few moments you should get a message that you need to reboot the VM. Do so, and when it comes back up you should be able to move on to the next step. If it complains, make sure that you are running the cmd process as Administrator, and that you haven't run out of rearms.

Fixing the Networking

The networking is broken by default. I take that back - it's not broken, just no longer configured for the PC the VM was created on. In the menu bar above the VM, click on 'Tools', and then 'Configure.' If this is the first time you've been here, it will complain about the networking, which we'll fix.

In the Settings window, select 'Networking.' All of them will be set to 'Not Connected,' which really doesn't do us any good. In the drop-down for Adapter 1, set it to your network card (wired or wireless, doesn't matter). On my laptop I could not get Internal Network or NAT to work at all, but setting it directly to an interface worked right off the bat. This will give your VM an IP on your local network, so be mindful if your network runs of of static IPs or you need to register it for DHCP.

If anyone knows how to get NAT working properly, let me know. I could not get it to work with either the Vista or Windows 7 VMs.

When You Run Out of Rearms

Each rearm lasts for 30 days, but more than likely you'll want to continue to use th VMs. When the VM is booted the first time, there will be a generated called 'VirtualPCUndo_[name of VM and random text]'. To roll your VM back to just after it was extracted is somewhat non-obvious, but do the following:

  • Boot the VM like normal
  • Click on 'Tools', and then 'Settings'
  • Leave this window open, and then shut down the VM
  • Once it's shut down, click on 'Undo Disks' in the settings
  • Click the 'Discard Changes' button

You can then rearm your VM more times! Any customizations you did to the VM will be lost though, but really you should only be testing IE in it anyway.

Now Test!

Now you have a full Windows install with proper versions of IE to test against. This will work much better than changing the browser modes in IE9 and give you a better feel for how the site will react. For example, I recently had to test some animations for a website in IE. They worked fine in IE9, but when switching to IE8 mode in the Developer tools it went to pot. As it turns out, under real IE8 it worked fine.


Categories: Testing VMs