Showing posts with label Web Tests. Show all posts
Showing posts with label Web Tests. Show all posts

Test Availability and Inspect Web Pages using Powershell


Have you ever wanted to test the availability of a URL or web page?  or check for the presence of content or links on a page?  even clicking through a flow of web pages automatically?

Well, these things are not necessarily new concepts or challenges.  In fact, in the Application Testing space this is the type of thing we do day in and out.

I have recently been messing around with Selenium and Python web test scripts, and just for kicks wondered if similar things could be achieved using Powershell.  Funnily enough, the answer is yes, and quite easily too for anyone familiar with Powershell scripting.

So here are some basics just for fun, to get things going...   the magic sauce is in the Invoke-WebRequest cmdlet.  Let's check up on this blog's main page as follows by feeding the URL we want to check to the Invoke-WebRequest cmdlet, and assigning the resulting object to a variable called $webpage:

$webpage = Invoke-WebRequest https://blazingtm.com

Nice.  Exciting. Maybe not 😃

What can we do with this thing called $webpage you might ask.  Well, first let's see what type this object actually is.  You can do this calling

$webpage.GetType()

It's a thing called HtmlWebResponseObject.  Ok, so not just a simple "webpage", but an object.  Well, so it may have associated member properties we can inspect, maybe that could be interesting.  We can do this using the following cmdlet

$webpageGet-Member

The result should look something like follows, listing all member properties and methods for the webpage:

Name MemberType Definition
---- ---------- ----------
Dispose Method void Dispose(), void IDisposable.Dispose()
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
AllElements Property Microsoft.PowerShell.Commands.WebCmdletElementCollection
BaseResponse Property System.Net.WebResponse BaseResponse {get;set;}
Content Property string Content {get;}
Forms Property Microsoft.PowerShell.Commands.FormObjectCollection Forms
Headers Property System.Collections.Generic.Dictionary[string,string] Hea
Images Property Microsoft.PowerShell.Commands.WebCmdletElementCollection
InputFields Property Microsoft.PowerShell.Commands.WebCmdletElementCollection
Links Property Microsoft.PowerShell.Commands.WebCmdletElementCollection
ParsedHtml Property mshtml.IHTMLDocument2 ParsedHtml {get;}
RawContent Property string RawContent {get;set;}
RawContentLength Property long RawContentLength {get;}
RawContentStream Property System.IO.MemoryStream RawContentStream {get;}
Scripts Property Microsoft.PowerShell.Commands.WebCmdletElementCollection
StatusCode Property int StatusCode {get;}
StatusDescription Property string StatusDescription {get;}

Let's have a little look at that StatusCode property.  To see what it is, use

$statuscode = $webpage.StatusCode

You would have guessed, if we look at the value of $statuscode we will see it's 200.  Provided the webpage was available earlier of course. 200 is good when it comes to web page availability.

We can test for this using something along the lines of

if ($statuscode -eq 200) {Write-Output("Brilliant, this page is available :)")}
else {Write-Output("Well, that did not work :(")}

Equally, we might want to make sure the page is not only available (ie a Status Code 200), but that it has a certain content on the page.  That is often useful to know to ensure a page has rendered the right results.

This is where the Content property comes in handy.  Let's say we wanted to check that the page contains the phrase "Late night musings".  Too easy, do this

$webpage.Content.Contains("Late night musings")

Now this will simply return True, or False, depending on whether the phrase is found.  Of course you can have further logic on the back of this, but you can see the basics of some interesting web tests evolving here.

That's all for tonight, but following on from this wouldn't it be great if we could script up a whole user flow navigating web pages to test availability of a web site, not just a page.  That's however a topic for another time.

Enjoy.

MB


Quick Look at Application Availability Monitoring using free IBM Cloud Service

I recently wrote about web application availability monitoring using Microsoft Azure and Application Insights.  You can read all about that here. Spoiler alert - Microsoft's offering is pretty impressive 😀.

Not wanting to favour one vendor over another, I figured I'd have a quick look at the IBM equivalent.  IBM's cloud has recently been rebadged. What was previously known as Softlayer and/or Bluemix is now officially named IBM Cloud.

IBM Cloud has a freemium model where some services - the ones deemed "lite" - are free.  Luckily, their Application Availability monitoring service falls into this bucket so that allowed me to have a go and road test the solution. Let's take a look...

IBM Cloud - Application Availability Monitoring




It was relatively simple to get things going, although there seem to have been a couple of quirks and hiccups.  Nevertheless, the following five high level steps will get you going:

  1. Sign up for an IBM Cloud account - the free one will do
  2. From the Catalogue, create a new basic/free CloudFoundry app - seems that availability monitoring can only be connected to a CloudFoundry app on the IBM Cloud
  3. From the Catalogue under the DevOps heading, create a new Availability Monitoring service - connect this to your CloudFoundry app
  4. Create and configure a new synthetic test - these can be for web pages or APIs, single action or multistep tests; pick the worldwide locations from where to run the test, frequency, and response validation rules
  5. Voila, wait for the tests to run and you will start to get response times and success/failure alerts

The visualisations and views are not bad out of the box, although navigation takes a little getting used to.  Following are some screenshots to give you a bit of an idea what you can expect:





The Verdict

In Summary, this is a decent service, and the synthetic multi step tests to mimic an end user transaction are handy.  The test has to be written in Selenium and uploaded to the IBM Cloud as far as I understand.

The screens seem to not always render and refresh reliably, but that could just be an issue with my browser.  My basic free CloudFoundry .NET app seems to be crashing regularly, but I suspect that I have not given it enough memory to run.

If you are an existing IBM customer who is already in the IBM ecosystem, this new capability is worth exploring.  The ability to drill down on the synthetic transaction results and get a waterfall type view of step timings is neat.

One drawback is that this service does not run independently from IBM Cloud hosted apps.  In other words, you cannot use it to monitor just any website, unlike the Microsoft flavour. Unless I have missed something?

Ultimately, try it and see if it's right for you.  It may be worth your time exploring this one. Enjoy.

MB


Links

IBM Cloud
CloudFoundry
Selenium



Load Test Your Web App in 5 Minutes

Recently I have been exploring the capabilities and merits of Microsoft Azure and Application Insights, and have stumbled onto another rather interesting and useful piece of functionality.

Application Insights can easily be combined with Visual Studio Team Services to quickly set up a load test for your web application.

Why Bother with Load Tests?

But why bother with load tests, you might ask?  Is it not good enough that a web application functions as designed with no errors when you do your user acceptance testing?  Surely that's all that matters, right?

Not necessarily.  There have been many recent examples of rather embarrassing failures of high profile web applications due to the sheer number of people trying to access it at the same time.  Who could forget the first Click Frenzy event, or more recently the Australian Census.

Digital businesses rely on web app performance and reliability

It becomes very real if you are a modern digital business, relying on the availability and performance of your web application for revenue, customer satisfaction and brand loyalty.  Your next big online promotion is coming up and you are hoping to drive sales and revenue hard.  But if your promo turns out to be a cracker, is your web application ready for the onslaught of your customers?

The answer is that you absolutely should test and push your application to its limits, so you can understand the capacity of compute you need to sustain the targeted number of concurrent visitors.  Of course you could just use the power of the cloud and automatically scale your application horizontally. But that would make for a whole other post another time.

Visual Studio Team Services to the rescue

Enter Visual Studio Team Services.  If your web app happens to run in Azure, most likely you have already set up an Application Insights workspace to gain visibility on your application's performance and availability. Right from the portal you can also set up a Load Test.  If you haven't already linked a VSTS account, you can do so by creating one on the fly.



Next simply configure the parameters of your load test, give it a name,  what URL to test, duration, how many concurrent users, and from what location to test.  Then sit back and let Azure App Insights and VSTS do the heavy lifting for you.


It will only take a little while to acquire the required resources to run the test but soon enough your test will kick in and the user load is generated.

Are there alternatives?

Of course there are many other testing and load generator tools available in the market.  Some of the more traditional options in this space that I am aware of and know reasonably well are HP LoadRunner and IBM Rational. These don't just do web applications but can also deal with legacy and LOB application testing. Add to this many newer generation web application centric testing tools and you can take your pick for what suits your circumstances best.

In Summary

Application Insights and VSTS are interesting, capable and low cost options and are worth a look if you are a developer in the Microsoft space and/or your applications already run on Azure.  I found the quick and easy setup for simple URL based load tests valuable.  Knowing ahead of time what loads your web application can handle will mean you are always well prepared for the next online sales drive or promotional event.


Watch This Quick Demo



Links

Microsoft Application Insights
HP LoadRunner
IBM Rational Functional Tester

Set Up Web Site Availability Monitoring Using Azure Application Insights In 5 Minutes

Have you got a website where availability matters?  Do you know what the user experience is like for people browsing your site?  Is your online store open for business 24/7?  Why would you even care?

Well, as soon as we are talking "business" and revenue generating web sites I guess the answer becomes obvious.  Customers won't put up with slow performing sites, with errors or unavailability when they want to shop with you.  They will simply move on to the next online store, and most likely not come back.

Of course there are many different ways, tools and services that allow you to monitor your web sites for availability and performance. However, since I'm looking into Azure Application Insights at the moment I was wondering what that would look like and whether this Microsoft option is capable and fit for purpose.

So I guess here goes...  for the purposes of this post let's use this sample raffle ticket sales promo site, which is already hosted in Azure. That's not a pre-requisite, but it is handy. So is it possible to get some web availability monitoring set up in under 5 minutes?  We'll give it a go.

Log into the Azure Portal. If you haven't already, set up an Application Insights workspace for your web application by selecting your web application, select Application Insights, give this new resource a name, and click OK.

How to create a new Application Insights resource in Azure Portal

Within a few seconds, you will get a confirmation in the portal stating that the resource has been created.  With a few clicks you can also instrument your Azure Web App for deeper monitoring, but for the purposes of this post we'll focus on web availability tests.

Select the Application Insights workspace linked to your web app, in our case the QLDNSWFundraising one.  As this app has already got some availability monitoring running, we actually have an Availability percentage straight on the Overview screen.  This is driven by a web test for the home page of this sample web site.

Let's click on Availability on the left and set up another web test monitor. This could be for a shopping cart page, a catalogue item search or any such thing.  You could even set up a multi step web test to simulate an actual customer transaction through your site.  That is however a topic for another post, and in fact Microsoft charges for these multi step web tests separately.


 You will see this following screen


Click Add test, give your new test a easily identifiable name - in our case Fundraising About - enter the actual URL of the page.  Leave the test frequency at default 5 minutes or change as desired.

You could at this point simply click Create and you would be done.  Pretty quick, hey?  But wait, there are a couple of neat advanced settings worth considering.

First, you may be interested in how availability and performance of your site differs from various geographic locations.  Why is that important?  Well, depending on where your site is hosted, performance and response times can vary greatly.  Of course there are mitigating options available such as content distribution/caching networks etc but that's another story.  Or it could be that local carrier outages prevent customers in some geographies from accessing your site but not others.  Good info for your customer service team.

Second, you may want to check the server response a little more in depth rather than just for a 200 response code (page served up okay).  This could be useful for a catalogue item search or the like, where you want to make sure the page returned has a specific word present.  This allows you to test dynamic pages that might be making database calls, which indirectly tests the health and availability of your full application stack.  Pretty neat trick, right?

Click on the Test locations and Success criteria sections respectively and configure these two blades with the desired settings.  Should look something like the following:



Finally click on Create and you have a working smart web availability test.  Within a few minutes, your new test will start running, and you will get the results back in the portal.  You can drill down on each test, check which locations may have failures or slow performance etc.



As a nice added bonus, you will also get a weekly digest email which will clearly show this week's performance and availability as compared to last week.  This can give you piece of mind that the site's performance is not deteriorating over time, or can highlight service level target issues etc.

In Summary

I'm actually quite impressed with the ease of setup, and the ease of accessing and consuming the availability and performance data.  Combine these web availability test with the full Application Insights instrumentation of your apps, and they will add significant value to your full stack monitoring.


Watch a Quick Demo

Most Popular Posts