Today I wanted to visually check a lot of URLs, to see if the page was loading fine, or if it was giving any kind of error. So I had an Excel file with the name of some applications (Azure WebApps), and for each the list URLs of that site, and I needed to load each URL and see, in a browser, what the pages look like.
The good thing is that depending the result, I could easily identify it if I had a high level view of all the pages. That’s were the thumbnail view comes in!
To do that I needed to automate several individual steps that I would later combine.
- Get the list of Application names and URLs from an Excel spreadsheet. That part was easy, as I’m already a fond user of ImportExcel PowerShell module
- Open a URL into a Browser. This StackOverflow answer helped me.
- Take a screenshot, ideally of a specific portion of the screen. For that last part I found this other scriplet on SO.
So I created a Frankenstein Powershell script combining all the pieces together, which you can see here.
The input I’m using is an Excel file, of which I’ll use two columns: Name and Hostnames, which contains a list of comma-separated URLs, of which I’ll only take the first one. I’ll use the Name column to name the output screenshot file.
This is how the Excel file would look like:
We load it using Import-Excel CmdLet. In the example case above, we would get:
PS C:\> Import-Excel D:\temp\file.xlsx Name HostNames ---- --------- google google.com, www.google.com microsoft www.microsoft.com yahoo yahoo.com
I didn’t find a way to take a screenshot of a non visible window, so I am showing the browser, and taking the screenshot of the region. For my purpose it works and it’s quite simple, but that presents some disadvantages (you cannot use the region of the screen while running the script, or you risk altering the result in the screenshot).
Another disadvantage is that it involves some precaution and some manual preparation, to position the windows, and modify the script accordingly, the first time at least.
- Open a Powershell command line window
- Run the following command. This will open an Internet Explorer window. Place it on your desktop, so that it will not overlap with the Powershell window. They can be side by side. It will be easier if you have two monitors, as you can place the browser window alone on a monitor.
$IE=new-object -com internetexplorer.application $IE.visible=$true
- Run the following commands and take note of the results:
$IE.Top $IE.Left $IE.Width $IE.Height
- Replace the results in the script. That way, each time we open a new browser the script will reposition it in the same location on your screen!
That’s it. Now you just have to run the script and it will do the job.
In the case of our example input file above, the output we’d get would look like in the output folder places in Thumbnail View:
In my particular use case, this below is what I was looking for:
As you can see, by placing the images in Thumbnail View, we can rapidly identify and classify the corresponding Web sites into 4 groups:
- Page seems to load fine
- Default initial Azure page (possibly no content deployed)
- Page doesn’t load, or takes too long
- Some HTTP error
Furthermore, within the first category, a quick inspection of the image will show if the page loads apparently fine, or if it shows some content problem.
If you have hundreds of sites, it can save you some precious time!
- I’m not sure what happens if the screen switch to screensaver mode. It may not work as expected. So, either deactivate the screensaver, or keep moving the mouse (out of the browser’s way) while the script runs.
- I use a new IE instance for each new URL, that is, I don’t recycle the IE instance for several URLs, for a simple reason: if the URL doesn’t load, I would possibly take a screenshot of the previously loaded URL, which is not what I want.